diff options
author | thecalcaholic <6317548+theCalcaholic@users.noreply.github.com> | 2022-10-09 19:06:33 +0300 |
---|---|---|
committer | thecalcaholic <6317548+theCalcaholic@users.noreply.github.com> | 2022-10-09 19:06:33 +0300 |
commit | 5b77f49d0651051a5bc6f5b5046d6eed41cfe79d (patch) | |
tree | 0a490cd283b0de7e83371d8a09400d92bf4f6737 | |
parent | ded50a34c50cfb48cbae1d367e540d567d7b4734 (diff) |
Dockerfile, install.sh: Move data directory out of nextcloud.sh after installation
Signed-off-by: thecalcaholic <6317548+theCalcaholic@users.noreply.github.com>
-rw-r--r-- | bin/ncp/CONFIG/nc-datadir.sh | 6 | ||||
-rw-r--r-- | build/docker/Dockerfile | 7 | ||||
-rw-r--r-- | etc/library.sh | 33 | ||||
-rw-r--r-- | etc/ncp-config.d/nc-datadir.cfg | 2 | ||||
-rw-r--r-- | install.sh | 4 |
5 files changed, 49 insertions, 3 deletions
diff --git a/bin/ncp/CONFIG/nc-datadir.sh b/bin/ncp/CONFIG/nc-datadir.sh index 3a0061d4..8d55a98f 100644 --- a/bin/ncp/CONFIG/nc-datadir.sh +++ b/bin/ncp/CONFIG/nc-datadir.sh @@ -147,7 +147,11 @@ configure() ( . "${BINDIR?}/SYSTEM/metrics.sh" - reload_metrics_config + reload_metrics_config || { + echo 'WARN: There was an issue reloading ncp metrics. This might not affect your installation, + but keep it in mind if there is an issue with metrics.' + true + } ) echo "The NC data directory has been moved successfully." diff --git a/build/docker/Dockerfile b/build/docker/Dockerfile index 1f813bec..a830deef 100644 --- a/build/docker/Dockerfile +++ b/build/docker/Dockerfile @@ -160,13 +160,18 @@ touch /.docker-image; \ apt-get update; \ apt-get install --no-install-recommends -y wget ca-certificates; \ -# install nextcloudpi +# install nextcloudpiset_app_param nc-datadir.sh DATADIR '/data-ro/ncdata' \ source /usr/local/etc/library.sh; \ cd /tmp/ncp-build/; \ install_app ncp.sh; \ mv /usr/local/etc/ncp-config.d/nc-init-copy.cfg /usr/local/etc/ncp-config.d/nc-init.cfg; \ run_app_unsafe bin/ncp/CONFIG/nc-init.sh; \ +echo 'Moving data directory to a more sensible location' \ +mkdir -p /opt/ncdata \ +set_app_param nc-datadir.sh DATADIR '/data-ro/ncdata' \ +run_app_unsafe bin/ncp/CONFIG/nc-datadir.sh \ +set_app_param nc-datadir.sh DATADIR '/data/ncdata' \ sed -i 's|data-ro|data|' /data-ro/nextcloud/config/config.php; \ # fix default paths diff --git a/etc/library.sh b/etc/library.sh index e43a8f45..80327d56 100644 --- a/etc/library.sh +++ b/etc/library.sh @@ -246,6 +246,39 @@ find_app_param() jq -r ".params[$p_num].value" < "$cfg_file" } +set_app_param() +{ + local script="${1?}" + local param_id="${2?}" + local param_value="${3?}" + local ncp_app="$(basename "$script" .sh)" + local cfg_file="$CFGDIR/$ncp_app.cfg" + + grep -q '[\\&#;'"'"'`|*?~<>^"()[{}$&[:space:]]' <<< "${param_value}" && { echo "Invalid characters in field ${vars[$i]}"; return 1; } + + cfg="$(cat "$cfg_file")" + + local len="$(jq '.params | length' <<<"$cfg")" + local param_found=false + + for (( i = 0 ; i < len ; i++ )); do + # check for invalid characters + [[ "$(jq -r ".params[$i].id" <<<"$cfg")" == "$param_id" ]] && { + cfg="$(jq ".params[$i].value = \"${param_value}\"" <<<"$cfg")" + param_found=true + } + + done + + [[ "$param_found" == "true" ]] || { + echo "Did not find parameter '${param_id}' in configuration of app '$(basename "$script" .sh)'" + return 1 + } + + echo "$cfg" > "$cfg_file" + +} + # receives a script file, no security checks function run_app_unsafe() { diff --git a/etc/ncp-config.d/nc-datadir.cfg b/etc/ncp-config.d/nc-datadir.cfg index f387c3e3..7ec1cd72 100644 --- a/etc/ncp-config.d/nc-datadir.cfg +++ b/etc/ncp-config.d/nc-datadir.cfg @@ -9,7 +9,7 @@ { "id": "DATADIR", "name": "Data directory", - "value": "/media/USBdrive/ncdata", + "value": "/opt/ncdata", "suggest": "/media/USBdrive/ncdata", "default": "/var/www/nextcloud/data", "type": "directory" @@ -67,6 +67,10 @@ rm /usr/local/etc/ncp-config.d/nc-nextcloud.cfg # armbian overlay is ro systemctl restart mysqld # TODO this shouldn't be necessary, but somehow it's needed in Debian 9.6. Fixme install_app ncp.sh run_app_unsafe bin/ncp/CONFIG/nc-init.sh +echo 'Moving data directory to a more sensible location' +mkdir -p /opt/ncdata +set_app_param nc-datadir.sh DATADIR '/opt/ncdata' +run_app_unsafe bin/ncp/CONFIG/nc-datadir.sh rm /.ncp-image # skip on Armbian / Vagrant / LXD ... |