From 4a0a1824cc0808b84845c0910e470c80d5503334 Mon Sep 17 00:00:00 2001 From: nachoparker Date: Fri, 8 Sep 2017 08:47:40 +0200 Subject: backend: is_active() functionality --- bin/nextcloudpi-config | 3 ++- changelog.md | 6 +++++- etc/library.sh | 11 +++++++++++ etc/nextcloudpi-config.d/letsencrypt.sh | 5 +++++ etc/nextcloudpi-config.d/nc-database.sh | 6 ++++++ etc/nextcloudpi-config.d/nc-datadir.sh | 7 +++++++ etc/nextcloudpi-config.d/nc-swapfile.sh | 8 +++++++- 7 files changed, 43 insertions(+), 3 deletions(-) diff --git a/bin/nextcloudpi-config b/bin/nextcloudpi-config index a21336a8..a631b8be 100755 --- a/bin/nextcloudpi-config +++ b/bin/nextcloudpi-config @@ -34,11 +34,12 @@ function nextcloud-config() [[ $? -eq $DIALOG_OK ]] && ncp-update while true; do + # fill options local LIST=() for item in $CONFDIR/*.sh; do DESC=$( grep "DESCRIPTION=" "$item" | sed 's|^DESCRIPTION="||;s|"$||' ) - grep -q "^ACTIVE_=yes" "$item" && local ON="✓" || local ON=" " + is_active_script "$item" && local ON="✓" || local ON=" " LIST+=( "$ON $( basename "$item" .sh )" "$DESC" ) done diff --git a/changelog.md b/changelog.md index 4351ceb3..d6c2ab6c 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ -[v0.26.18](https://github.com/nextcloud/nextcloudpi/commit/a4144dc) (2017-09-07) refactor show_info(), make it only depend on variables +[v0.26.20](https://github.com/nextcloud/nextcloudpi/commit/bbbe114) (2017-09-08) backend: is_active() functionality + +[v0.26.19](https://github.com/nextcloud/nextcloudpi/commit/9e7b3ab) (2017-09-08) letsencrypt: occ path fix + +[v0.26.18](https://github.com/nextcloud/nextcloudpi/commit/0fcde74) (2017-09-07) refactor show_info(), make it only depend on variables [v0.26.17](https://github.com/nextcloud/nextcloudpi/commit/0197f31) (2017-09-07) ncp-web: link to changelog diff --git a/etc/library.sh b/etc/library.sh index ad4f0072..bd45b4f5 100755 --- a/etc/library.sh +++ b/etc/library.sh @@ -210,6 +210,17 @@ function activate_script() launch_script "$SCRIPT" } +function is_active_script() +{ + ( + local SCRIPT=$1 + unset is_active + source "$SCRIPT" + grep -q "^ACTIVE_=yes" "$SCRIPT" && return 0 + [[ $( type -t is_active ) == function ]] && is_active + ) +} + function launch_script() { ( diff --git a/etc/nextcloudpi-config.d/letsencrypt.sh b/etc/nextcloudpi-config.d/letsencrypt.sh index 4c6cf73f..ddb3802c 100644 --- a/etc/nextcloudpi-config.d/letsencrypt.sh +++ b/etc/nextcloudpi-config.d/letsencrypt.sh @@ -28,6 +28,11 @@ Both ports 80 and 443 need to be accessible from the internet Your certificate will be automatically renewed every month" +is_active() +{ + test -d /etc/letsencrypt/live +} + install() { cd /etc || return 1 diff --git a/etc/nextcloudpi-config.d/nc-database.sh b/etc/nextcloudpi-config.d/nc-database.sh index 43472b4f..63553a09 100644 --- a/etc/nextcloudpi-config.d/nc-database.sh +++ b/etc/nextcloudpi-config.d/nc-database.sh @@ -25,6 +25,12 @@ or the database will fail. ** If it ever fails with a white page, move the database back to the SD **" +is_active() +{ + local SRCDIR=$( grep datadir /etc/mysql/mariadb.conf.d/50-server.cnf | awk -F "= " '{ print $2 }' ) + [[ "$SRCDIR" != "/var/lib/mysql" ]] +} + configure() { local SRCDIR=$( grep datadir /etc/mysql/mariadb.conf.d/50-server.cnf | awk -F "= " '{ print $2 }' ) diff --git a/etc/nextcloudpi-config.d/nc-datadir.sh b/etc/nextcloudpi-config.d/nc-datadir.sh index 9fc5c5f0..c84393bc 100644 --- a/etc/nextcloudpi-config.d/nc-datadir.sh +++ b/etc/nextcloudpi-config.d/nc-datadir.sh @@ -20,6 +20,13 @@ DESCRIPTION="Change your data dir to a new location, like a USB drive" INFO="Note that non Unix filesystems such as NTFS are not supported because they do not provide a compatible user/permissions system" +is_active() +{ + local SRCDIR + SRCDIR=$( cd /var/www/nextcloud; sudo -u www-data php occ config:system:get datadirectory ) || return 1; + [[ "$SRCDIR" != "/var/www/nextcloud/data" ]] +} + configure() { ## CHECKS diff --git a/etc/nextcloudpi-config.d/nc-swapfile.sh b/etc/nextcloudpi-config.d/nc-swapfile.sh index 5c794381..1e5a66bf 100644 --- a/etc/nextcloudpi-config.d/nc-swapfile.sh +++ b/etc/nextcloudpi-config.d/nc-swapfile.sh @@ -14,10 +14,16 @@ # More at https://ownyourbits.com/ # -SWAPFILE_=/var/swap +SWAPFILE_=/media/USBdrive/swap SWAPSIZE_=1024 DESCRIPTION="Move and resize your swapfile. Recommended to move to a permanent USB drive" +is_active() +{ + local DIR=$( swapon -s | sed -n 2p | awk '{ print $1 }' ) + [[ "$DIR" != "/var/swap" ]] +} + configure() { local ORIG=$( grep -oP "CONF_SWAPFILE=.*" /etc/dphys-swapfile | cut -f2 -d= ) -- cgit v1.2.3