]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Finishing simulation mode of bin/update-nextcloud
authorFrank Brehm <frank@brehm-online.com>
Tue, 6 Feb 2024 08:06:49 +0000 (09:06 +0100)
committerFrank Brehm <frank@brehm-online.com>
Tue, 6 Feb 2024 08:06:49 +0000 (09:06 +0100)
bin/update-nextcloud
lib/functions.rc

index 5e716af8016cc07d07b4cb7ee0abd091e47003e3..ff1f3c7b87f9346b248afe3ee7041bdf89e7e57b 100755 (executable)
@@ -172,9 +172,9 @@ get_old_version() {
 
     if [[ -d "${NEXTCLOUD_DIR_NEW}" ]] ; then
         warn "The directory '${YELLOW}${NEXTCLOUD_DIR_NEW}${NORMAL}' is already existing."
-        if yes_or_no "Continue [y/n]? " ; then
+        if yes_or_no "Continue with removing '${CYAN}${NEXTCLOUD_DIR_NEW}${NORMAL}' [y/n]? " ; then
             info "Removing existing '${YELLOW}${NEXTCLOUD_DIR_NEW}${NORMAL}' ..."
-            RM -r "${NEXTCLOUD_DIR_NEW}"
+            rm -rf "${NEXTCLOUD_DIR_NEW}"
         else
             info "Give it up."
             exit 1
@@ -297,6 +297,11 @@ unpack_archive() {
 
     info "Unpacking '${CYAN}${archive}${NORMAL}' into '${CYAN}${TEMP_DIR}${NORMAL}' ..."
 
+    if [[ -d "${NEXTCLOUD_DIR_NEW}" ]] ; then
+        error "Directory '${RED}${NEXTCLOUD_DIR_NEW}${NORMAL}' is already existing."
+        exit 7
+    fi
+
     debug "Activating trap ..."
     trap cleanup_tmp_dir INT TERM EXIT ABRT
 
@@ -305,15 +310,11 @@ unpack_archive() {
     if [[ "${VERBOSE}" && "${VERBOSE}" -gt '1' ]] ; then
         cmd="tar xfvj \"${archive}\""
     fi
-    if [[ "${SIMULATE}" ]] ; then
-        info "Simulate exec: ${cmd}"
-    else
-        debug "Exec: ${cmd}"
-        eval ${cmd}
-    fi
+    debug "Exec: ${cmd}"
+    eval ${cmd}
 
     info "Moving '${CYAN}${TEMP_DIR}/nextcloud${NORMAL}' to '${CYAN}${NEXTCLOUD_DIR_NEW}${NORMAL}' ..."
-    mv_no_verbose "${TEMP_DIR}/nextcloud" "${NEXTCLOUD_DIR_NEW}"
+    mv_no_verbose_force "${TEMP_DIR}/nextcloud" "${NEXTCLOUD_DIR_NEW}"
     cd
 
     debug "Deactivating trap ..."
@@ -325,19 +326,17 @@ unpack_archive() {
 #------------------------------------------------------------------------------
 adjust_permissions() {
 
-    cd "${NEXTCLOUD_DIR_NEW}"
+    if [[ -d "${NEXTCLOUD_DIR_NEW}" ]] ; then
+        cd "${NEXTCLOUD_DIR_NEW}"
+    fi
 
-    info "Adjusting permissions if '${CYAN}${NEXTCLOUD_DIR_NEW}${NORMAL}' ..."
+    info "Adjusting permissions of '${CYAN}${NEXTCLOUD_DIR_NEW}${NORMAL}' ..."
     info "Setting ownership to ${WWW_USER}:${WWW_GROUP} ..."
-    chown_no_verbose --recursive "${WWW_USER}:${WWW_GROUP}" .
+    chown_no_verbose_force --recursive "${WWW_USER}:${WWW_GROUP}" "${NEXTCLOUD_DIR_NEW}"
     info "Setting file mode to '${FILE_PERMS}' ..."
-    if [[ -z "${SIMULATE}" ]] ; then
-        find ./ -type f -print0 | xargs --null chmod "${FILE_PERMS}"
-    fi
+    find "${NEXTCLOUD_DIR_NEW}" -type f -print0 | xargs --null chmod "${FILE_PERMS}"
     info "Setting dir mode to '${DIR_PERMS}' ..."
-    if [[ -z "${SIMULATE}" ]] ; then
-        find ./ -type d -print0 | xargs --null chmod "${DIR_PERMS}"
-    fi
+    find "${NEXTCLOUD_DIR_NEW}" -type d -print0 | xargs --null chmod "${DIR_PERMS}"
 
 }
 
@@ -409,8 +408,8 @@ copy_config() {
     local new_cfg_file="${NEXTCLOUD_DIR_NEW}/config/config.php"
 
     info "Copying configuration ..."
-    CP "${cur_cfg_file}" "${new_cfg_file}"
-    CHOWN "${WWW_USER}:${WWW_GROUP}" "${new_cfg_file}"
+    cp_force "${cur_cfg_file}" "${new_cfg_file}"
+    chown_force "${WWW_USER}:${WWW_GROUP}" "${new_cfg_file}"
 
 }
 
@@ -450,6 +449,7 @@ main() {
 
     get_options "$@"
     umask 0022
+    debug "Verbose level is '${CYAN}${VERBOSE}${NORMAL}'."
 
     get_old_version
     do_backup
@@ -465,6 +465,11 @@ main() {
     start_service "${SERVICE_NAME}"
     release_maintenance
 
+    if [[ -d "${NEXTCLOUD_DIR_NEW}" ]] ; then
+        info "Purging ''${CYAN}${NEXTCLOUD_DIR_NEW}${NORMAL}' ..."
+        rm -rf "${NEXTCLOUD_DIR_NEW}"
+    fi
+
 }
 
 main "$@"
index 210b451fa5ac3f3dc74f61bd3bc1965b2779ea20..254392615b681a5bb7709ebb0e42d17ae0bcfebc 100644 (file)
@@ -10,7 +10,7 @@ BLUE=""
 CYAN=""
 NORMAL=""
 
-VERSION="0.5.1"
+VERSION="0.5.2"
 
 STD_SHORT_OPTIONS="sdvqhV"
 STD_LONG_OPTIONS="simulate,debug,verbose,quiet,nocolor,help,version"
@@ -439,6 +439,20 @@ CP() {
 
 }
 
+#------------------------------------------------------------------------------
+cp_force() {
+    local cmd="cp $*"
+    if [[ "${VERBOSE}" ]] ; then
+        cmd="cp --verbose $*"
+    fi
+    debug "Executing: ${cmd}"
+    if [[ -z "${VERBOSE}" ]] ; then
+        cp "$@"
+    else
+        cp --verbose "$@"
+    fi
+}
+
 #------------------------------------------------------------------------------
 cp_no_verbose() {
     if [[ "${SIMULATE}" ]] ; then
@@ -479,6 +493,12 @@ mv_no_verbose() {
     mv "$@"
 }
 
+#------------------------------------------------------------------------------
+mv_no_verbose_force() {
+    debug "Executing: mv $*"
+    mv "$@"
+}
+
 #------------------------------------------------------------------------------
 CHOWN() {
 
@@ -499,6 +519,20 @@ CHOWN() {
 
 }
 
+#------------------------------------------------------------------------------
+chown_force() {
+    local cmd="chown $*"
+    if [[ "${VERBOSE}" ]] ; then
+        cmd="chown --verbose $*"
+    fi
+    debug "Executing: ${cmd}"
+    if [[ -z "${VERBOSE}" ]] ; then
+        chown "$@"
+    else
+        chown --verbose "$@"
+    fi
+}
+
 #------------------------------------------------------------------------------
 chown_no_verbose() {
     if [[ "${SIMULATE}" ]] ; then
@@ -509,6 +543,12 @@ chown_no_verbose() {
     chown "$@"
 }
 
+#------------------------------------------------------------------------------
+chown_no_verbose_force() {
+    debug "Executing: chown $*"
+    chown "$@"
+}
+
 #------------------------------------------------------------------------------
 CHMOD() {
 
@@ -529,6 +569,20 @@ CHMOD() {
 
 }
 
+#------------------------------------------------------------------------------
+chmod_force() {
+    local cmd="chmod $*"
+    if [[ "${VERBOSE}" ]] ; then
+        cmd="chmod --verbose $*"
+    fi
+    debug "Executing: ${cmd}"
+    if [[ -z "${VERBOSE}" ]] ; then
+        chmod "$@"
+    else
+        chmod --verbose "$@"
+    fi
+}
+
 #------------------------------------------------------------------------------
 chmod_no_verbose() {
     if [[ "${SIMULATE}" ]] ; then
@@ -659,7 +713,8 @@ yes_or_no() {
 
     local answer=
     debug "Trying to get an answer with a timeout of ${timeout} seconds."
-    if read -p "${msg}" -t "${timeout}" answer ; then
+    echo -e -n "${msg}"
+    if read -t "${timeout}" answer ; then
         debug "Got an answer: '${answer}'"
     else
         exit 1