diff --git a/README.md b/README.md index ee60266..e450f4f 100644 --- a/README.md +++ b/README.md @@ -1,67 +1,42 @@ + + # Cachet for YunoHost [![Integration level](https://dash.yunohost.org/integration/cachet.svg)](https://dash.yunohost.org/appci/app/cachet) ![](https://ci-apps.yunohost.org/ci/badges/cachet.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/cachet.maintain.svg) -[![Install cachet with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=cachet) +[![Install Cachet with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=cachet) -> *This package allows you to install Cachet quickly and simply on a YunoHost server. -If you don't have YunoHost, please see [here](https://yunohost.org/#/install) to know how to install and enjoy it.* +*[Lire ce readme en français.](./README_fr.md)* + +> *This package allows you to install Cachet quickly and simply on a YunoHost server. +If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/install) to learn how to install it.* ## Overview + [Cachet](https://cachethq.io/) is a free, open source status page for your API, service or company. Built with all of the features that you'd expect from a status page, Cachet comes with a powerful API, a metric system, multiple user support, two factor authentication for added security and is easy to get setup. A powerful, self-hosted alternative to StatusPage.io and Status.io. -**Shipped version:** 2.3.18 + +**Shipped version:** 2.3.18~ynh2 + +**Demo:** https://demo.cachethq.io/ ## Screenshots -![](https://github.com/CachetHQ/Assets/raw/master/screenshots/main-interface.png) +![](./doc/screenshots/main-interface.png) -## Demo +## Documentation and resources -* [Official demo](https://demo.cachethq.io/) +* Official app website: https://cachethq.io/ +* Official admin documentation: https://docs.cachethq.io/ +* Upstream app code repository: https://github.com/CachetHQ/Cachet +* YunoHost documentation for this app: https://yunohost.org/app_cachet +* Report a bug: https://github.com/YunoHost-Apps/cachet_ynh/issues -## Configuration +## Developer info -Totally configurable through the Cachet application dashboard. - -## Documentation - - * Official documentation: https://docs.cachethq.io/ - * YunoHost documentation: If specific documentation is needed, feel free to contribute. - -## YunoHost specific features - -#### Multi-user support - -* LDAP or HTTP authentication aren't supported (see limitations below). -* This package supports multiple instances installation. - -#### Supported architectures - -* x86-64 - [![Build Status](https://ci-apps.yunohost.org/ci/logs/cachet.svg)](https://ci-apps.yunohost.org/ci/apps/cachet/) -* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/cachet.svg)](https://ci-apps-arm.yunohost.org/ci/apps/cachet/) - -## Limitations - -- Must necessarily be installed on domain root (see upstream issue [here](https://github.com/CachetHQ/Cachet/issues/1696)) -- Can't integrate with YunoHost SSO as LDAP support is not implemented yet (see upstream issue [here](https://github.com/CachetHQ/Cachet/issues/2108)) - - -## Additional information - -None. - -## Links - - * Report a bug: https://github.com/YunoHost-Apps/cachet_ynh/issues - * App website: https://cachethq.io/ - * Upstream app repository: https://github.com/CachetHQ/Cachet - * YunoHost website: https://yunohost.org/ - ---- - -## Developers info - -Please do your pull request to the [testing branch](https://github.com/YunoHost-Apps/cachet_ynh/tree/testing). +Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/cachet_ynh/tree/testing). To try the testing branch, please proceed like that. ``` @@ -69,3 +44,5 @@ sudo yunohost app install https://github.com/YunoHost-Apps/cachet_ynh/tree/testi or sudo yunohost app upgrade cachet -u https://github.com/YunoHost-Apps/cachet_ynh/tree/testing --debug ``` + +**More info regarding app packaging:** https://yunohost.org/packaging_apps \ No newline at end of file diff --git a/README_fr.md b/README_fr.md new file mode 100644 index 0000000..5b07b34 --- /dev/null +++ b/README_fr.md @@ -0,0 +1,44 @@ +# Cachet pour YunoHost + +[![Niveau d'intégration](https://dash.yunohost.org/integration/cachet.svg)](https://dash.yunohost.org/appci/app/cachet) ![](https://ci-apps.yunohost.org/ci/badges/cachet.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/cachet.maintain.svg) +[![Installer Cachet avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=cachet) + +*[Read this readme in english.](./README.md)* +*[Lire ce readme en français.](./README_fr.md)* + +> *Ce package vous permet d'installer Cachet rapidement et simplement sur un serveur YunoHost. +Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour savoir comment l'installer et en profiter.* + +## Vue d'ensemble + +[Cachet](https://cachethq.io/) is a free, open source status page for your API, service or company. Built with all of the features that you'd expect from a status page, Cachet comes with a powerful API, a metric system, multiple user support, two factor authentication for added security and is easy to get setup. A powerful, self-hosted alternative to StatusPage.io and Status.io. + + +**Version incluse :** 2.3.18~ynh2 + +**Démo :** https://demo.cachethq.io/ + +## Captures d'écran + +![](./doc/screenshots/main-interface.png) + +## Documentations et ressources + +* Site officiel de l'app : https://cachethq.io/ +* Documentation officielle de l'admin : https://docs.cachethq.io/ +* Dépôt de code officiel de l'app : https://github.com/CachetHQ/Cachet +* Documentation YunoHost pour cette app : https://yunohost.org/app_cachet +* Signaler un bug : https://github.com/YunoHost-Apps/cachet_ynh/issues + +## Informations pour les développeurs + +Merci de faire vos pull request sur la [branche testing](https://github.com/YunoHost-Apps/cachet_ynh/tree/testing). + +Pour essayer la branche testing, procédez comme suit. +``` +sudo yunohost app install https://github.com/YunoHost-Apps/cachet_ynh/tree/testing --debug +ou +sudo yunohost app upgrade cachet -u https://github.com/YunoHost-Apps/cachet_ynh/tree/testing --debug +``` + +**Plus d'infos sur le packaging d'applications :** https://yunohost.org/packaging_apps \ No newline at end of file diff --git a/check_process b/check_process index 5598173..7e60bfa 100644 --- a/check_process +++ b/check_process @@ -1,10 +1,10 @@ ;; Test complet ; Manifest - domain="domain.tld" (DOMAIN) - admin="john" (USER) + domain="domain.tld" + admin="john" admin_password="secret" language="en" - is_public=1 (PUBLIC|public=1|private=0) + is_public=1 ; Checks pkg_linter=1 setup_sub_dir=0 diff --git a/conf/.env b/conf/.env new file mode 100644 index 0000000..613075b --- /dev/null +++ b/conf/.env @@ -0,0 +1,44 @@ +APP_ENV=production +APP_DEBUG=false +APP_URL=http://__DOMAIN____PATH__ +APP_TIMEZONE=UTC +APP_KEY=__KEY__ +DEBUGBAR_ENABLED=false + +DB_DRIVER=mysql +DB_HOST=localhost +DB_UNIX_SOCKET=null +DB_DATABASE=__DB_NAME__ +DB_USERNAME=__DB_USER__ +DB_PASSWORD=__DB_PWD__ +DB_PORT=null +DB_PREFIX=null + +CACHE_DRIVER=file +SESSION_DRIVER=file +QUEUE_DRIVER=sync + +CACHET_BEACON=false +CACHET_EMOJI=false +CACHET_AUTO_TWITTER=true + +MAIL_DRIVER=sendmail +MAIL_HOST= +MAIL_PORT=25 +MAIL_USERNAME=null +MAIL_PASSWORD=null +MAIL_ADDRESS=__EMAIL__ +MAIL_NAME=__ADMIN__ +MAIL_ENCRYPTION=tls + +REDIS_HOST=null +REDIS_DATABASE=null +REDIS_PORT=null + +GITHUB_TOKEN=null + +NEXMO_KEY=null +NEXMO_SECRET=null +NEXMO_SMS_FROM=Cachet + +TRUSTED_PROXIES= diff --git a/conf/app.src b/conf/app.src index f52595a..7578381 100644 --- a/conf/app.src +++ b/conf/app.src @@ -3,4 +3,3 @@ SOURCE_SUM=7897744356bf81a2bcbc734f132eb5daafa889611c9c72fb2501afb3e9007cac SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true -SOURCE_FILENAME= diff --git a/conf/init-mysql.sql b/conf/init-mysql.sql index 5fd696a..87b2384 100644 --- a/conf/init-mysql.sql +++ b/conf/init-mysql.sql @@ -8,4 +8,4 @@ INSERT INTO `settings` (`id`, `name`, `value`) VALUES INSERT INTO `users` (`id`, `username`, `password`, `email`, `api_key`, `active`, `level`) VALUES -(1, '__USER__', '__PASSWORD_HASH__', '__EMAIL__', '', 1, 1); +(1, '__ADMIN__', '__PASSWORD_HASH__', '__EMAIL__', '', 1, 1); diff --git a/conf/nginx.conf b/conf/nginx.conf index 976e546..337e563 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -4,11 +4,6 @@ location __PATH__/ { # Path to source alias __FINALPATH__/public/ ; - # Force usage of https - if ($scheme = http) { - rewrite ^ https://$server_name$request_uri? permanent; - } - more_set_headers "Strict-Transport-Security: max-age=15768000"; index index.php; diff --git a/doc/DESCRIPTION.md b/doc/DESCRIPTION.md new file mode 100644 index 0000000..374be92 --- /dev/null +++ b/doc/DESCRIPTION.md @@ -0,0 +1 @@ +[Cachet](https://cachethq.io/) is a free, open source status page for your API, service or company. Built with all of the features that you'd expect from a status page, Cachet comes with a powerful API, a metric system, multiple user support, two factor authentication for added security and is easy to get setup. A powerful, self-hosted alternative to StatusPage.io and Status.io. diff --git a/doc/screenshots/main-interface.png b/doc/screenshots/main-interface.png new file mode 100644 index 0000000..4b6940a Binary files /dev/null and b/doc/screenshots/main-interface.png differ diff --git a/manifest.json b/manifest.json index 6e400a0..634d863 100644 --- a/manifest.json +++ b/manifest.json @@ -8,13 +8,20 @@ }, "version": "2.3.18~ynh2", "url": "https://cachethq.io/", + "upstream": { + "license": "BSD-3-Clause", + "website": "https://cachethq.io/", + "demo": "https://demo.cachethq.io/", + "admindoc": "https://docs.cachethq.io/", + "code": "https://github.com/CachetHQ/Cachet" + }, "license": "BSD-3-Clause", "maintainer": { "name": "JimboJoe", "email": "jimmy@monin.net" }, "requirements": { - "yunohost": ">= 4.1.7" + "yunohost": ">= 4.3.0" }, "multi_instance": true, "services": [ @@ -26,23 +33,16 @@ "install" : [ { "name": "domain", - "type": "domain", - "example": "domain.org" + "type": "domain" }, { "name": "admin", - "type": "user", - "example": "johndoe" + "type": "user" }, { - "name": "admin_password", + "name": "password", "type": "password", - "optional": true, - "ask": { - "en": "Set the password for admin user", - "fr": "Définissez le mot de passe pour l'utilisateur" - }, - "example": "supersecretpassword" + "optional": true }, { "name": "is_public", diff --git a/scripts/_common.sh b/scripts/_common.sh index 83c96be..a600a6a 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -6,7 +6,10 @@ YNH_PHP_VERSION="7.3" -extra_php_dependencies="php${YNH_PHP_VERSION}-gd php${YNH_PHP_VERSION}-mbstring php${YNH_PHP_VERSION}-xml php${YNH_PHP_VERSION}-mysql php${YNH_PHP_VERSION}-sqlite3" +pkg_dependencies="php${YNH_PHP_VERSION}-gd php${YNH_PHP_VERSION}-mbstring php${YNH_PHP_VERSION}-xml php${YNH_PHP_VERSION}-mysql php${YNH_PHP_VERSION}-sqlite3" + +# Composer version +YNH_COMPOSER_VERSION="1.10.17" #================================================= # PERSONAL HELPERS @@ -22,80 +25,3 @@ exec_artisan() { # EXPERIMENTAL HELPERS #================================================= -# Execute a command as another user -# usage: exec_as USER COMMAND [ARG ...] -ynh_exec_as() { - local USER=$1 - shift 1 - - if [[ $USER = $(whoami) ]]; then - eval "$@" - else - sudo -u "$USER" "$@" - fi -} - - -readonly YNH_DEFAULT_COMPOSER_VERSION=1.10.17 -# Declare the actual composer version to use. -# A packager willing to use another version of composer can override the variable into its _common.sh. -YNH_COMPOSER_VERSION=${YNH_COMPOSER_VERSION:-$YNH_DEFAULT_COMPOSER_VERSION} - -# Execute a command with Composer -# -# usage: ynh_composer_exec [--phpversion=phpversion] [--workdir=$final_path] --commands="commands" -# | arg: -v, --phpversion - PHP version to use with composer -# | arg: -w, --workdir - The directory from where the command will be executed. Default $final_path. -# | arg: -c, --commands - Commands to execute. -ynh_composer_exec () { - # Declare an array to define the options of this helper. - local legacy_args=vwc - declare -Ar args_array=( [v]=phpversion= [w]=workdir= [c]=commands= ) - local phpversion - local workdir - local commands - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - workdir="${workdir:-$final_path}" - phpversion="${phpversion:-$YNH_PHP_VERSION}" - - COMPOSER_HOME="$workdir/.composer" \ - php${phpversion} "$workdir/composer.phar" $commands \ - -d "$workdir" --quiet --no-interaction -} - -# Install and initialize Composer in the given directory -# -# usage: ynh_install_composer [--phpversion=phpversion] [--workdir=$final_path] [--install_args="--optimize-autoloader"] [--composerversion=composerversion] -# | arg: -v, --phpversion - PHP version to use with composer -# | arg: -w, --workdir - The directory from where the command will be executed. Default $final_path. -# | arg: -a, --install_args - Additional arguments provided to the composer install. Argument --no-dev already include -# | arg: -c, --composerversion - Composer version to install -ynh_install_composer () { - # Declare an array to define the options of this helper. - local legacy_args=vwa - declare -Ar args_array=( [v]=phpversion= [w]=workdir= [a]=install_args= [c]=composerversion=) - local phpversion - local workdir - local install_args - local composerversion - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - workdir="${workdir:-$final_path}" - phpversion="${phpversion:-$YNH_PHP_VERSION}" - install_args="${install_args:-}" - composerversion="${composerversion:-$YNH_COMPOSER_VERSION}" - - curl -sS https://getcomposer.org/installer \ - | COMPOSER_HOME="$workdir/.composer" \ - php${phpversion} -- --quiet --install-dir="$workdir" --version=$composerversion \ - || ynh_die "Unable to install Composer." - - # update dependencies to create composer.lock - ynh_composer_exec --phpversion="${phpversion}" --workdir="$workdir" --commands="install --no-dev $install_args" \ - || ynh_die "Unable to update core dependencies with Composer." -} - -#================================================= -# FUTURE OFFICIAL HELPERS -#================================================= diff --git a/scripts/backup b/scripts/backup index 995929f..ae47347 100644 --- a/scripts/backup +++ b/scripts/backup @@ -25,6 +25,7 @@ app=$YNH_APP_INSTANCE_NAME final_path=$(ynh_app_setting_get --app=$app --key=final_path) domain=$(ynh_app_setting_get --app=$app --key=domain) db_name=$(ynh_app_setting_get --app=$app --key=db_name) +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= # DECLARE DATA AND CONF FILES TO BACKUP @@ -47,7 +48,7 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" # BACKUP THE PHP-FPM CONFIGURATION #================================================= -ynh_backup --src_path="/etc/php/$YNH_PHP_VERSION/fpm/pool.d/$app.conf" +ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" #================================================= # BACKUP THE MYSQL DATABASE diff --git a/scripts/install b/scripts/install index 1ecbab6..f5227bd 100644 --- a/scripts/install +++ b/scripts/install @@ -27,16 +27,16 @@ ynh_abort_if_errors domain=$YNH_APP_ARG_DOMAIN path_url="/" admin=$YNH_APP_ARG_ADMIN -admin_password=$YNH_APP_ARG_ADMIN_PASSWORD +password=$YNH_APP_ARG_PASSWORD is_public=$YNH_APP_ARG_IS_PUBLIC language=$YNH_APP_ARG_LANGUAGE +email=$(ynh_user_get_info $admin mail) app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= - ynh_script_progression --message="Validating installation parameters..." --weight=1 final_path=/var/www/$app @@ -53,13 +53,9 @@ ynh_script_progression --message="Storing installation settings..." --weight=1 ynh_app_setting_set --app=$app --key=domain --value=$domain ynh_app_setting_set --app=$app --key=path --value=$path_url ynh_app_setting_set --app=$app --key=admin --value=$admin -ynh_app_setting_set --app=$app --key=admin_password --value=$admin_password +ynh_app_setting_set --app=$app --key=password --value=$password ynh_app_setting_set --app=$app --key=language --value=$language -#================================================= -# STANDARD MODIFICATIONS -#================================================= - #================================================= # CREATE A MYSQL DATABASE #================================================= @@ -70,6 +66,21 @@ db_user=$db_name ynh_app_setting_set --app=$app --key=db_name --value=$db_name ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name +#================================================= +# INSTALL DEPENDENCIES +#================================================= +ynh_script_progression --message="Installing dependencies..." --weight=4 + +ynh_install_app_dependencies $pkg_dependencies + +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Configuring system user..." --weight=1 + +# Create a system user +ynh_system_user_create --username=$app --home_dir="$final_path" + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -87,51 +98,24 @@ ynh_script_progression --message="Configuring NGINX web server..." --weight=1 # Create a dedicated NGINX config ynh_add_nginx_config -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." --weight=2 - -# Create a system user -ynh_system_user_create --username=$app - #================================================= # PHP-FPM CONFIGURATION #================================================= ynh_script_progression --message="Configuring PHP-FPM..." --weight=8 # Create a dedicated php-fpm config -ynh_add_fpm_config --package="$extra_php_dependencies" +ynh_add_fpm_config #================================================= -# SPECIFIC SETUP +# ADD A CONFIGURATION #================================================= -# PRE-CONFIGURE CACHET -#================================================= -ynh_script_progression --message="Configuring Cachet..." --weight=10 +ynh_script_progression --message="Adding a configuration file..." --weight=1 -env_conf="$final_path/.env" +key=$(ynh_string_random 24) +ynh_add_config --template="../conf/.env" --destination="$final_path/.env" -cp $final_path/.env.example $env_conf -ynh_replace_string --match_string="APP_URL=http://localhost" --replace_string="APP_URL=https://$domain$path_url" --target_file="$env_conf" -ynh_replace_string --match_string="APP_KEY=SomeRandomString" --replace_string="APP_KEY=$(ynh_string_random 24)" --target_file="$env_conf" - -ynh_replace_string --match_string="DB_DATABASE=cachet" --replace_string="DB_DATABASE=$db_name" --target_file="$env_conf" -ynh_replace_string --match_string="DB_USERNAME=homestead" --replace_string="DB_USERNAME=$db_name" --target_file="$env_conf" -ynh_replace_string --match_string="DB_PASSWORD=secret" --replace_string="DB_PASSWORD=$db_pwd" --target_file="$env_conf" - -ynh_replace_string --match_string="MAIL_DRIVER=log" --replace_string="MAIL_DRIVER=sendmail" --target_file="$env_conf" -ynh_replace_string --match_string="MAIL_HOST=null" --replace_string="MAIL_HOST=" --target_file="$env_conf" -ynh_replace_string --match_string="MAIL_PORT=null" --replace_string="MAIL_PORT=25" --target_file="$env_conf" -ynh_replace_string --match_string="MAIL_USERNAME=null" --replace_string="MAIL_USERNAME=null" --target_file="$env_conf" -ynh_replace_string --match_string="MAIL_PASSWORD=null" --replace_string="MAIL_PASSWORD=null" --target_file="$env_conf" -admin_mail="$(ynh_user_get_info $admin mail)" -ynh_replace_string --match_string="MAIL_ADDRESS=null" --replace_string="MAIL_ADDRESS=$admin_mail" --target_file="$env_conf" -ynh_replace_string --match_string="MAIL_NAME=null" --replace_string="MAIL_NAME=$admin" --target_file="$env_conf" - -# Disable reporting to CachetHQ servers -ynh_replace_string --match_string="CACHET_BEACON=true" --replace_string="CACHET_BEACON=false" --target_file="$env_conf" -ynh_store_file_checksum "$env_conf" +chmod 400 "$final_path/.env" +chown $app:$app "$final_path/.env" #================================================= # INSTALL AND INITIALIZE COMPOSER @@ -153,14 +137,14 @@ exec_artisan "cachet:install" # Populate MySQL database sql_conf="../conf/init-mysql.sql" ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain$path_url" --target_file="$sql_conf" -ynh_replace_string --match_string="__USER__" --replace_string="$admin" --target_file="$sql_conf" +ynh_replace_string --match_string="__ADMIN__" --replace_string="$admin" --target_file="$sql_conf" ynh_replace_string --match_string="__LANGUAGE__" --replace_string="$language" --target_file="$sql_conf" -password_hash="$(cd $final_path ; php$YNH_PHP_VERSION artisan tinker -q --no-ansi <<< "echo Hash::make('$admin_password');" |head -n 1)" +password_hash="$(cd $final_path ; php$YNH_PHP_VERSION artisan tinker -q --no-ansi <<< "echo Hash::make('$password');" |head -n 1)" password_pash="${password_hash::-1}" # Remove last character ynh_replace_string --match_string="__PASSWORD_HASH__" --replace_string="$password_pash" --target_file="$sql_conf" -ynh_replace_string --match_string="__EMAIL__" --replace_string="$admin_mail" --target_file="$sql_conf" +ynh_replace_string --match_string="__EMAIL__" --replace_string="$email" --target_file="$sql_conf" ynh_mysql_connect_as --user="$db_name" --password="$db_pwd" --database="$db_name" \ < "$sql_conf" @@ -180,8 +164,9 @@ ynh_store_file_checksum --file="$production_conf" #================================================= # Set permissions to app files -chown -R root: $final_path -chown -R $app: "${final_path}/.env" "${final_path}/storage/" "${final_path}/bootstrap/" +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" #================================================= # SETUP SSOWAT diff --git a/scripts/restore b/scripts/restore index 13e1968..c42e287 100644 --- a/scripts/restore +++ b/scripts/restore @@ -13,10 +13,6 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= -ynh_clean_setup () { - #### Remove this function if there's nothing to clean before calling the remove script. - true -} # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -32,16 +28,14 @@ path_url=$(ynh_app_setting_get --app=$app --key=path) final_path=$(ynh_app_setting_get --app=$app --key=final_path) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= ynh_script_progression --message="Validating restoration parameters..." --weight=1 -ynh_webpath_available --domain=$domain --path_url=$path_url \ - || ynh_die --message="Path not available: ${domain}${path_url}" -test ! -d $final_path \ - || ynh_die --message="There is already a directory: $final_path " +test ! -d $final_path || ynh_die --message="There is already a directory: $final_path " #================================================= # STANDARD RESTORATION STEPS @@ -64,26 +58,31 @@ ynh_restore_file --origin_path="$final_path" ynh_script_progression --message="Recreating the dedicated system user..." --weight=3 # Create the dedicated user (if not existing) -ynh_system_user_create --username=$app +ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # RESTORE USER RIGHTS #================================================= # Restore permissions on app files -chown -R root: $final_path -chown -R $app: "${final_path}/.env" "${final_path}/storage/" "${final_path}/bootstrap/" +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" + +#================================================= +# REINSTALL DEPENDENCIES +#================================================= +ynh_script_progression --message="Reinstalling dependencies..." --weight=7 + +# Define and install dependencies +ynh_install_app_dependencies $pkg_dependencies #================================================= # RESTORE THE PHP-FPM CONFIGURATION #================================================= ynh_script_progression --message="Reconfiguring PHP-FPM..." --weight=6 -# Restore the file first, so it can have a backup if different -ynh_restore_file --origin_path="/etc/php/$YNH_PHP_VERSION/fpm/pool.d/$app.conf" - -# Recreate a dedicated PHP-FPM config -ynh_add_fpm_config --package="$extra_php_dependencies" +ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" #================================================= # SPECIFIC RESTORATION diff --git a/scripts/upgrade b/scripts/upgrade index f5c4674..d35b422 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -29,6 +29,20 @@ db_name=$(ynh_app_setting_get --app=$app --key=db_name) upgrade_type=$(ynh_check_app_version_changed) +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=4 + +# Backup the current version of the app +ynh_backup_before_upgrade +ynh_clean_setup () { + # restore it if the upgrade fails + ynh_restore_upgradebackup +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= @@ -54,18 +68,12 @@ if ynh_legacy_permissions_exists; then fi #================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +# CREATE DEDICATED USER #================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=4 +ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 -# Backup the current version of the app -ynh_backup_before_upgrade -ynh_clean_setup () { - # restore it if the upgrade fails - ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors +# Create a dedicated user (if not existing) +ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # STANDARD UPGRADE STEPS @@ -75,7 +83,7 @@ ynh_abort_if_errors ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=1 # Recreate a dedicated PHP-FPM config -ynh_add_fpm_config --package="$extra_php_dependencies" +ynh_add_fpm_config #================================================= # SET MAINTENANCE MODE ON @@ -117,23 +125,17 @@ ynh_script_progression --message="Upgrading NGINX web server configuration..." - ynh_add_nginx_config #================================================= -# CREATE DEDICATED USER +# UPGRADE DEPENDENCIES #================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 +ynh_script_progression --message="Upgrading dependencies..." --weight=6 -# Create a dedicated user (if not existing) -ynh_system_user_create --username=$app +ynh_install_app_dependencies $pkg_dependencies #================================================= # SPECIFIC UPGRADE #================================================= - ynh_script_progression --message="Upgrading Cachet configuration and dependencies..." --weight=20 -#================================================= -# INSTALL AND INITIALIZE COMPOSER -#================================================= - ynh_install_composer --install_args="--optimize-autoloader" #================================================= @@ -150,8 +152,9 @@ ynh_secure_remove --file=bootstrap/cache/* #================================================= # Set permissions on app files -chown -R root: $final_path -chown -R $app: "${final_path}/.env" "${final_path}/storage/" "${final_path}/bootstrap/" +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" #================================================= # SET MAINTENANCE MODE OFF