This is an automated email from the ASF dual-hosted git repository.

wohali pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb-pkg.git


The following commit(s) were added to refs/heads/master by this push:
     new 43199b3  Added configure hook 'snap set couchdb admin=[password]' (#63)
43199b3 is described below

commit 43199b341499fa33ff802121a0736c7f16067c0a
Author: Simon Klassen <[email protected]>
AuthorDate: Tue Mar 10 10:03:04 2020 +0800

    Added configure hook 'snap set couchdb admin=[password]' (#63)
    
    Co-authored-by: Joan Touzet <[email protected]>
---
 README-SNAP.md         |  8 ++++++++
 snap/hooks/configure   | 25 ++++++++++++++++++++++++-
 snap/hooks/pre-refresh | 22 ----------------------
 3 files changed, 32 insertions(+), 23 deletions(-)

diff --git a/README-SNAP.md b/README-SNAP.md
index 1bd2432..686f73a 100644
--- a/README-SNAP.md
+++ b/README-SNAP.md
@@ -18,6 +18,14 @@ The snap can be installed from a file or directly from the 
snap store:
 $ sudo snap install couchdb
 ```  
 
+If this is your first time installing couchdb then you will need to set an 
admin password
+and manually start CouchDB.
+
+```bash
+$ sudo snap set couchdb admin=[your-password-goes-here]
+$ sudo snap start couchdb 
+```
+
 ## Enable snap permissions
 
 The snap installation uses AppArmor to protect your system. CouchDB requests 
access to two
diff --git a/snap/hooks/configure b/snap/hooks/configure
index 5076e5a..d41b33d 100755
--- a/snap/hooks/configure
+++ b/snap/hooks/configure
@@ -15,7 +15,7 @@
 set -e
 
 VM_ARGS=$SNAP_DATA/etc/vm.args
-
+LOCAL_INI=$SNAP_DATA/etc/local.ini
 
 ## add or replace for the vm.arg file
 _modify_vm_args() {
@@ -30,6 +30,20 @@ _modify_vm_args() {
   fi
 }
 
+## add or replace for the vm.arg file
+_modify_ini_args() {
+  opt=$1
+  value="$2"
+  replace_line="$opt = $value"
+  if $(grep -q "^[;|[:space:]]*$opt[[:space:]]*=" $LOCAL_INI); then
+    sed "s/^[;|[:space:]]*$opt[[:space:]]*=.*/$replace_line/" $LOCAL_INI 
2>/dev/null >${LOCAL_INI}.new
+    mv -f ${LOCAL_INI}.new $LOCAL_INI 2>/dev/null
+  else
+    echo $replace_line >> $LOCAL_INI
+  fi
+}
+
+
 # The vm_args file can only be changed from the filesystem
 # configutaion vm.args file
 
@@ -43,3 +57,12 @@ do
   fi
 done
 
+LOCAL_INI_OPTIONS="admin"
+for key in $LOCAL_INI_OPTIONS
+do
+  val=$(snapctl get $key)
+  if [ ! -z "$val" ]; then
+    _modify_ini_args $key $val
+    sleep 0.125
+  fi
+done
diff --git a/snap/hooks/pre-refresh b/snap/hooks/pre-refresh
deleted file mode 100755
index 248e6b3..0000000
--- a/snap/hooks/pre-refresh
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/bin/sh
-
-# Licensed under the Apache License, Version 2.0 (the "License"); you may not
-# use this file except in compliance with the License. You may obtain a copy of
-# the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations under
-# the License.
-
-# If the data directory does not exisit in /var/couchdb/common; but does 
exisit in /var/couchdb/current; move it to common.
-
-if [ ! -d ${SNAP_COMMON}/data ]; then
-   if [ -d ${SNAP_DATA}/data ]; then
-       mv ${SNAP_DATA}/data ${SNAP_COMMON}/data
-   fi
-fi
-

Reply via email to