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
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
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 ..."
#------------------------------------------------------------------------------
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}"
}
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}"
}
get_options "$@"
umask 0022
+ debug "Verbose level is '${CYAN}${VERBOSE}${NORMAL}'."
get_old_version
do_backup
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 "$@"
CYAN=""
NORMAL=""
-VERSION="0.5.1"
+VERSION="0.5.2"
STD_SHORT_OPTIONS="sdvqhV"
STD_LONG_OPTIONS="simulate,debug,verbose,quiet,nocolor,help,version"
}
+#------------------------------------------------------------------------------
+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
mv "$@"
}
+#------------------------------------------------------------------------------
+mv_no_verbose_force() {
+ debug "Executing: mv $*"
+ mv "$@"
+}
+
#------------------------------------------------------------------------------
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
chown "$@"
}
+#------------------------------------------------------------------------------
+chown_no_verbose_force() {
+ debug "Executing: chown $*"
+ chown "$@"
+}
+
#------------------------------------------------------------------------------
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
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