From: Frank Brehm Date: Sat, 25 Apr 2020 19:59:55 +0000 (+0200) Subject: Continuing with bin/update-nextcloud till unpacking and adjusting permissions X-Git-Tag: 0.1.2~2 X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=798092e16e7c546571ebbdef5e6ad70f7e723293;p=pixelpark%2Fadmin-tools.git Continuing with bin/update-nextcloud till unpacking and adjusting permissions --- diff --git a/bin/update-nextcloud b/bin/update-nextcloud index 541ae94..ed7aad6 100755 --- a/bin/update-nextcloud +++ b/bin/update-nextcloud @@ -9,16 +9,25 @@ BIN_DIR=$( dirname "${MY_REAL_NAME}" ) BASE_DIR=$( dirname "${BIN_DIR}" ) LIB_DIR="${BASE_DIR}/lib" CONF_DIR="${BASE_DIR}/etc" +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" DOWNLOAD_DIR="/root/Downloads" ARTIFACT="nextcloud-bla.tar.bz2" MD5_FILE="${ARTIFACT}.md5" SHA256_FILE="${ARTIFACT}.sha256" DOWNLOAD_URL_BASE="https://download.nextcloud.com/server/releases" +TEMP_DIR_PARENT="/var/tmp" +TEMP_DIR= +WWW_USER="www-data" +WWW_GROUP="www-data" +FILE_PERMS="0640" +DIR_PERMS="0750" + if [[ -f "${LIB_DIR}/functions.rc" ]] ; then . "${LIB_DIR}/functions.rc" @@ -29,6 +38,11 @@ fi detect_color +if [[ -f "${CONF_FILE}" ]] ; then + debug "Sourcing '${CYAN}${CONF_FILE}${NORMAL}' ..." + . "${CONF_FILE}" +fi + DESCRIPTION=$( cat <<-EOF Updates the local Nextcloud installation under '${CYAN}${NEXTCLOUD_DIR_LINK}${NORMAL}'. @@ -99,6 +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}" check_for_root @@ -128,6 +143,17 @@ get_old_version() { fi fi + if [[ -d "${NEW_NEXTCLOUD_DIR}" ]] ; then + warn "The directory '${YELLOW}${NEW_NEXTCLOUD_DIR}${NORMAL}' is already existing." + if yes_or_no "Continue [y/n]? " ; then + info "Removing existing '${YELLOW}${NEW_NEXTCLOUD_DIR}${NORMAL}' ..." + RM -r "${NEW_NEXTCLOUD_DIR}" + else + info "Give it up." + exit 1 + fi + fi + echo info "Updating Nextcloud from version '${GREEN}${OLD_VERSION}${NORMAL}' to '${GREEN}${NEW_VERSION}${NORMAL}' ..." @@ -177,6 +203,70 @@ download_release() { } +#------------------------------------------------------------------------------ +cleanup_tmp_dir() { + + if [[ -z "${TEMP_DIR}" ]] ; then + return 0 + fi + + if [[ ! -d "${TEMP_DIR}" ]] ; then + return 0 + fi + + cd + + debug "Removing temporary directory '${CYAN}${TEMP_DIR}${NORMAL}' ..." + RM -r "${TEMP_DIR}" + +} + +#------------------------------------------------------------------------------ +unpack_archive() { + + TEMP_DIR=$( mktemp -d "${TEMP_DIR_PARENT}/nextcloud-unpack-XXXXXXXXXX" ) + local archive="${DOWNLOAD_DIR}/${ARTIFACT}" + + debug "Activating trap ..." + trap cleanup_tmp_dir INT TERM EXIT ABRT + + cd "${TEMP_DIR}" + info "Unpacking '${GREEN}${archive}${NORMAL}' ..." + if [[ "${VERBOSE}" == "y" ]] ; then + tar xfvj "${archive}" + else + tar xfj "${archive}" + fi + + info "Moving '${CYAN}${TEMP_DIR}/nextcloud${NORMAL}' to '${CYAN}${NEW_NEXTCLOUD_DIR}${NORMAL}' ..." + mv "${TEMP_DIR}/nextcloud" "${NEW_NEXTCLOUD_DIR}" + cd + + debug "Deactivating trap ..." + trap - INT TERM EXIT ABRT + cleanup_tmp_dir + +} + +#------------------------------------------------------------------------------ +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}" . + info "Setting file mode to '${FILE_PERMS}' ..." + find ./ -type f -print0 | xargs --null chmod ${verbose_opt} "${FILE_PERMS}" + info "Setting dir mode to '${DIR_PERMS}' ..." + find ./ -type d -print0 | xargs --null chmod ${verbose_opt} "${DIR_PERMS}" + +} + #------------------------------------------------------------------------------ main() { @@ -185,29 +275,13 @@ main() { get_old_version download_release + unpack_archive + adjust_permissions + } main "$@" exit 0 -# NEW_NEXTCLOUD_DIR="${BASEDIR}/nextcloud-${VERSION}" -# -# if [[ -d "${NEW_NEXTCLOUD_DIR}" ]] ; then -# echo "Nextcloud version '${VERSION}' seems to be already installed." -# exit 2 -# fi -# -# ARTIFACT="nextcloud-${VERSION}.tar.bz2" -# RELEASE_URL="https://download.nextcloud.com/server/releases/${ARTIFACT}" -# CHECKSUM_URL="https://download.nextcloud.com/server/releases/${ARTIFACT}.md5" -# DOWNLOAD_DIR="/root/Downloads" -# -# cd "${DOWNLOAD_DIR}" -# wget -q "${RELEASE_URL}" -# wget -q "${CHECKSUM_URL}" -# md5sum -c "${ARTIFACT}.md5" -# - - # vim: ts=4 et list diff --git a/lib/functions.rc b/lib/functions.rc index 566b4bc..3620119 100644 --- a/lib/functions.rc +++ b/lib/functions.rc @@ -10,7 +10,7 @@ BLUE="" CYAN="" NORMAL="" -VERSION="0.3.2" +VERSION="0.3.3" STD_SHORT_OPTIONS="sdvhV" STD_LONG_OPTIONS="simulate,debug,verbose,nocolor,help,version" @@ -329,6 +329,21 @@ MV() { } +#------------------------------------------------------------------------------ +CHOWN() { + + if [[ "${SIMULATE}" == "y" ]] ; then + debug "Simulated chowning of $*" + return + fi + if [[ "${VERBOSE}" != "y" ]] ; then + chown "$@" + else + chown --verbose "$@" + fi + +} + #------------------------------------------------------------------------------ set_locale() {