diff --git a/spk/selfoss/src/service-setup.sh b/spk/selfoss/src/service-setup.sh index 8e6d1c643ee1..654f94a94b3c 100755 --- a/spk/selfoss/src/service-setup.sh +++ b/spk/selfoss/src/service-setup.sh @@ -37,69 +37,67 @@ set_selfoss_permissions () service_postinst () { - if [ ${SYNOPKG_DSM_VERSION_MAJOR} -lt 7 ]; then - # Install the web interface - echo "Installing web interface" - ${MKDIR} ${SELFOSS_ROOT} - rsync -aX ${SYNOPKG_PKGDEST}/share/${SYNOPKG_PKGNAME}/ ${SELFOSS_ROOT} 2>&1 - - # Install web configurations - TEMPDIR="${SYNOPKG_PKGTMP}/web" - ${MKDIR} ${TEMPDIR} - WS_CFG_PATH="/usr/syno/etc/packages/WebStation" - WS_CFG_FILE="WebStation.json" - PHP_CFG_FILE="PHPSettings.json" - PHP_PROF_NAME="Default PHP 7.4 Profile" - WS_BACKEND="$(${JQ} -r '.default.backend' ${WS_CFG_PATH}/${WS_CFG_FILE})" - WS_PHP="$(${JQ} -r '.default.php' ${WS_CFG_PATH}/${WS_CFG_FILE})" - CFG_UPDATE="no" - # Check if Apache is the selected back-end - if [ ! "$WS_BACKEND" = "2" ]; then - echo "Set Apache as the back-end server" - ${JQ} '.default.backend = 2' ${WS_CFG_PATH}/${WS_CFG_FILE} > ${TEMPDIR}/${WS_CFG_FILE} - ${MV} ${WS_CFG_PATH}/${WS_CFG_FILE} ${WS_CFG_PATH}/${WS_CFG_FILE}.bak - rsync -aX ${TEMPDIR}/${WS_CFG_FILE} ${WS_CFG_PATH}/ 2>&1 - ${RM} ${TEMPDIR}/${WS_CFG_FILE} - CFG_UPDATE="yes" - fi - # Check if default PHP profile is selected - if [ -z "$WS_PHP" ] || [ "$WS_PHP" = "null" ]; then - echo "Enable default PHP profile" - # Locate default PHP profile - PHP_PROF_ID="$(${JQ} -r '. | to_entries[] | select(.value | type == "object" and .profile_desc == "'"$PHP_PROF_NAME"'") | .key' "${WS_CFG_PATH}/${PHP_CFG_FILE}")" - ${JQ} ".default.php = \"$PHP_PROF_ID\"" "${WS_CFG_PATH}/${WS_CFG_FILE}" > ${TEMPDIR}/${WS_CFG_FILE} - ${MV} ${WS_CFG_PATH}/${WS_CFG_FILE} ${WS_CFG_PATH}/${WS_CFG_FILE}.bak - rsync -aX ${TEMPDIR}/${WS_CFG_FILE} ${WS_CFG_PATH}/ 2>&1 - ${RM} ${TEMPDIR}/${WS_CFG_FILE} - CFG_UPDATE="yes" - fi - # Check for Selfoss PHP profile - if ! ${JQ} -e '.["com-synocommunity-packages-selfoss"]' "${WS_CFG_PATH}/${PHP_CFG_FILE}" >/dev/null; then - echo "Add PHP profile for Selfoss" - ${JQ} --slurpfile ocNode ${SYNOPKG_PKGDEST}/web/selfoss.json '.["com-synocommunity-packages-selfoss"] = $ocNode[0]' ${WS_CFG_PATH}/${PHP_CFG_FILE} > ${TEMPDIR}/${PHP_CFG_FILE} - ${MV} ${WS_CFG_PATH}/${PHP_CFG_FILE} ${WS_CFG_PATH}/${PHP_CFG_FILE}.bak - rsync -aX ${TEMPDIR}/${PHP_CFG_FILE} ${WS_CFG_PATH}/ 2>&1 - ${RM} ${TEMPDIR}/${PHP_CFG_FILE} - CFG_UPDATE="yes" - fi - # Check for Selfoss Apache config - if [ ! -f "/usr/local/etc/apache24/sites-enabled/selfoss.conf" ]; then - echo "Add Apache config for Selfoss" - rsync -aX ${SYNOPKG_PKGDEST}/web/selfoss.conf /usr/local/etc/apache24/sites-enabled/ 2>&1 - CFG_UPDATE="yes" - fi - # Restart Apache if configs have changed - if [ "$CFG_UPDATE" = "yes" ]; then - echo "Restart Apache to load new configs" - ${SYNOSVC} --restart pkgctl-Apache2.4 - fi - # Clean-up temporary files - ${RM} ${TEMPDIR} - fi - if [ "${SYNOPKG_PKG_STATUS}" = "INSTALL" ]; then - # Fix permissions if [ ${SYNOPKG_DSM_VERSION_MAJOR} -lt 7 ]; then + # Install the web interface + echo "Installing web interface" + ${MKDIR} ${SELFOSS_ROOT} + rsync -aX ${SYNOPKG_PKGDEST}/share/${SYNOPKG_PKGNAME}/ ${SELFOSS_ROOT} 2>&1 + + # Install web configurations + TEMPDIR="${SYNOPKG_PKGTMP}/web" + ${MKDIR} ${TEMPDIR} + WS_CFG_PATH="/usr/syno/etc/packages/WebStation" + WS_CFG_FILE="WebStation.json" + PHP_CFG_FILE="PHPSettings.json" + PHP_PROF_NAME="Default PHP 7.4 Profile" + WS_BACKEND="$(${JQ} -r '.default.backend' ${WS_CFG_PATH}/${WS_CFG_FILE})" + WS_PHP="$(${JQ} -r '.default.php' ${WS_CFG_PATH}/${WS_CFG_FILE})" + CFG_UPDATE="no" + # Check if Apache is the selected back-end + if [ ! "$WS_BACKEND" = "2" ]; then + echo "Set Apache as the back-end server" + ${JQ} '.default.backend = 2' ${WS_CFG_PATH}/${WS_CFG_FILE} > ${TEMPDIR}/${WS_CFG_FILE} + ${MV} ${WS_CFG_PATH}/${WS_CFG_FILE} ${WS_CFG_PATH}/${WS_CFG_FILE}.bak + rsync -aX ${TEMPDIR}/${WS_CFG_FILE} ${WS_CFG_PATH}/ 2>&1 + ${RM} ${TEMPDIR}/${WS_CFG_FILE} + CFG_UPDATE="yes" + fi + # Check if default PHP profile is selected + if [ -z "$WS_PHP" ] || [ "$WS_PHP" = "null" ]; then + echo "Enable default PHP profile" + # Locate default PHP profile + PHP_PROF_ID="$(${JQ} -r '. | to_entries[] | select(.value | type == "object" and .profile_desc == "'"$PHP_PROF_NAME"'") | .key' "${WS_CFG_PATH}/${PHP_CFG_FILE}")" + ${JQ} ".default.php = \"$PHP_PROF_ID\"" "${WS_CFG_PATH}/${WS_CFG_FILE}" > ${TEMPDIR}/${WS_CFG_FILE} + ${MV} ${WS_CFG_PATH}/${WS_CFG_FILE} ${WS_CFG_PATH}/${WS_CFG_FILE}.bak + rsync -aX ${TEMPDIR}/${WS_CFG_FILE} ${WS_CFG_PATH}/ 2>&1 + ${RM} ${TEMPDIR}/${WS_CFG_FILE} + CFG_UPDATE="yes" + fi + # Check for Selfoss PHP profile + if ! ${JQ} -e '.["com-synocommunity-packages-selfoss"]' "${WS_CFG_PATH}/${PHP_CFG_FILE}" >/dev/null; then + echo "Add PHP profile for Selfoss" + ${JQ} --slurpfile ocNode ${SYNOPKG_PKGDEST}/web/selfoss.json '.["com-synocommunity-packages-selfoss"] = $ocNode[0]' ${WS_CFG_PATH}/${PHP_CFG_FILE} > ${TEMPDIR}/${PHP_CFG_FILE} + ${MV} ${WS_CFG_PATH}/${PHP_CFG_FILE} ${WS_CFG_PATH}/${PHP_CFG_FILE}.bak + rsync -aX ${TEMPDIR}/${PHP_CFG_FILE} ${WS_CFG_PATH}/ 2>&1 + ${RM} ${TEMPDIR}/${PHP_CFG_FILE} + CFG_UPDATE="yes" + fi + # Check for Selfoss Apache config + if [ ! -f "/usr/local/etc/apache24/sites-enabled/selfoss.conf" ]; then + echo "Add Apache config for Selfoss" + rsync -aX ${SYNOPKG_PKGDEST}/web/selfoss.conf /usr/local/etc/apache24/sites-enabled/ 2>&1 + CFG_UPDATE="yes" + fi + # Restart Apache if configs have changed + if [ "$CFG_UPDATE" = "yes" ]; then + echo "Restart Apache to load new configs" + ${SYNOSVC} --restart pkgctl-Apache2.4 + fi + # Clean-up temporary files + ${RM} ${TEMPDIR} + + # Fix permissions set_selfoss_permissions ${SELFOSS_ROOT} fi fi @@ -107,38 +105,40 @@ service_postinst () service_postuninst () { - if [ ${SYNOPKG_DSM_VERSION_MAJOR} -lt 7 ]; then - # Remove the web interface - ${RM} ${SELFOSS_ROOT} + if [ "${SYNOPKG_PKG_STATUS}" = "UNINSTALL" ]; then + if [ ${SYNOPKG_DSM_VERSION_MAJOR} -lt 7 ]; then + # Remove the web interface + ${RM} ${SELFOSS_ROOT} - # Remove web configurations - TEMPDIR="${SYNOPKG_PKGTMP}/web" - ${MKDIR} ${TEMPDIR} - WS_CFG_PATH="/usr/syno/etc/packages/WebStation" - PHP_CFG_FILE="PHPSettings.json" - CFG_UPDATE="no" - # Check for Selfoss PHP profile - if ${JQ} -e '.["com-synocommunity-packages-selfoss"]' "${WS_CFG_PATH}/${PHP_CFG_FILE}" >/dev/null; then - echo "Removing PHP profile for Selfoss" - ${JQ} 'del(.["com-synocommunity-packages-selfoss"])' ${WS_CFG_PATH}/${PHP_CFG_FILE} > ${TEMPDIR}/${PHP_CFG_FILE} - ${MV} ${WS_CFG_PATH}/${PHP_CFG_FILE} ${WS_CFG_PATH}/${PHP_CFG_FILE}.bak - rsync -aX ${TEMPDIR}/${PHP_CFG_FILE} ${WS_CFG_PATH}/ 2>&1 - ${RM} ${TEMPDIR}/${PHP_CFG_FILE} - CFG_UPDATE="yes" - fi - # Check for Selfoss Apache config - if [ -f "/usr/local/etc/apache24/sites-enabled/selfoss.conf" ]; then - echo "Removing Apache config for Selfoss" - ${RM} /usr/local/etc/apache24/sites-enabled/selfoss.conf - CFG_UPDATE="yes" - fi - # Restart Apache if configs have changed - if [ "$CFG_UPDATE" = "yes" ]; then - echo "Restart Apache to load new configs" - ${SYNOSVC} --restart pkgctl-Apache2.4 + # Remove web configurations + TEMPDIR="${SYNOPKG_PKGTMP}/web" + ${MKDIR} ${TEMPDIR} + WS_CFG_PATH="/usr/syno/etc/packages/WebStation" + PHP_CFG_FILE="PHPSettings.json" + CFG_UPDATE="no" + # Check for Selfoss PHP profile + if ${JQ} -e '.["com-synocommunity-packages-selfoss"]' "${WS_CFG_PATH}/${PHP_CFG_FILE}" >/dev/null; then + echo "Removing PHP profile for Selfoss" + ${JQ} 'del(.["com-synocommunity-packages-selfoss"])' ${WS_CFG_PATH}/${PHP_CFG_FILE} > ${TEMPDIR}/${PHP_CFG_FILE} + ${MV} ${WS_CFG_PATH}/${PHP_CFG_FILE} ${WS_CFG_PATH}/${PHP_CFG_FILE}.bak + rsync -aX ${TEMPDIR}/${PHP_CFG_FILE} ${WS_CFG_PATH}/ 2>&1 + ${RM} ${TEMPDIR}/${PHP_CFG_FILE} + CFG_UPDATE="yes" + fi + # Check for Selfoss Apache config + if [ -f "/usr/local/etc/apache24/sites-enabled/selfoss.conf" ]; then + echo "Removing Apache config for Selfoss" + ${RM} /usr/local/etc/apache24/sites-enabled/selfoss.conf + CFG_UPDATE="yes" + fi + # Restart Apache if configs have changed + if [ "$CFG_UPDATE" = "yes" ]; then + echo "Restart Apache to load new configs" + ${SYNOSVC} --restart pkgctl-Apache2.4 + fi + # Clean-up temporary files + ${RM} ${TEMPDIR} fi - # Clean-up temporary files - ${RM} ${TEMPDIR} fi }