From 3665a9131c4f0bac07727a5f908905e9a6348535 Mon Sep 17 00:00:00 2001 From: Ondrej Kubik Date: Sat, 4 Nov 2017 19:20:37 +0000 Subject: splitting hooks and using snapctl instead of local settings file Signed-off-by: Ondrej Kubik --- snap-src/bin/wekan-read-settings | 38 +++++++++++--------------------------- snap/hooks/configure | 28 +++------------------------- snap/hooks/install | 12 ++++++++++++ snap/hooks/post-refresh | 1 + 4 files changed, 27 insertions(+), 52 deletions(-) create mode 100755 snap/hooks/install create mode 120000 snap/hooks/post-refresh diff --git a/snap-src/bin/wekan-read-settings b/snap-src/bin/wekan-read-settings index aec05bba..a924eaea 100755 --- a/snap-src/bin/wekan-read-settings +++ b/snap-src/bin/wekan-read-settings @@ -3,34 +3,18 @@ # read wekan config source $SNAP/bin/config -# TODO: uncomment following, once snapctl can be called from outside the hooks -# for key in ${keys[@]} -# do -# # snappy is picky about key syntax, using mapping -# MAP_KEY="KEY_$key" -# SNAPPY_KEY= -# if value=$(snapctl get ${!MAP_KEY}); then -# echo "$key='$value'" -# export $key=$value -# else -# # use default value -# default_value="DEFAULT_$key" -# echo "using default value: $key='${!default_value}'" -# export $key=${!default_value} -# fi -# done -# TODO: get rid of this workaround once above can be used -# loop through all values, and if not defined, use default value for key in ${keys[@]} do - if [ "x" == "x${!key}" ]; then - # use default value - default_value="DEFAULT_$key" - echo "using default value: $key='${!default_value}'" - export $key=${!default_value} - # echo "export $key='${!def_value}'" >> $SETTINGS_FILE - else - echo "$key='${!key}'" - fi + default_value="DEFAULT_$key" + description="DESCRIPTION_$key" + snappy_key="KEY_$key" + value=$(snapctl get ${!snappy_key}) + if [ "x$value" == "x" ]; then + echo -e "$key=${!default_value} (default value)" + export $key=${!default_value} + else + echo -e "$key=$value" + export $key=$value + fi done diff --git a/snap/hooks/configure b/snap/hooks/configure index 1e2b0ec7..60ce81e8 100755 --- a/snap/hooks/configure +++ b/snap/hooks/configure @@ -1,32 +1,10 @@ #!/bin/bash +exec >> $SNAP_COMMON/hook.log 2>&1 +echo "$(date '+%Y-%m-%d %H:%M:%S') $0: Entering hook" + # read wekan config . $SNAP/bin/config -# create run dir, we're going to use it for unix socket -mkdir -p $SNAP_DATA/share -mkdir -p $SNAP_DATA/shared - # settings were altered by user, safest way to get them applied is to restart service -# TODO: remove this workaround once it's not needed -# for the moment we can't read settings outside of the hook, -# so store all settings in helpper script which is then picked by main wrapper -echo -e "#!/bin/sh\n" > $SETTINGS_FILE -for key in ${keys[@]} -do - # snappy is picky about key syntax, using mapping - MAP_KEY="KEY_$key" - if value=$(snapctl get ${!MAP_KEY}); then - echo "export $key='$value'" >> $SETTINGS_FILE - elif [ -d "${!key}" ]; then - # store back value from SETTINGS_FILE - echo "export $key='${!key}'" >> $SETTINGS_FILE - fi -done - -# set file executable -chmod 755 $SETTINGS_FILE -# we can't use snapctl to restart service, may be one day .... - -echo "Setting has been updated, restart service." diff --git a/snap/hooks/install b/snap/hooks/install new file mode 100755 index 00000000..14087eaa --- /dev/null +++ b/snap/hooks/install @@ -0,0 +1,12 @@ +#!/bin/bash + +exec >> $SNAP_COMMON/hook.log 2>&1 +echo "$(date '+%Y-%m-%d %H:%M:%S') $0: Entering hook" + +# coppy caddy file in place +[ ! -e $SNAP_COMMON/Caddyfile ] && cp $SNAP/Caddyfile $SNAP_COMMON/Caddyfile + +# create run dir, we're going to use it for unix socket +mkdir -p $SNAP_DATA/share +mkdir -p $SNAP_DATA/shared + diff --git a/snap/hooks/post-refresh b/snap/hooks/post-refresh new file mode 120000 index 00000000..f7ffc47a --- /dev/null +++ b/snap/hooks/post-refresh @@ -0,0 +1 @@ +install \ No newline at end of file -- cgit v1.2.3-1-g7c22