From 28f20a50015e94e052e1ca0a311069f5430edf97 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Mon, 27 Apr 2020 14:04:22 +0200 Subject: [PATCH] Syncing apps in bin/update-nextcloud --- bin/update-nextcloud | 52 ++++++++++++++++++++++++++++++++++---------- lib/functions.rc | 2 +- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/bin/update-nextcloud b/bin/update-nextcloud index ed7aad6..bb0aa1d 100755 --- a/bin/update-nextcloud +++ b/bin/update-nextcloud @@ -13,9 +13,9 @@ CONF_FILE="${CONF_DIR}/update-nextcloud.rc" NEW_VERSION="" OLD_VERSION="" -BASEDIR=/var/www -NEXTCLOUD_DIR_LINK="${BASEDIR}/nextcloud" -NEW_NEXTCLOUD_DIR="${BASEDIR}/nextcloud-bla" +WWW_BASE=/var/www +NEXTCLOUD_DIR_LINK="${WWW_BASE}/nextcloud" +NEW_NEXTCLOUD_DIR="${WWW_BASE}/nextcloud-bla" DOWNLOAD_DIR="/root/Downloads" ARTIFACT="nextcloud-bla.tar.bz2" MD5_FILE="${ARTIFACT}.md5" @@ -113,7 +113,7 @@ get_options() { ARTIFACT="nextcloud-${NEW_VERSION}.tar.bz2" MD5_FILE="${ARTIFACT}.md5" SHA256_FILE="${ARTIFACT}.sha256" - NEW_NEXTCLOUD_DIR="${BASEDIR}/nextcloud-${NEW_VERSION}" + NEW_NEXTCLOUD_DIR="${WWW_BASE}/nextcloud-${NEW_VERSION}" check_for_root @@ -252,19 +252,48 @@ unpack_archive() { adjust_permissions() { cd "${NEW_NEXTCLOUD_DIR}" - local verbose_opt="" - if [[ "${VERBOSE}" == "y" ]] ; then - verbose_opt=" --verbose" - fi info "Adjusting permissions if '${CYAN}${NEW_NEXTCLOUD_DIR}${NORMAL}' ..." info "Setting ownership to ${WWW_USER}:${WWW_GROUP} ..." - CHOWN -R "${WWW_USER}:${WWW_GROUP}" . + chown -R "${WWW_USER}:${WWW_GROUP}" . info "Setting file mode to '${FILE_PERMS}' ..." - find ./ -type f -print0 | xargs --null chmod ${verbose_opt} "${FILE_PERMS}" + find ./ -type f -print0 | xargs --null chmod "${FILE_PERMS}" info "Setting dir mode to '${DIR_PERMS}' ..." - find ./ -type d -print0 | xargs --null chmod ${verbose_opt} "${DIR_PERMS}" + find ./ -type d -print0 | xargs --null chmod "${DIR_PERMS}" + +} + +#------------------------------------------------------------------------------ +sync_apps() { + + local cur_nc_dir="${WWW_BASE}/nextcloud-${OLD_VERSION}" + local cur_apps_dir="${cur_nc_dir}/apps" + local new_apps_dir="${NEW_NEXTCLOUD_DIR}/apps" + local app= + + TEMP_DIR=$( mktemp -d "${TEMP_DIR_PARENT}/nextcloud-apps-XXXXXXXXXX" ) + debug "Activating trap ..." + trap cleanup_tmp_dir INT TERM EXIT ABRT + info "Evaluating apps to sync from '${CYAN}${cur_apps_dir}${NORMAL}' => '${CYAN}${new_apps_dir}${NORMAL}' ..." + cd "${TEMP_DIR}" + ls -1 "${cur_apps_dir}/" > INSTALLED_APPS.txt + ls -1 "${new_apps_dir}/" > DEFAULT_APPS.txt + + local app_sync_list=$( diff --suppress-common-lines -y DEFAULT_APPS.txt INSTALLED_APPS.txt | \ + sed -e 's/^[[:space:]]*>.//g' ) + + debug "Apps to sync:\n${app_sync_list}" + for app in ${app_sync_list} ; do + debug "Syncing app '${CYAN}${app}${NORMAL}' ..." + rsync -a "${cur_apps_dir}/${app}" "${new_apps_dir}/" + done + + cd + + debug "Deactivating trap ..." + trap - INT TERM EXIT ABRT + cleanup_tmp_dir } #------------------------------------------------------------------------------ @@ -277,6 +306,7 @@ main() { download_release unpack_archive adjust_permissions + sync_apps } diff --git a/lib/functions.rc b/lib/functions.rc index 3620119..ad6af55 100644 --- a/lib/functions.rc +++ b/lib/functions.rc @@ -10,7 +10,7 @@ BLUE="" CYAN="" NORMAL="" -VERSION="0.3.3" +VERSION="0.3.4" STD_SHORT_OPTIONS="sdvhV" STD_LONG_OPTIONS="simulate,debug,verbose,nocolor,help,version" -- 2.39.5