#!/bin/bash # Updater for NextCloudPi # # Copyleft 2017 by Ignacio Nunez Hernanz # GPL licensed (see end of file) * Use at your own risk! # # More at https://ownyourbits.com/ # set -e CONFDIR=/usr/local/etc/ncp-config.d/ UPDATESDIR=updates # don't make sense in a docker container EXCL_DOCKER=" nc-automount nc-format-USB nc-datadir nc-database nc-ramlogs nc-swapfile nc-static-IP nc-wifi nc-nextcloud nc-init UFW nc-snapshot nc-snapshot-auto nc-snapshot-sync nc-restore-snapshot nc-audit nc-hdd-monitor nc-zram SSH fail2ban NFS " # better use a designated container EXCL_DOCKER+=" samba " # check running apt pgrep apt &>/dev/null && { echo "apt is currently running. Try again later"; exit 1; } cp etc/library.sh /usr/local/etc/ source /usr/local/etc/library.sh mkdir -p "$CONFDIR" # prevent installing some ncp-apps in the docker version [[ -f /.docker-image ]] && { for opt in $EXCL_DOCKER; do touch $CONFDIR/$opt.cfg done } # copy all files in bin and etc cp -r bin/* /usr/local/bin/ find etc -maxdepth 1 -type f ! -path etc/ncp.cfg -exec cp '{}' /usr/local/etc \; # set initial config # TODO remove me after next NCP release [[ -f "${NCPCFG}" ]] || cat > /usr/local/etc/ncp.cfg < "$file" done } # configure if active by default [ -f /usr/local/"$file" ] || { [[ "$(jq -r ".params[0].id" "$file")" == "ACTIVE" ]] && \ [[ "$(jq -r ".params[0].value" "$file")" == "yes" ]] && { cp "$file" /usr/local/"$file" run_app "$(basename "$file" .cfg)" } } cp "$file" /usr/local/"$file" done # update NCVER in ncp.cfg and nc-nextcloud.cfg (for nc-autoupdate-nc and nc-update-nextcloud) nc_version=$(jq -r .nextcloud_version < etc/ncp.cfg) cfg="$(jq '.' /usr/local/etc/ncp.cfg)" cfg="$(jq ".nextcloud_version = \"$nc_version\"" <<<"$cfg")" echo "$cfg" > /usr/local/etc/ncp.cfg cfg="$(jq '.' etc/ncp-config.d/nc-nextcloud.cfg)" cfg="$(jq ".params[0].value = \"$nc_version\"" <<<"$cfg")" echo "$cfg" > /usr/local/etc/ncp-config.d/nc-nextcloud.cfg # install localization files cp -rT etc/ncp-config.d/l10n "$CONFDIR"/l10n # these files can contain sensitive information, such as passwords chown -R root:www-data "$CONFDIR" chmod 660 "$CONFDIR"/* chmod 750 "$CONFDIR"/l10n # install web interface cp -r ncp-web /var/www/ chown -R www-data:www-data /var/www/ncp-web chmod 770 /var/www/ncp-web # install NC app rm -rf /var/www/ncp-app cp -r ncp-app /var/www/ # install ncp-previewgenerator rm -rf /var/www/ncp-previewgenerator cp -r ncp-previewgenerator /var/www/ chown -R www-data: /var/www/ncp-previewgenerator # copy NC app to nextcloud directory and enable it rm -rf /var/www/nextcloud/apps/nextcloudpi cp -r /var/www/ncp-app /var/www/nextcloud/apps/nextcloudpi chown -R www-data: /var/www/nextcloud/apps/nextcloudpi [[ -f /.docker-image ]] && { # remove unwanted ncp-apps for the docker version for opt in $EXCL_DOCKER; do rm $CONFDIR/$opt.cfg find /usr/local/bin/ncp -name "$opt.sh" -exec rm '{}' \; done # update services cp docker/{lamp/010lamp,nextcloud/020nextcloud,nextcloudpi/000ncp} /etc/services-enabled.d } # only live updates from here [[ -f /.ncp-image ]] && exit 0 # update old images ./run_update_history.sh "$UPDATESDIR" # update to the latest NC version is_active_app nc-autoupdate-nc && run_app nc-autoupdate-nc # check dist-upgrade check_distro "$NCPCFG" && check_distro etc/ncp.cfg || { php_ver_new=$(jq -r '.php_version' < etc/ncp.cfg) release_new=$(jq -r '.release' < etc/ncp.cfg) cfg="$(jq '.' "$NCPCFG")" cfg="$(jq '.php_version = "'$php_ver_new'"' <<<"$cfg")" cfg="$(jq '.release = "'$release_new'"' <<<"$cfg")" echo "$cfg" > /usr/local/etc/ncp-recommended.cfg [[ -f /.dockerenv ]] && \ msg="Update to $release_new available. Get the latest container to upgrade" || \ msg="Update to $release_new available. Type 'sudo ncp-dist-upgrade' to upgrade" echo "${msg}" notify_admin "New distribution available" "${msg}" wall "${msg}" cat > /etc/update-motd.d/30ncp-dist-upgrade <