Skip to content

Commit

Permalink
Add PHP script launcher
Browse files Browse the repository at this point in the history
  • Loading branch information
mreid-tt committed Jan 29, 2024
1 parent 0535869 commit a3d4c60
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions spk/fengoffice/src/service-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ MYSQL="/usr/local/mariadb10/bin/mysql"
MYSQLDUMP="/usr/local/mariadb10/bin/mysqldump"
MYSQL_USER="fengoffice"
MYSQL_DATABASE="fengoffice"
PHP="/usr/local/bin/php74"
if [ "${SYNOPKG_DSM_VERSION_MAJOR}" -ge 7 ]; then
WEB_DIR="/var/services/web_packages"
else
Expand All @@ -24,20 +23,38 @@ fi
WEB_ROOT="${WEB_DIR}/${SYNOPKG_PKGNAME}"
SYNOSVC="/usr/syno/sbin/synoservice"

exec_php() {
PHP="/usr/local/bin/php74"
# Define the resource file
RESOURCE_FILE="${SYNOPKG_PKGDEST}/web/fengoffice.json"
# Extract extensions and assign to variable
if [ -f "$RESOURCE_FILE" ]; then
PHP_SETTINGS=$(jq -r '.extensions | map("-d extension=" + . + ".so") | join(" ")' "$RESOURCE_FILE")
else
PHP_SETTINGS=""
fi
# Fix for mysqli default socket on DSM 6
if [ ${SYNOPKG_DSM_VERSION_MAJOR} -lt 7 ]; then
PHP_SETTINGS="${PHP_SETTINGS} -d mysqli.default_socket=/run/mysqld/mysqld10.sock"
fi
COMMAND="${PHP} ${PHP_SETTINGS} $*"
if [ ${SYNOPKG_DSM_VERSION_MAJOR} -lt 7 ]; then
/bin/su "$WEB_USER" -s /bin/sh -c "${COMMAND}" >> ${LOG_FILE} 2>&1
else
$COMMAND >> ${LOG_FILE} 2>&1
fi
return $?
}

service_prestart ()
{
FENGOFFICE="${WEB_ROOT}/cron.php"
COMMAND="${PHP} ${FENGOFFICE}"
SLEEP_TIME="600"
# Main loop
while true; do
# Update
echo "Updating..."
if [ ${SYNOPKG_DSM_VERSION_MAJOR} -lt 7 ]; then
/bin/su "$WEB_USER" -s /bin/sh -c "${COMMAND}" >> ${LOG_FILE} 2>&1
else
$COMMAND >> ${LOG_FILE} 2>&1
fi
exec_php "${FENGOFFICE}"
# Wait
echo "Waiting ${SLEEP_TIME} seconds..."
sleep ${SLEEP_TIME}
Expand Down Expand Up @@ -148,14 +165,6 @@ service_postinst ()

# Run installer
if [ "${SYNOPKG_PKG_STATUS}" = "INSTALL" ]; then
# Define the resource file
RESOURCE_FILE="${SYNOPKG_PKGDEST}/web/fengoffice.json"
# Extract extensions and assign to variable
PHP_SETTINGS=$(jq -r '.extensions[] | "-d extension=" + . + ".so"' "$RESOURCE_FILE")
# Fix for mysqli default socket on DSM 6
if [ ${SYNOPKG_DSM_VERSION_MAJOR} -lt 7 ]; then
PHP_SETTINGS="${PHP_SETTINGS} -d mysqli.default_socket=/run/mysqld/mysqld10.sock"
fi
# Setup parameters for installation script
QUERY_STRING="\
script_installer_storage[database_type]=mysqli\
Expand All @@ -171,14 +180,10 @@ script_installer_storage[database_type]=mysqli\
&script_installer_storage[plugins][]=workspaces\
&submited=submited"
# Prepare environment
COMMAND="${PHP} ${PHP_SETTINGS} install_helper.php"
cd ${WEB_ROOT}/public/install/ || exit 1
# Execute based on DSM version
if [ ${SYNOPKG_DSM_VERSION_MAJOR} -lt 7 ]; then
/bin/su "$WEB_USER" -s /bin/sh -c "${COMMAND}" > /dev/null 2>&1
else
$COMMAND > /dev/null 2>&1
fi
echo "Run ${SC_DNAME} installer"
exec_php "install_helper.php"
fi
}

Expand Down Expand Up @@ -288,11 +293,6 @@ service_restore ()
fi

# Run update scripts
if [ ${SYNOPKG_DSM_VERSION_MAJOR} -lt 7 ]; then
/bin/su "$WEB_USER" -s /bin/sh -c "${PHP} ${WEB_ROOT}/public/upgrade/console.php ${INSTALLED_VERSION} ${PACKAGE_VERSION}" >> ${LOG_FILE} 2>&1
/bin/su "$WEB_USER" -s /bin/sh -c "${PHP} ${WEB_ROOT}/public/install/plugin-console.php update_all" >> ${LOG_FILE} 2>&1
else
${PHP} ${WEB_ROOT}/public/upgrade/console.php ${INSTALLED_VERSION} ${PACKAGE_VERSION} >> ${LOG_FILE} 2>&1
${PHP} ${WEB_ROOT}/public/install/plugin-console.php update_all >> ${LOG_FILE} 2>&1
fi
exec_php "${WEB_ROOT}/public/upgrade/console.php" "${INSTALLED_VERSION}" "${PACKAGE_VERSION}"
exec_php "${WEB_ROOT}/public/install/plugin-console.php" "update_all"
}

0 comments on commit a3d4c60

Please sign in to comment.