Skip to content

Commit

Permalink
Fix uninstall validation
Browse files Browse the repository at this point in the history
  • Loading branch information
mreid-tt committed Sep 11, 2024
1 parent 4838bce commit e58329b
Showing 1 changed file with 46 additions and 44 deletions.
90 changes: 46 additions & 44 deletions spk/fengoffice/src/service-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -231,66 +231,68 @@ script_installer_storage[database_type]=mysqli\
&script_installer_storage[plugins][]=workspaces\
&submited=submited"
# Prepare environment
cd ${WEB_ROOT}/public/install/ || exit 1
cd ${WEB_ROOT}/public/install/
# Execute based on DSM version
echo "Run ${SC_DNAME} installer"
exec_php "install_helper.php"
fi
fi
}

service_preuninst ()
validate_preuninst ()
{
# Check database
if [ "${SYNOPKG_PKG_STATUS}" = "UNINSTALL" ] && ! ${MYSQL} -u root -p"${wizard_mysql_password_root}" -e quit > /dev/null 2>&1; then
echo "Incorrect MySQL root password"
exit 1
fi

if [ "${SYNOPKG_PKG_STATUS}" = "UNINSTALL" ]; then
# Check export directory
if [ -n "${wizard_export_path}" ]; then
if [ ! -d "${wizard_export_path}" ]; then
# If the export path directory does not exist, create it
${MKDIR} "${wizard_export_path}" || {
# If mkdir fails, print an error message and exit
echo "Error: Unable to create directory ${wizard_export_path}. Check permissions."
exit 1
}
elif [ ! -w "${wizard_export_path}" ]; then
# If the export path directory is not writable, print an error message and exit
echo "Error: Unable to write to directory ${wizard_export_path}. Check permissions."
# Check export directory
if [ "${SYNOPKG_PKG_STATUS}" = "UNINSTALL" ] && [ -n "${wizard_export_path}" ]; then
if [ ! -d "${wizard_export_path}" ]; then
# If the export path directory does not exist, create it
${MKDIR} "${wizard_export_path}" || {
# If mkdir fails, print an error message and exit
echo "Error: Unable to create directory ${wizard_export_path}. Check permissions."
exit 1
fi

# Prepare archive structure
FENG_VER=$(sed -n "s|return '\(.*\)';|\1|p" ${WEB_ROOT}/config/installed_version.php | xargs)
TEMPDIR="${SYNOPKG_PKGTMP}/${SYNOPKG_PKGNAME}_backup_v${FENG_VER}_$(date +"%Y%m%d")"
${MKDIR} "${TEMPDIR}"

# Backup Directories
echo "Copying previous configuration and data from ${WEB_ROOT}"
rsync -aX "${WEB_ROOT}" "${TEMPDIR}/" 2>&1

# Backup the Database
echo "Copying previous database from ${MYSQL_DATABASE}"
${MKDIR} "${TEMPDIR}/database"
${MYSQLDUMP} -u root -p"${wizard_mysql_password_root}" ${MYSQL_DATABASE} > ${TEMPDIR}/database/${MYSQL_DATABASE}-dbbackup.sql 2>&1

# Create backup archive
archive_name="$(basename "$TEMPDIR").tar.gz"
echo "Creating compressed archive of ${SC_DNAME} data in file $archive_name"
tar -C "$TEMPDIR" -czf "${SYNOPKG_PKGTMP}/$archive_name" . 2>&1
}
elif [ ! -w "${wizard_export_path}" ]; then
# If the export path directory is not writable, print an error message and exit
echo "Error: Unable to write to directory ${wizard_export_path}. Check permissions."
exit 1
fi
fi
}

# Move archive to export directory
RSYNC_BAK_ARGS="--backup --suffix=.bak"
rsync -aX ${RSYNC_BAK_ARGS} "${SYNOPKG_PKGTMP}/$archive_name" "${wizard_export_path}/" 2>&1
echo "Backup file copied successfully to ${wizard_export_path}"
service_preuninst ()
{
if [ "${SYNOPKG_PKG_STATUS}" = "UNINSTALL" ] && [ -n "${wizard_export_path}" ]; then
# Prepare archive structure
FENG_VER=$(sed -n "s|return '\(.*\)';|\1|p" ${WEB_ROOT}/config/installed_version.php | xargs)
TEMPDIR="${SYNOPKG_PKGTMP}/${SYNOPKG_PKGNAME}_backup_v${FENG_VER}_$(date +"%Y%m%d")"
${MKDIR} "${TEMPDIR}"

# Backup Directories
echo "Copying previous configuration and data from ${WEB_ROOT}"
rsync -aX "${WEB_ROOT}" "${TEMPDIR}/" 2>&1

# Backup the Database
echo "Copying previous database from ${MYSQL_DATABASE}"
${MKDIR} "${TEMPDIR}/database"
${MYSQLDUMP} -u root -p"${wizard_mysql_password_root}" ${MYSQL_DATABASE} > ${TEMPDIR}/database/${MYSQL_DATABASE}-dbbackup.sql 2>&1

# Create backup archive
archive_name="$(basename "$TEMPDIR").tar.gz"
echo "Creating compressed archive of ${SC_DNAME} data in file $archive_name"
tar -C "$TEMPDIR" -czf "${SYNOPKG_PKGTMP}/$archive_name" . 2>&1

# Move archive to export directory
RSYNC_BAK_ARGS="--backup --suffix=.bak"
rsync -aX ${RSYNC_BAK_ARGS} "${SYNOPKG_PKGTMP}/$archive_name" "${wizard_export_path}/" 2>&1
echo "Backup file copied successfully to ${wizard_export_path}"

# Clean-up temporary files
${RM} "${TEMPDIR}"
${RM} "${SYNOPKG_PKGTMP}/$archive_name"
fi
# Clean-up temporary files
${RM} "${TEMPDIR}"
${RM} "${SYNOPKG_PKGTMP}/$archive_name"
fi
}

Expand Down

0 comments on commit e58329b

Please sign in to comment.