diff --git a/check_process b/check_process index ed441aa..cbcb32c 100644 --- a/check_process +++ b/check_process @@ -1,28 +1,23 @@ -# See here for more information -# https://github.com/YunoHost/package_check#syntax-check_process-file - -# Move this file from check_process.default to check_process when you have filled it. - ;; Test complet ; Manifest domain="domain.tld" (DOMAIN) path="/path" (PATH) admin="john" (USER) - language="fr" + language="en" is_public=1 (PUBLIC|public=1|private=0) password="pass" - port="666" (PORT) + install_profil="minimal" ; Checks pkg_linter=1 - setup_sub_dir=0 - setup_root=0 + setup_sub_dir=1 + setup_root=1 setup_nourl=0 - setup_private=0 - setup_public=0 - upgrade=00 - backup_restore=0 - multi_instance=0 - incorrect_path=0 + setup_private=1 + setup_public=1 + upgrade=0 + backup_restore=1 + multi_instance=1 + incorrect_path=1 port_already_use=0 change_url=0 ;;; Levels @@ -39,10 +34,5 @@ Level 9=0 Level 10=0 ;;; Options -Email= -Notification=none -;;; Upgrade options - ; commit=CommitHash - name=Name and date of the commit. - manifest_arg=domain=DOMAIN&path=PATH&admin=USER&language=fr&is_public=1&password=pass&port=666& - +Email=yalh@yahoo.com +Notification=all diff --git a/conf/composer.json b/conf/composer.json new file mode 100644 index 0000000..6c096d5 --- /dev/null +++ b/conf/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "drush/drush": "8.*" + } +} diff --git a/conf/cron b/conf/cron new file mode 100644 index 0000000..41d21c6 --- /dev/null +++ b/conf/cron @@ -0,0 +1,2 @@ +H * * * * __APP__ /usr/bin/env PATH=__FINALPATH__/.composer/vendor/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin COLUMNS=72 drush --quiet @__APP__ core-cron +0 22 * * * __APP__ /usr/bin/env PATH=__FINALPATH__/.composer/vendor/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin COLUMNS=72 drush --quiet @__APP__ pm-update -y \ No newline at end of file diff --git a/conf/nginx.conf b/conf/nginx.conf index f2277ea..c892fbf 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -2,23 +2,63 @@ location __PATH__/ { # Path to source - alias __FINALPATH__/ ; + alias __FINALPATH__/__APP__/ ; + index index.php; + if (!-e $request_filename) + { + rewrite ^__PATH__/(.+)$ __PATH__/index.php?q=$1 last; + } # Force usage of https if ($scheme = http) { rewrite ^ https://$server_name$request_uri? permanent; } -### Example PHP configuration (remove it if not used) index index.php; # Common parameter to increase upload size limit in conjunction with dedicated php-fpm file #client_max_body_size 50M; try_files $uri $uri/ index.php; - location ~ [^/]\.php(/|$) { + + location ~ /favicon.ico { + log_not_found off; + access_log off; + } + + location ~ /robots.txt { + allow all; + log_not_found off; + access_log off; + } + + # Very rarely should these ever be accessed outside of your lan + location ~* \.(txt|log)$ { + allow 192.168.0.0/16; + deny all; + } + + # Allow "Well-Known URIs" as per RFC 5785 + location ~* ^/.well-known/ { + allow all; + } + + # Block access to "hidden" files and directories whose names begin with a + # period. This includes directories used by version control systems such + # as Subversion or Git to store control files. + location ~ (^|/)\. { + return 403; + } + + # Don't allow direct access to PHP files in the vendor directory. + location ~ /vendor/.*\.php$ { + deny all; + return 404; + } + + location ~ '[^/]\.php$|^/update.php' { fastcgi_split_path_info ^(.+?\.php)(/.*)$; - fastcgi_pass unix:/var/run/php/php7.0-fpm-__NAME__.sock; + fastcgi_pass unix:/var/run/php/php7.2-fpm-__APP__.sock; fastcgi_index index.php; include fastcgi_params; @@ -26,8 +66,28 @@ location __PATH__/ { fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $request_filename; } -### End of PHP configuration part + + # Fighting with Styles? This little gem is amazing. + location ~ ^/sites/.*/files/styles/ { + try_files $uri @rewrite; + } + + # Handle private files through Drupal. Private file's path can come + # with a language prefix. + location ~ ^(/[a-z\-]+)?/system/files/ { + try_files $uri /index.php?$query_string; + } + + location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ { + try_files $uri @rewrite; + expires max; + log_not_found off; + } # Include SSOWAT user panel. include conf.d/yunohost_panel.conf.inc; } + +location @rewrite { + rewrite ^/(.*)$ /index.php?q=$1; +} \ No newline at end of file diff --git a/conf/php-fpm.conf b/conf/php-fpm.conf index ab5dca9..a7b230f 100644 --- a/conf/php-fpm.conf +++ b/conf/php-fpm.conf @@ -33,7 +33,7 @@ group = __USER__ ; (IPv6 and IPv4-mapped) on a specific port; ; '/path/to/unix/socket' - to listen on a unix socket. ; Note: This value is mandatory. -listen = /var/run/php/php7.0-fpm-__NAMETOCHANGE__.sock +listen = /var/run/php/php7.2-fpm-__NAMETOCHANGE__.sock ; Set listen(2) backlog. ; Default Value: 511 (-1 on FreeBSD and OpenBSD) @@ -358,7 +358,7 @@ request_terminate_timeout = 1d ; Chdir to this directory at the start. ; Note: relative path can be used. ; Default Value: current directory or / when chroot -chdir = __FINALPATH__ +chdir = __FINALPATH__/__NAMETOCHANGE__ ; Redirect worker stdout and stderr into main error log. If not set, stdout and ; stderr will be redirected to /dev/null according to FastCGI specs. diff --git a/conf/systemd.service b/conf/systemd.service deleted file mode 100644 index 76cdf64..0000000 --- a/conf/systemd.service +++ /dev/null @@ -1,13 +0,0 @@ -[Unit] -Description=Small description of the service -After=network.target - -[Service] -Type=simple -User=__APP__ -Group=__APP__ -WorkingDirectory=__FINALPATH__/ -ExecStart=__FINALPATH__/script >> /var/log/__APP__/__APP__.log 2>&1 - -[Install] -WantedBy=multi-user.target diff --git a/conf/yoursite.aliases.drushrc.php b/conf/yoursite.aliases.drushrc.php new file mode 100644 index 0000000..9d11437 --- /dev/null +++ b/conf/yoursite.aliases.drushrc.php @@ -0,0 +1,37 @@ +> ~/.drush/mysite.aliases.drushrc.php + * Then edit that file to wrap the code in tags. + */ + +/** + * Local alias + * Set the root and site_path values to point to your local site + */ +$aliases['__APP__'] = array( + 'root' => '__FINALPATH__/__APP__/', + 'uri' => 'https://__DOMAIN____PATH_URL__', + 'path-aliases' => array( + '%dump-dir' => '/tmp', + ), +); +?> \ No newline at end of file diff --git a/manifest.json b/manifest.json index 5634cec..a468a61 100644 --- a/manifest.json +++ b/manifest.json @@ -35,8 +35,8 @@ "name": "path", "type": "path", "ask": { - "en": "Choose a path for Drupal 7", - "fr": "Choisissez un chemin pour Drupal 7" + "en": "Choose a path for Drupal 7", + "fr": "Choisissez un chemin pour Drupal 7" }, "example": "/example", "default": "/example" @@ -67,7 +67,7 @@ "fr": "Choisissez la langue de l'application" }, "choices": ["fr", "en"], - "default": "fr" + "default": "en" }, { "name": "password", @@ -81,6 +81,16 @@ "fr": "Utilisez le champ aide pour ajouter une information à l'intention de l'administrateur à propos de cette question." }, "example": "Choose a password" + }, + { + "name": "install_profil", + "type": "string", + "ask": { + "en": "Choose the Drupal 7 install profile to use", + "fr": "Choisissez le profile d'installation de Drupal 7" + }, + "choices": ["minimal", "standard"], + "default": "standard" } ] } diff --git a/scripts/_common.sh b/scripts/_common.sh index 8bb05b4..c98bf55 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -7,6 +7,8 @@ # dependencies used by the app pkg_dependencies="deb1 deb2" +extra_pkg_dependencies="php7.2-fpm php7.2-cli php7.2-gd php7.2-mysql php7.2-xml php7.2-ldap php7.2-mbstring php7.2-uploadprogress" + #================================================= # PERSONAL HELPERS #================================================= diff --git a/scripts/backup b/scripts/backup index 3ad6e47..7682154 100644 --- a/scripts/backup +++ b/scripts/backup @@ -53,7 +53,7 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= ynh_print_info --message="Backing up php-fpm configuration..." -ynh_backup --src_path="/etc/php/7.0/fpm/pool.d/$app.conf" +ynh_backup --src_path="/etc/php/7.2/fpm/pool.d/$app.conf" #================================================= # BACKUP THE MYSQL DATABASE @@ -64,20 +64,6 @@ ynh_mysql_dump_db --database="$db_name" > db.sql #================================================= # SPECIFIC BACKUP -#================================================= -# BACKUP LOGROTATE -#================================================= -ynh_print_info --message="Backing up logrotate configuration..." - -ynh_backup --src_path="/etc/logrotate.d/$app" - -#================================================= -# BACKUP SYSTEMD -#================================================= -ynh_print_info --message="Backing up systemd configuration..." - -ynh_backup --src_path="/etc/systemd/system/$app.service" - #================================================= # BACKUP A CRON FILE #================================================= diff --git a/scripts/install b/scripts/install index abb1f45..2513228 100644 --- a/scripts/install +++ b/scripts/install @@ -7,16 +7,15 @@ #================================================= source _common.sh +source ynh_add_extra_apt_repos__3 +source ynh_install_php__3 +source ynh_composer__2 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 @@ -30,17 +29,10 @@ admin=$YNH_APP_ARG_ADMIN is_public=$YNH_APP_ARG_IS_PUBLIC language=$YNH_APP_ARG_LANGUAGE password=$YNH_APP_ARG_PASSWORD +install_profil=$YNH_APP_ARG_INSTALL_PROFIL + +admin_mail=$(ynh_user_get_info $admin 'mail') -### If it's a multi-instance app, meaning it can be installed several times independently -### The id of the app as stated in the manifest is available as $YNH_APP_ID -### The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...) -### The app instance name is available as $YNH_APP_INSTANCE_NAME -### - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample -### - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2 -### - ynhexample__{N} for the subsequent installations, with N=3,4, ... -### The app instance name is probably what interests you most, since this is -### guaranteed to be unique. This is a good unique identifier to define installation path, -### db names, ... app=$YNH_APP_INSTANCE_NAME #================================================= @@ -48,8 +40,6 @@ app=$YNH_APP_INSTANCE_NAME #================================================= ynh_print_info --message="Validating installation parameters..." -### If the app uses nginx as web server (written in HTML/PHP in most cases), the final path should be "/var/www/$app". -### If the app provides an internal web server (or uses another application server such as uwsgi), the final path should be "/opt/yunohost/$app" final_path=/var/www/$app test ! -e "$final_path" || ynh_die "This path already contains a folder" @@ -66,80 +56,46 @@ 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=is_public --value=$is_public ynh_app_setting_set --app=$app --key=language --value=$language +ynh_app_setting_set --app=$app --key=install_profil --value=$install_profil #================================================= # STANDARD MODIFICATIONS -#================================================= -# FIND AND OPEN A PORT -#================================================= -ynh_print_info --message="Configuring firewall..." - -### Use these lines if you have to open a port for the application -### `ynh_find_port` will find the first available port starting from the given port. -### If you're not using these lines: -### - Remove the section "CLOSE A PORT" in the remove script - -# Find a free port -port=$(ynh_find_port 8095) -# Open this port -ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port -ynh_app_setting_set --app=$app --key=port --value=$port - #================================================= # INSTALL DEPENDENCIES #================================================= ynh_print_info --message="Installing dependencies..." -### `ynh_install_app_dependencies` allows you to add any "apt" dependencies to the package. -### Those deb packages will be installed as dependencies of this package. -### If you're not using this helper: -### - Remove the section "REMOVE DEPENDENCIES" in the remove script -### - Remove the variable "pkg_dependencies" in _common.sh -### - As well as the section "REINSTALL DEPENDENCIES" in the restore script -### - And the section "UPGRADE DEPENDENCIES" in the upgrade script +ynh_install_php --phpversion="7.2" --package="$extra_pkg_dependencies" -ynh_install_app_dependencies $pkg_dependencies +#ynh_install_app_dependencies $pkg_dependencies #================================================= # CREATE A MYSQL DATABASE #================================================= ynh_print_info --message="Creating a MySQL database..." -### Use these lines if you need a database for the application. -### `ynh_mysql_setup_db` will create a database, an associated user and a ramdom password. -### The password will be stored as 'mysqlpwd' into the app settings, -### and will be available as $db_pwd -### If you're not using these lines: -### - Remove the section "BACKUP THE MYSQL DATABASE" in the backup script -### - Remove also the section "REMOVE THE MYSQL DATABASE" in the remove script -### - As well as the section "RESTORE THE MYSQL DATABASE" in the restore script - db_name=$(ynh_sanitize_dbid $app) +db_user=$db_name ynh_app_setting_set --app=$app --key=db_name --value=$db_name -ynh_mysql_setup_db --db_user=$db_name --db_name=$db_name +ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_print_info --message="Setting up source files..." -### `ynh_setup_source` is used to install an app from a zip or tar.gz file, -### downloaded from an upstream source, like a git repository. -### `ynh_setup_source` use the file conf/app.src - ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source --dest_dir="$final_path" +#ynh_setup_source --dest_dir="$final_path" +mkdir -p "$final_path" #================================================= # NGINX CONFIGURATION #================================================= ynh_print_info --message="Configuring nginx web server..." -### `ynh_add_nginx_config` will use the file conf/nginx.conf - # Create a dedicated nginx config -ynh_add_nginx_config +ynh_add_nginx_config "app" #================================================= # CREATE DEDICATED USER @@ -147,102 +103,86 @@ ynh_add_nginx_config ynh_print_info --message="Configuring system user..." # Create a system user -ynh_system_user_create --username=$app +ynh_system_user_create --username=$app --home_dir="$final_path" + +#================================================= +# SPECIFIC SETUP +#================================================= +# CREATE DRUSH ALIAS +#================================================= +ynh_print_info --message="Creating Drush alias..." + +mkdir -p "$final_path/.drush" + +cp -f "../conf/yoursite.aliases.drushrc.php" "$final_path/.drush/$app.aliases.drushrc.php" + +ynh_replace_string "__FINALPATH__" "$final_path" "$final_path/.drush/$app.aliases.drushrc.php" +ynh_replace_string "__APP__" "$app" "$final_path/.drush/$app.aliases.drushrc.php" +ynh_replace_string "__DOMAIN__" "$domain" "$final_path/.drush/$app.aliases.drushrc.php" +ynh_replace_string "__PATH_URL__" "$path_url" "$final_path/.drush/$app.aliases.drushrc.php" + +#================================================= +# INSTALL COMPOSER +#================================================= +ynh_print_info --message="Installing Composer..." + +mkdir -p "$final_path/.composer" + +cp -f "../conf/composer.json" "$final_path/.composer/composer.json" + +ynh_install_composer --phpversion="7.2" --workdir="$final_path/.composer" + +export PATH="$final_path/.composer/vendor/bin:$PATH" + +#================================================= +# INSTALL DRUPAL +#================================================= +ynh_print_info --message="Installing Drupal..." + +chown -R $app: $final_path + +pushd "$final_path" + sudo -u $app env PATH=$PATH drush pm-download drupal-7 --drupal-project-rename=$app +popd + +sudo -u $app env PATH=$PATH drush @$app site-install $install_profil --account-name=$admin --account-pass=$password --account-mail=$admin_mail --db-url=mysql://$db_user:$db_pwd@localhost/$db_name --site-name="$app" --locale=$language --yes +sudo -u $app env PATH=$PATH drush @$app pm-download drush_language +#sudo -u $app env PATH=$PATH drush @$app pm-download ldap +#sudo -u $app env PATH=$PATH drush @$app pm-enable -y ldap_servers ldap_user ldap_authentication ldap_authorization ldap_authorization_drupal_role +sudo -u $app env PATH=$PATH drush @$app pm-download l10n_update +sudo -u $app env PATH=$PATH drush @$app pm-enable -y l10n_update +sudo -u $app env PATH=$PATH drush @$app language-add $language +sudo -u $app env PATH=$PATH drush @$app language-default $language +sudo -u $app env PATH=$PATH drush @$app cache-clear drush +sudo -u $app env PATH=$PATH drush @$app l10n-update-refresh +sudo -u $app env PATH=$PATH drush @$app l10n-update +sudo -u $app env PATH=$PATH drush @$app pm-update +sudo -u $app env PATH=$PATH drush @$app core-cron + +#================================================= +# SET THE CRON FILE +#================================================= +ynh_print_info --message="Set the cron file" + +cp ../conf/cron /etc/cron.d/$app + +ynh_replace_string "__FINALPATH__" "$final_path" /etc/cron.d/$app +ynh_replace_string "__APP__" "$app" /etc/cron.d/$app #================================================= # PHP-FPM CONFIGURATION #================================================= ynh_print_info --message="Configuring php-fpm..." -### `ynh_add_fpm_config` is used to set up a PHP config. -### You can remove it if your app doesn't use PHP. -### `ynh_add_fpm_config` will use the files conf/php-fpm.conf and conf/php-fpm.ini -### If you're not using these lines: -### - You can remove these files in conf/. -### - Remove the section "BACKUP THE PHP-FPM CONFIGURATION" in the backup script -### - Remove also the section "REMOVE PHP-FPM CONFIGURATION" in the remove script -### - As well as the section "RESTORE THE PHP-FPM CONFIGURATION" in the restore script -### With the reload at the end of the script. -### - And the section "PHP-FPM CONFIGURATION" in the upgrade script - # Create a dedicated php-fpm config -ynh_add_fpm_config - -#================================================= -# SPECIFIC SETUP -#================================================= -# ... -#================================================= - -#================================================= -# SETUP SYSTEMD -#================================================= -ynh_print_info --message="Configuring a systemd service..." - -### `ynh_systemd_config` is used to configure a systemd script for an app. -### It can be used for apps that use sysvinit (with adaptation) or systemd. -### Have a look at the app to be sure this app needs a systemd script. -### `ynh_systemd_config` will use the file conf/systemd.service -### If you're not using these lines: -### - You can remove those files in conf/. -### - Remove the section "BACKUP SYSTEMD" in the backup script -### - Remove also the section "STOP AND REMOVE SERVICE" in the remove script -### - As well as the section "RESTORE SYSTEMD" in the restore script -### - And the section "SETUP SYSTEMD" in the upgrade script - -# Create a dedicated systemd config -ynh_add_systemd_config - -#================================================= -# SETUP APPLICATION WITH CURL -#================================================= - -### Use these lines only if the app installation needs to be finalized through -### web forms. We generally don't want to ask the final user, -### so we're going to use curl to automatically fill the fields and submit the -### forms. - -# Set right permissions for curl install -chown -R $app: $final_path - -# Set the app as temporarily public for curl call -ynh_print_info --message="Configuring SSOwat..." -ynh_app_setting_set --app=$app --key=skipped_uris --value="/" -# Reload SSOwat config -yunohost app ssowatconf - -# Reload Nginx -systemctl reload nginx - -# Installation with curl -ynh_print_info --message="Finalizing installation..." -ynh_local_curl "/INSTALL_PATH" "key1=value1" "key2=value2" "key3=value3" - -# Remove the public access -if [ $is_public -eq 0 ] -then - ynh_app_setting_delete --app=$app --key=skipped_uris -fi - -#================================================= -# MODIFY A CONFIG FILE -#================================================= - -### `ynh_replace_string` is used to replace a string in a file. -### (It's compatible with sed regular expressions syntax) - -ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$final_path/CONFIG_FILE" +ynh_add_fpm_config --phpversion="7.2" #================================================= # STORE THE CONFIG FILE CHECKSUM #================================================= -### `ynh_store_file_checksum` is used to store the checksum of a file. -### That way, during the upgrade script, by using `ynh_backup_if_checksum_is_different`, -### you can make a backup of this file before modifying it again if the admin had modified it. - # Calculate and store the config file checksum into the app settings -ynh_store_file_checksum --file="$final_path/CONFIG_FILE" +ynh_store_file_checksum --file="$final_path/$app/sites/default/settings.php" #================================================= # GENERIC FINALIZATION @@ -250,44 +190,8 @@ ynh_store_file_checksum --file="$final_path/CONFIG_FILE" # SECURE FILES AND DIRECTORIES #================================================= -### For security reason, any app should set the permissions to root: before anything else. -### Then, if write authorization is needed, any access should be given only to directories -### that really need such authorization. - # Set permissions to app files -chown -R root: $final_path - -#================================================= -# SETUP LOGROTATE -#================================================= -ynh_print_info --message="Configuring log rotation..." - -### `ynh_use_logrotate` is used to configure a logrotate configuration for the logs of this app. -### Use this helper only if there is effectively a log file for this app. -### If you're not using this helper: -### - Remove the section "BACKUP LOGROTATE" in the backup script -### - Remove also the section "REMOVE LOGROTATE CONFIGURATION" in the remove script -### - As well as the section "RESTORE THE LOGROTATE CONFIGURATION" in the restore script -### - And the section "SETUP LOGROTATE" in the upgrade script - -# Use logrotate to manage application logfile(s) -ynh_use_logrotate - -#================================================= -# ADVERTISE SERVICE IN ADMIN PANEL -#================================================= - -### `yunohost service add` is a CLI yunohost command to add a service in the admin panel. -### You'll find the service in the 'services' section of YunoHost admin panel. -### This CLI command would be useless if the app does not have any services (systemd or sysvinit) -### If you're not using these lines: -### - You can remove these files in conf/. -### - Remove the section "REMOVE SERVICE FROM ADMIN PANEL" in the remove script -### - As well as the section "ADVERTISE SERVICE IN ADMIN PANEL" in the restore script - -yunohost service add $app --log "/var/log/$app/$app.log" -# if using yunohost version 3.2 or more in the 'manifest.json', a description can be added -#yunohost service add $app --description "$app daemon for XXX" --log "/var/log/$app/$app.log" +chown -R $app: $final_path #================================================= # SETUP SSOWAT diff --git a/scripts/remove b/scripts/remove index 3b84ac5..ab05642 100644 --- a/scripts/remove +++ b/scripts/remove @@ -7,6 +7,8 @@ #================================================= source _common.sh +source ynh_add_extra_apt_repos__3 +source ynh_install_php__3 source /usr/share/yunohost/helpers #================================================= @@ -24,25 +26,6 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # STANDARD REMOVE -#================================================= -# REMOVE SERVICE FROM ADMIN PANEL -#================================================= - -# Remove a service from the admin panel, added by `yunohost service add` -if yunohost service status $app >/dev/null 2>&1 -then - ynh_print_info --message="Removing $app service" - yunohost service remove $app -fi - -#================================================= -# STOP AND REMOVE SERVICE -#================================================= -ynh_print_info --message="Stopping and removing the systemd service" - -# Remove the dedicated systemd config -ynh_remove_systemd_config - #================================================= # REMOVE THE MYSQL DATABASE #================================================= @@ -57,7 +40,8 @@ ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name ynh_print_info --message="Removing dependencies" # Remove metapackage and its dependencies -ynh_remove_app_dependencies +#ynh_remove_app_dependencies +ynh_remove_php #================================================= # REMOVE APP MAIN DIR @@ -83,24 +67,6 @@ ynh_print_info --message="Removing php-fpm configuration" # Remove the dedicated php-fpm config ynh_remove_fpm_config -#================================================= -# REMOVE LOGROTATE CONFIGURATION -#================================================= -ynh_print_info --message="Removing logrotate configuration" - -# Remove the app-specific logrotate config -ynh_remove_logrotate - -#================================================= -# CLOSE A PORT -#================================================= - -if yunohost firewall list | grep -q "\- $port$" -then - ynh_print_info --message="Closing port $port" - ynh_exec_warn_less yunohost firewall disallow TCP $port -fi - #================================================= # SPECIFIC REMOVE #================================================= @@ -110,12 +76,6 @@ fi # Remove a cron file ynh_secure_remove --file="/etc/cron.d/$app" -# Remove a directory securely -ynh_secure_remove --file="/etc/$app/" - -# Remove the log files -ynh_secure_remove --file="/var/log/$app/" - #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/restore b/scripts/restore index 2dd4a68..3c4d9fd 100644 --- a/scripts/restore +++ b/scripts/restore @@ -8,16 +8,14 @@ #Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh +source ../settings/scripts/ynh_add_extra_apt_repos__3 +source ../settings/scripts/ynh_install_php__3 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 @@ -64,20 +62,20 @@ ynh_restore_file --origin_path="$final_path" ynh_print_info --message="Recreating the dedicated system user..." # 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 #================================================= # RESTORE THE PHP-FPM CONFIGURATION #================================================= -ynh_restore_file --origin_path="/etc/php/7.0/fpm/pool.d/$app.conf" +ynh_restore_file --origin_path="/etc/php/7.2/fpm/pool.d/$app.conf" #================================================= # SPECIFIC RESTORATION @@ -87,7 +85,8 @@ ynh_restore_file --origin_path="/etc/php/7.0/fpm/pool.d/$app.conf" ynh_print_info --message="Reinstalling dependencies..." # Define and install dependencies -ynh_install_app_dependencies $pkg_dependencies +#ynh_install_app_dependencies $pkg_dependencies +ynh_install_php --phpversion="7.2" --package="$extra_pkg_dependencies" #================================================= # RESTORE THE MYSQL DATABASE @@ -98,32 +97,12 @@ db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) ynh_mysql_setup_db --db_user=$db_name --db_name=$db_name --db_pwd=$db_pwd ynh_mysql_connect_as --user=$db_name --password=$db_pwd --database=$db_name < ./db.sql -#================================================= -# RESTORE SYSTEMD -#================================================= -ynh_print_info --message="Restoring the systemd configuration..." - -ynh_restore_file --origin_path="/etc/systemd/system/$app.service" -systemctl enable $app.service - -#================================================= -# ADVERTISE SERVICE IN ADMIN PANEL -#================================================= - -yunohost service add $app --log "/var/log/$app/$app.log" - #================================================= # RESTORE THE CRON FILE #================================================= ynh_restore_file --origin_path="/etc/cron.d/$app" -#================================================= -# RESTORE THE LOGROTATE CONFIGURATION -#================================================= - -ynh_restore_file --origin_path="/etc/logrotate.d/$app" - #================================================= # GENERIC FINALIZATION #================================================= @@ -131,7 +110,7 @@ ynh_restore_file --origin_path="/etc/logrotate.d/$app" #================================================= ynh_print_info --message="Reloading nginx web server and php-fpm..." -systemctl reload php7.0-fpm +systemctl reload php7.2-fpm systemctl reload nginx #================================================= diff --git a/scripts/ynh_add_extra_apt_repos__3 b/scripts/ynh_add_extra_apt_repos__3 new file mode 100644 index 0000000..3276f00 --- /dev/null +++ b/scripts/ynh_add_extra_apt_repos__3 @@ -0,0 +1,294 @@ +#!/bin/bash + +# Pin a repository. +# +# usage: ynh_pin_repo --package=packages --pin=pin_filter [--priority=priority_value] [--name=name] [--append] +# | arg: -p, --package - Packages concerned by the pin. Or all, *. +# | arg: -i, --pin - Filter for the pin. +# | arg: -p, --priority - Priority for the pin +# | arg: -n, --name - Name for the files for this repo, $app as default value. +# | arg: -a, --append - Do not overwrite existing files. +# +# See https://manpages.debian.org/stretch/apt/apt_preferences.5.en.html for information about pinning. +# +ynh_pin_repo () { + # Declare an array to define the options of this helper. + local legacy_args=pirna + declare -Ar args_array=( [p]=package= [i]=pin= [r]=priority= [n]=name= [a]=append ) + local package + local pin + local priority + local name + local append + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + package="${package:-*}" + priority=${priority:-50} + name="${name:-$app}" + append=${append:-0} + + if [ $append -eq 1 ] + then + append="tee -a" + else + append="tee" + fi + + mkdir -p "/etc/apt/preferences.d" + echo "Package: $package +Pin: $pin +Pin-Priority: $priority" \ + | $append "/etc/apt/preferences.d/$name" +} + +# Add a repository. +# +# usage: ynh_add_repo --uri=uri --suite=suite --component=component [--name=name] [--append] +# | arg: -u, --uri - Uri of the repository. +# | arg: -s, --suite - Suite of the repository. +# | arg: -c, --component - Component of the repository. +# | arg: -n, --name - Name for the files for this repo, $app as default value. +# | arg: -a, --append - Do not overwrite existing files. +# +# Example for a repo like deb http://forge.yunohost.org/debian/ stretch stable +# uri suite component +# ynh_add_repo --uri=http://forge.yunohost.org/debian/ --suite=stretch --component=stable +# +ynh_add_repo () { + # Declare an array to define the options of this helper. + local legacy_args=uscna + declare -Ar args_array=( [u]=uri= [s]=suite= [c]=component= [n]=name= [a]=append ) + local uri + local suite + local component + local name + local append + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + name="${name:-$app}" + append=${append:-0} + + if [ $append -eq 1 ] + then + append="tee -a" + else + append="tee" + fi + + mkdir -p "/etc/apt/sources.list.d" + # Add the new repo in sources.list.d + echo "deb $uri $suite $component" \ + | $append "/etc/apt/sources.list.d/$name.list" +} + +# Add an extra repository correctly, pin it and get the key. +# +# usage: ynh_install_extra_repo --repo="repo" [--key=key_url] [--priority=priority_value] [--name=name] [--append] +# | arg: -r, --repo - Complete url of the extra repository. +# | arg: -k, --key - url to get the public key. +# | arg: -p, --priority - Priority for the pin +# | arg: -n, --name - Name for the files for this repo, $app as default value. +# | arg: -a, --append - Do not overwrite existing files. +ynh_install_extra_repo () { + # Declare an array to define the options of this helper. + local legacy_args=rkpna + declare -Ar args_array=( [r]=repo= [k]=key= [p]=priority= [n]=name= [a]=append ) + local repo + local key + local priority + local name + local append + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + name="${name:-$app}" + append=${append:-0} + key=${key:-0} + priority=${priority:-} + + if [ $append -eq 1 ] + then + append="--append" + wget_append="tee -a" + else + append="" + wget_append="tee" + fi + + # Split the repository into uri, suite and components. + # Remove "deb " at the beginning of the repo. + repo="${repo#deb }" + + # Get the uri + local uri="$(echo "$repo" | awk '{ print $1 }')" + + # Get the suite + local suite="$(echo "$repo" | awk '{ print $2 }')" + + # Get the components + local component="${repo##$uri $suite }" + + # Add the repository into sources.list.d + ynh_add_repo --uri="$uri" --suite="$suite" --component="$component" --name="$name" $append + + # Pin the new repo with the default priority, so it won't be used for upgrades. + # Build $pin from the uri without http and any sub path + local pin="${uri#*://}" + pin="${pin%%/*}" + # Set a priority only if asked + if [ -n "$priority" ] + then + priority="--priority=$priority" + fi + ynh_pin_repo --package="*" --pin="origin \"$pin\"" $priority --name="$name" $append + + # Get the public key for the repo + if [ -n "$key" ] + then + mkdir -p "/etc/apt/trusted.gpg.d" + wget -q "$key" -O - | gpg --dearmor | $wget_append /etc/apt/trusted.gpg.d/$name.gpg > /dev/null + fi + + # Update the list of package with the new repo + ynh_package_update +} + +# Remove an extra repository and the assiociated configuration. +# +# usage: ynh_remove_extra_repo [--name=name] +# | arg: -n, --name - Name for the files for this repo, $app as default value. +ynh_remove_extra_repo () { + # Declare an array to define the options of this helper. + local legacy_args=n + declare -Ar args_array=( [n]=name= ) + local name + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + name="${name:-$app}" + + ynh_secure_remove "/etc/apt/sources.list.d/$name.list" + ynh_secure_remove "/etc/apt/preferences.d/$name" + ynh_secure_remove "/etc/apt/trusted.gpg.d/$name.gpg" + ynh_secure_remove "/etc/apt/trusted.gpg.d/$name.asc" + + # Update the list of package to exclude the old repo + ynh_package_update +} + +# Install packages from an extra repository properly. +# +# usage: ynh_install_extra_app_dependencies --repo="repo" --package="dep1 dep2" [--key=key_url] [--name=name] +# | arg: -r, --repo - Complete url of the extra repository. +# | arg: -p, --package - The packages to install from this extra repository +# | arg: -k, --key - url to get the public key. +# | arg: -n, --name - Name for the files for this repo, $app as default value. +ynh_install_extra_app_dependencies () { + # Declare an array to define the options of this helper. + local legacy_args=rpkn + declare -Ar args_array=( [r]=repo= [p]=package= [k]=key= [n]=name= ) + local repo + local package + local key + local name + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + name="${name:-$app}" + key=${key:-0} + + # Set a key only if asked + if [ -n "$key" ] + then + key="--key=$key" + fi + # Add an extra repository for those packages + ynh_install_extra_repo --repo="$repo" $key --priority=995 --name=$name + + # Install requested dependencies from this extra repository. + ynh_add_app_dependencies --package="$package" + + # Remove this extra repository after packages are installed + ynh_remove_extra_repo --name=$app +} + +#================================================= + +# patched version of ynh_install_app_dependencies to be used with ynh_add_app_dependencies + +# Define and install dependencies with a equivs control file +# This helper can/should only be called once per app +# +# usage: ynh_install_app_dependencies dep [dep [...]] +# | arg: dep - the package name to install in dependence +# You can give a choice between some package with this syntax : "dep1|dep2" +# Example : ynh_install_app_dependencies dep1 dep2 "dep3|dep4|dep5" +# This mean in the dependence tree : dep1 & dep2 & (dep3 | dep4 | dep5) +# +# Requires YunoHost version 2.6.4 or higher. +ynh_install_app_dependencies () { + local dependencies=$@ + dependencies="$(echo "$dependencies" | sed 's/\([^\<=\>]\)\ \([^(]\)/\1, \2/g')" + dependencies=${dependencies//|/ | } + local manifest_path="../manifest.json" + if [ ! -e "$manifest_path" ]; then + manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place + fi + + local version=$(grep '\"version\": ' "$manifest_path" | cut -d '"' -f 4) # Retrieve the version number in the manifest file. + if [ ${#version} -eq 0 ]; then + version="1.0" + fi + local dep_app=${app//_/-} # Replace all '_' by '-' + + # Handle specific versions + if [[ "$dependencies" =~ [\<=\>] ]] + then + # Replace version specifications by relationships syntax + # https://www.debian.org/doc/debian-policy/ch-relationships.html + # Sed clarification + # [^(\<=\>] ignore if it begins by ( or < = >. To not apply twice. + # [\<=\>] matches < = or > + # \+ matches one or more occurence of the previous characters, for >= or >>. + # [^,]\+ matches all characters except ',' + # Ex: package>=1.0 will be replaced by package (>= 1.0) + dependencies="$(echo "$dependencies" | sed 's/\([^(\<=\>]\)\([\<=\>]\+\)\([^,]\+\)/\1 (\2 \3)/g')" + fi + + cat > /tmp/${dep_app}-ynh-deps.control << EOF # Make a control file for equivs-build +Section: misc +Priority: optional +Package: ${dep_app}-ynh-deps +Version: ${version} +Depends: ${dependencies} +Architecture: all +Description: Fake package for $app (YunoHost app) dependencies + This meta-package is only responsible of installing its dependencies. +EOF + ynh_package_install_from_equivs /tmp/${dep_app}-ynh-deps.control \ + || ynh_die --message="Unable to install dependencies" # Install the fake package and its dependencies + rm /tmp/${dep_app}-ynh-deps.control + ynh_app_setting_set --app=$app --key=apt_dependencies --value="$dependencies" +} + +ynh_add_app_dependencies () { + # Declare an array to define the options of this helper. + local legacy_args=pr + declare -Ar args_array=( [p]=package= [r]=replace) + local package + local replace + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + replace=${replace:-0} + + local current_dependencies="" + if [ $replace -eq 0 ] + then + local dep_app=${app//_/-} # Replace all '_' by '-' + if ynh_package_is_installed --package="${dep_app}-ynh-deps" + then + current_dependencies="$(dpkg-query --show --showformat='${Depends}' ${dep_app}-ynh-deps) " + fi + + current_dependencies=${current_dependencies// | /|} + fi + + ynh_install_app_dependencies "${current_dependencies}${package}" +} diff --git a/scripts/ynh_composer__2 b/scripts/ynh_composer__2 new file mode 100644 index 0000000..0949586 --- /dev/null +++ b/scripts/ynh_composer__2 @@ -0,0 +1,46 @@ +#!/bin/bash + +# Execute a command with Composer +# +# usage: ynh_composer_exec --phpversion=phpversion [--workdir=$final_path] --commands="commands" +# | 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}" + + 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] +# | arg: -w, --workdir - The directory from where the command will be executed. Default $final_path. +ynh_install_composer () { + # Declare an array to define the options of this helper. + local legacy_args=vw + declare -Ar args_array=( [v]=phpversion= [w]=workdir= ) + local phpversion + local workdir + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + workdir="${workdir:-$final_path}" + + curl -sS https://getcomposer.org/installer \ + | COMPOSER_HOME="$workdir/.composer" \ + php${phpversion} -- --quiet --install-dir="$workdir" \ + || ynh_die "Unable to install Composer." + + # update dependencies to create composer.lock + ynh_composer_exec --phpversion="${phpversion}" --workdir="$workdir" --commands="install --no-dev" \ + || ynh_die "Unable to update core dependencies with Composer." +}