| 1234567891011121314151617181920212223242526272829303132333435 | #!/bin/bashexec >> $SNAP_DATA/hook.log 2>&1echo "$(date '+%Y-%m-%d %H:%M:%S') $0: Entering hook"set -x# read wekan config. $SNAP/bin/config# settings were altered by user, safest way to get them applied is to restart service# first check if caddy service is enabledvalue=$(snapctl get caddy-enabled)if [ "$value" = "true" ]; then    # update caddy file    bind_port=$(snapctl get caddy-bind-port)    port=$(snapctl get port)    [ "x" != "x${bind_port}" ] && sed -i 's|proxy / localhost:.* {|proxy / localhost:'"${bind_port}"' {|g' $SNAP_COMMON/Caddyfile    [ "x" != "x$port" ] && sed -i 's|http://:.*|http://:'"${port}"'|g' $SNAP_COMMON/Caddyfile    snapctl start --enable ${SNAP_NAME}.caddy 2>&1 || true    snapctl restart ${SNAP_NAME}.caddy 2>&1 || trueelse    snapctl stop --disable ${SNAP_NAME}.caddy 2>&1 || truefivalue=$(snapctl get disable-mongodb)if [ "$value" = "true" ]; then    snapctl stop --disable ${SNAP_NAME}.mongodb 2>&1 || trueelse    snapctl start --enable ${SNAP_NAME}.mongodb 2>&1 || true    snapctl restart ${SNAP_NAME}.mongodb 2>&1 || truefi# restart all servicessnapctl restart ${SNAP_NAME}.wekan 2>&1 || true
 |