From c8c8f5392d95c810c2562e589ff4b6ffcfec5a74 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 10 Jun 2020 03:17:46 +0200 Subject: [PATCH] Get ride of sury --- manifest.json | 2 +- scripts/_common.sh | 18 ++- scripts/backup | 25 ++-- scripts/change_url | 12 +- scripts/install | 33 ++--- scripts/remove | 14 +- scripts/restore | 57 ++++---- scripts/upgrade | 95 ++++++------ scripts/ynh_add_extra_apt_repos | 249 -------------------------------- scripts/ynh_install_php | 78 ---------- 10 files changed, 133 insertions(+), 450 deletions(-) delete mode 100644 scripts/ynh_add_extra_apt_repos delete mode 100644 scripts/ynh_install_php diff --git a/manifest.json b/manifest.json index d6df645..1a00d66 100644 --- a/manifest.json +++ b/manifest.json @@ -14,7 +14,7 @@ "email": "plopoyop@gmail.com" }, "requirements": { - "yunohost": ">= 3.7" + "yunohost": ">= 3.8.1" }, "multi_instance": true, "services": [ diff --git a/scripts/_common.sh b/scripts/_common.sh index eaf6cdd..f868f35 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -5,6 +5,20 @@ #================================================= # dependencies used by the app -YNH_PHP_VERSION="7.3" -extra_pkg_dependencies="php$YNH_PHP_VERSION-intl php$YNH_PHP_VERSION-curl php$YNH_PHP_VERSION-mbstring" pkg_dependencies="ffmpeg" + +YNH_PHP_VERSION="7.3" + +extra_php_dependencies="php$YNH_PHP_VERSION-intl php$YNH_PHP_VERSION-curl php$YNH_PHP_VERSION-mbstring" + +#================================================= +# PERSONAL HELPERS +#================================================= + +#================================================= +# EXPERIMENTAL HELPERS +#================================================= + +#================================================= +# FUTURE OFFICIAL HELPERS +#================================================= diff --git a/scripts/backup b/scripts/backup index b2e084c..4b20468 100755 --- a/scripts/backup +++ b/scripts/backup @@ -20,39 +20,38 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -final_path=$(ynh_app_setting_get $app final_path) -domain=$(ynh_app_setting_get $app domain) -db_name=$(ynh_app_setting_get $app db_name) -fpm_config_dir=$(ynh_app_setting_get $app fpm_config_dir) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +domain=$(ynh_app_setting_get --app=$app --key=domain) +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= -# STANDARD BACKUP STEPS +# DECLARE DATA AND CONF FILES TO BACKUP +#================================================= +ynh_print_info --message="Declaring files to be backed up..." + #================================================= # BACKUP THE APP MAIN DIR #================================================= -ynh_script_progression --message="Backing up the main app directory..." --weight=30 -ynh_backup "$final_path" +ynh_backup --src_path="$final_path" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Backing up nginx web server configuration..." --weight=1 -ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # BACKUP THE PHP-FPM CONFIGURATION #================================================= -ynh_script_progression --message="Backing up php-fpm configuration..." --weight=1 -ynh_backup "$fpm_config_dir/pool.d/$app.conf" +ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)" --last \ No newline at end of file + +ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/change_url b/scripts/change_url index 65159a7..5ab0a27 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -27,7 +27,7 @@ app=$YNH_APP_INSTANCE_NAME ynh_script_progression --message="Loading installation settings..." # Needed for helper "ynh_add_nginx_config" -final_path=$(ynh_app_setting_get $app final_path) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # CHECK WHICH PARTS SHOULD BE CHANGED @@ -58,7 +58,7 @@ nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf if [ $change_path -eq 1 ] then # Make a backup of the original nginx config file if modified - ynh_backup_if_checksum_is_different "$nginx_conf_path" + ynh_backup_if_checksum_is_different --file="$nginx_conf_path" # Set global variables for nginx helper domain="$old_domain" path_url="$new_path" @@ -70,10 +70,10 @@ fi if [ $change_domain -eq 1 ] then # Delete file checksum for the old conf file location - ynh_delete_file_checksum "$nginx_conf_path" + ynh_delete_file_checksum --file="$nginx_conf_path" mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf # Store file checksum for the new config file location - ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf" + ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" fi #================================================= @@ -83,10 +83,10 @@ fi #================================================= ynh_script_progression --message="Reloading nginx web server..." --weight=1 -systemctl reload nginx +ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Change of URL completed for $app." --last +ynh_script_progression --message="Change of URL completed for $app" --last diff --git a/scripts/install b/scripts/install index fa936b5..3b1446a 100755 --- a/scripts/install +++ b/scripts/install @@ -7,8 +7,6 @@ #================================================= source _common.sh -source ynh_add_extra_apt_repos -source ynh_install_php source /usr/share/yunohost/helpers #================================================= @@ -16,7 +14,6 @@ source /usr/share/yunohost/helpers #================================================= 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 @@ -38,40 +35,37 @@ app=$YNH_APP_INSTANCE_NAME ynh_script_progression --message="Validating installation parameters..." final_path=/var/www/$app -test ! -e "$final_path" || ynh_die "This path already contains a folder" +test ! -e "$final_path" || ynh_die --message="This path already contains a folder" # Register (book) web path -ynh_webpath_register $app $domain $path_url +ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= ynh_script_progression --message="Storing installation settings..." -ynh_app_setting_set $app domain $domain -ynh_app_setting_set $app path $path_url -ynh_app_setting_set $app is_public $is_public +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=is_public --value=$is_public #================================================= # STANDARD MODIFICATIONS -#================================================= - #================================================= # INSTALL DEPENDENCIES #================================================= ynh_script_progression --message="Installing dependencies..." --weight=60 ynh_install_app_dependencies $pkg_dependencies -ynh_install_php --phpversion="$YNH_PHP_VERSION" --package="$extra_pkg_dependencies" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." --weight=6 -ynh_app_setting_set $app final_path $final_path +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 "$final_path" +ynh_setup_source --dest_dir="$final_path" #================================================= # NGINX CONFIGURATION @@ -87,7 +81,7 @@ ynh_add_nginx_config ynh_script_progression --message="Configuring system user..." --weight=2 # Create a system user -ynh_system_user_create $app +ynh_system_user_create --username=$app #================================================= # PHP-FPM CONFIGURATION @@ -95,16 +89,18 @@ ynh_system_user_create $app ynh_script_progression --message="Configuring php-fpm..." --weight=1 # Create a dedicated php-fpm config -ynh_add_fpm_config --phpversion="$YNH_PHP_VERSION" +ynh_add_fpm_config --usage=low --footprint=low --package="$extra_php_dependencies" #================================================= # SPECIFIC SETUP #================================================= + cp ../conf/config.yml "$final_path/config/" #================================================= # STORE THE CONFIG FILE CHECKSUM #================================================= +ynh_script_progression --message="Storing the config file checksum..." # Calculate and store the config file checksum into the app settings ynh_store_file_checksum "$final_path/config/config.yml" @@ -114,10 +110,11 @@ ynh_store_file_checksum "$final_path/config/config.yml" #================================================= # SECURE FILES AND DIRECTORIES #================================================= +ynh_script_progression --message="Securing files and directories..." # Set permissions to app files chown -R root: $final_path -chown -R alltube: $final_path/templates_c/ +chown -R $app: $final_path/templates_c/ #================================================= # SETUP SSOWAT @@ -135,10 +132,10 @@ fi #================================================= ynh_script_progression --message="Reloading nginx web server..." --weight=1 -systemctl reload nginx +ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of $app completed" --last \ No newline at end of file +ynh_script_progression --message="Installation of $app completed" --last diff --git a/scripts/remove b/scripts/remove index edd092f..de12dfd 100755 --- a/scripts/remove +++ b/scripts/remove @@ -16,16 +16,12 @@ ynh_script_progression --message="Loading settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -port=$(ynh_app_setting_get $app port) -db_name=$(ynh_app_setting_get $app db_name) -db_user=$db_name -final_path=$(ynh_app_setting_get $app final_path) +domain=$(ynh_app_setting_get --app=$app --key=domain) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # STANDARD REMOVE #================================================= -#=================================================#================================================= # REMOVE DEPENDENCIES #================================================= ynh_script_progression --message="Removing dependencies..." --weight=30 @@ -39,7 +35,7 @@ ynh_remove_app_dependencies ynh_script_progression --message="Removing app main directory..." --weight=30 # Remove the app directory securely -ynh_secure_remove "$final_path" +ynh_secure_remove --file="$final_path" #================================================= # REMOVE NGINX CONFIGURATION @@ -65,10 +61,10 @@ ynh_remove_fpm_config ynh_script_progression --message="Removing the dedicated system user..." --weight=5 # Delete a system user -ynh_system_user_delete $app +ynh_system_user_delete --username=$app #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" --last \ No newline at end of file +ynh_script_progression --message="Removal of $app completed" --last diff --git a/scripts/restore b/scripts/restore index ddb3992..c55c4d3 100755 --- a/scripts/restore +++ b/scripts/restore @@ -8,8 +8,6 @@ #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 -source ../settings/scripts/ynh_install_php source /usr/share/yunohost/helpers #================================================= @@ -22,88 +20,87 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading settings.." +ynh_script_progression --message="Loading settings..." app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -path_url=$(ynh_app_setting_get $app path) -final_path=$(ynh_app_setting_get $app final_path) -fpm_config_dir=$(ynh_app_setting_get $app fpm_config_dir) -fpm_service=$(ynh_app_setting_get $app fpm_service) +domain=$(ynh_app_setting_get --app=$app --key=domain) +path_url=$(ynh_app_setting_get --app=$app --key=path) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +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_script_progression --message="Validating restoration parameters..." --weight=1 -ynh_webpath_available $domain $path_url \ - || ynh_die "Path not available: ${domain}${path_url}" +ynh_webpath_available --domain=$domain --path_url=$path_url \ + || ynh_die --message="Path not available: ${domain}${path_url}" test ! -d $final_path \ - || ynh_die "There is already a directory: $final_path " + || ynh_die --message="There is already a directory: $final_path " #================================================= # STANDARD RESTORATION STEPS #================================================= # RESTORE THE NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Restoring the nginx configuration..." -ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring the app main directory.." --weight=1 +ynh_script_progression --message="Restoring the app main directory..." --weight=1 -ynh_restore_file "$final_path" +ynh_restore_file --origin_path="$final_path" #================================================= # RECREATE THE DEDICATED USER #================================================= -ynh_script_progression --message="Recreating the dedicated system user.." --weight=1 +ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 # Create the dedicated user (if not existing) -ynh_system_user_create $app +ynh_system_user_create --username=$app #================================================= # RESTORE USER RIGHTS #================================================= +ynh_script_progression --message="Restoring user rights..." # Restore permissions on app files chown -R root: $final_path -chown -R alltube: $final_path/templates_c/ +chown -R $app: $final_path/templates_c/ #================================================= # RESTORE THE PHP-FPM CONFIGURATION #================================================= +ynh_script_progression --message="Restoring PHP-FPM configuration..." -ynh_restore_file --origin_path="$fpm_config_dir/pool.d/$app.conf" +ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" + +# Recreate a dedicated php-fpm config +ynh_add_fpm_config --usage=low --footprint=low --package="$extra_php_dependencies" #================================================= # SPECIFIC RESTORATION #================================================= # REINSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Reinstalling dependencies.." --weight=60 +ynh_script_progression --message="Reinstalling dependencies..." --weight=60 # Define and install dependencies -if [ "$fpm_service" = "php7.0-fpm" ]; then - apt_dependencies=$(ynh_app_setting_get $app apt_dependencies) - ynh_install_app_dependencies $apt_dependencie -else - ynh_install_app_dependencies $pkg_dependencies - ynh_install_php --phpversion="$YNH_PHP_VERSION" --package="$extra_pkg_dependencies" -fi +ynh_install_app_dependencies $pkg_dependencies #================================================= # GENERIC FINALIZATION #================================================= # RELOAD NGINX AND PHP-FPM #================================================= -ynh_script_progression --message="Reloading nginx web server and php-fpm.." --weight=1 +ynh_script_progression --message="Reloading nginx web server and php-fpm..." --weight=1 -systemctl reload php7.3-fpm -systemctl reload nginx +ynh_systemd_action --service_name=php$phpversion-fpm --action=reload +ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT diff --git a/scripts/upgrade b/scripts/upgrade index abab253..a746d11 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -7,22 +7,46 @@ #================================================= source _common.sh -source ynh_add_extra_apt_repos -source ynh_install_php source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading settings.." --weight=1 +ynh_script_progression --message="Loading settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -path_url=$(ynh_app_setting_get $app path) -is_public=$(ynh_app_setting_get $app is_public) -final_path=$(ynh_app_setting_get $app final_path) -fpm_service=$(ynh_app_setting_get $app fpm_service) +domain=$(ynh_app_setting_get --app=$app --key=domain) +path_url=$(ynh_app_setting_get --app=$app --key=path) +is_public=$(ynh_app_setting_get --app=$app --key=is_public) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) + +#================================================= +# CHECK VERSION +#================================================= +ynh_script_progression --message="Checking version..." + +upgrade_type=$(ynh_check_app_version_changed) + +#================================================= +# ENSURE DOWNWARD COMPATIBILITY +#================================================= +ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 + +# Fix is_public as a boolean value +if [ "$is_public" = "Yes" ]; then + ynh_app_setting_set --app=$app --key=is_public --value=1 + is_public=1 +elif [ "$is_public" = "No" ]; then + ynh_app_setting_set --app=$app --key=is_public --value=0 + is_public=0 +fi + +# If final_path doesn't exist, create it +if [ -z "$final_path" ]; then + final_path=/var/www/$app + ynh_app_setting_set --app=$app --key=final_path --value=$final_path +fi #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP @@ -38,39 +62,19 @@ ynh_clean_setup () { # Exit if an error occurs during the execution of the script ynh_abort_if_errors -#================================================= -# ENSURE DOWNWARD COMPATIBILITY -#================================================= -ynh_script_progression --message="Ensuring downward compatibility.." --weight=1 - -if [ "$fpm_service" = "php7.0-fpm" ]; then - ynh_remove_fpm_config -fi - -# Fix is_public as a boolean value -if [ "$is_public" = "Yes" ]; then - ynh_app_setting_set $app is_public 1 - is_public=1 -elif [ "$is_public" = "No" ]; then - ynh_app_setting_set $app is_public 0 - is_public=0 -fi - -# If final_path doesn't exist, create it -if [ -z $final_path ]; then - final_path=/var/www/$app - ynh_app_setting_set $app final_path $final_path -fi - #================================================= # STANDARD UPGRADE STEPS #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Upgrading source files..." --weight=6 -# Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source "$final_path" +if [ "$upgrade_type" == "UPGRADE_APP" ] +then + ynh_script_progression --message="Upgrading source files..." --weight=6 + + # Download, check integrity, uncompress and patch the source from app.src + ynh_setup_source --dest_dir="$final_path" +fi #================================================= # NGINX CONFIGURATION @@ -85,9 +89,7 @@ ynh_add_nginx_config #================================================= ynh_script_progression --message="Upgrading dependencies..." --weight=60 - ynh_install_app_dependencies $pkg_dependencies -ynh_install_php --phpversion="$YNH_PHP_VERSION" --package="$extra_pkg_dependencies" #================================================= # CREATE DEDICATED USER @@ -95,7 +97,7 @@ ynh_install_php --phpversion="$YNH_PHP_VERSION" --package="$extra_pkg_dependenci ynh_script_progression --message="Making sure dedicated system user exists..." --weight=2 # Create a dedicated user (if not existing) -ynh_system_user_create $app +ynh_system_user_create --username=$app #================================================= # PHP-FPM CONFIGURATION @@ -103,10 +105,14 @@ ynh_system_user_create $app ynh_script_progression --message="Upgrading php-fpm configuration..." --weight=1 # Create a dedicated php-fpm config -ynh_add_fpm_config --phpversion="$YNH_PHP_VERSION" +ynh_add_fpm_config --usage=low --footprint=low --package="$extra_php_dependencies" + +#================================================= +# SPECIFIC UPGRADE +#================================================= +# MODIFY A CONFIG FILE +#================================================= -### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. -### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it. ynh_backup_if_checksum_is_different "$final_path/config/config.yml" # Recalculate and store the checksum of the file for the next upgrade. ynh_store_file_checksum "$final_path/config/config.yml" @@ -116,10 +122,11 @@ ynh_store_file_checksum "$final_path/config/config.yml" #================================================= # SECURE FILES AND DIRECTORIES #================================================= +ynh_script_progression --message="Securing files and directories..." # Set permissions on app files chown -R root: $final_path -chown -R alltube: $final_path/templates_c/ +chown -R $app: $final_path/templates_c/ #================================================= # SETUP SSOWAT @@ -143,10 +150,10 @@ fi #================================================= ynh_script_progression --message="Reloading nginx web server..." --weight=1 -systemctl reload nginx +ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --last \ No newline at end of file +ynh_script_progression --message="Upgrade of $app completed" --last diff --git a/scripts/ynh_add_extra_apt_repos b/scripts/ynh_add_extra_apt_repos deleted file mode 100644 index df092aa..0000000 --- a/scripts/ynh_add_extra_apt_repos +++ /dev/null @@ -1,249 +0,0 @@ -# Add dependencies to install with ynh_install_app_dependencies -# -# [internal] -# -# usage: ynh_add_app_dependencies --package=phpversion [--replace] -# | arg: -p, --package - Packages to add as dependencies for the app. -# | arg: -r, --replace - Replace dependencies instead of adding to existing ones. -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}" -} - -# 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 -} - -# Add an extra repository correctly, pin it and get the key. -# -# [internal] -# -# 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. -# -# [internal] -# -# 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 -} - -# Add a repository. -# -# [internal] -# -# 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" -} - -# Pin a repository. -# -# [internal] -# -# 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" -} \ No newline at end of file diff --git a/scripts/ynh_install_php b/scripts/ynh_install_php deleted file mode 100644 index 7ac4420..0000000 --- a/scripts/ynh_install_php +++ /dev/null @@ -1,78 +0,0 @@ -#!/bin/bash - -# Install another version of php. -# -# usage: ynh_install_php --phpversion=phpversion [--package=packages] -# | arg: -v, --phpversion - Version of php to install. Can be one of 7.1, 7.2 or 7.3 -# | arg: -p, --package - Additionnal php packages to install -ynh_install_php () { - # Declare an array to define the options of this helper. - local legacy_args=vp - declare -Ar args_array=( [v]=phpversion= [p]=package= ) - local phpversion - local package - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - package=${package:-} - - # Store php_version into the config of this app - ynh_app_setting_set $app php_version $phpversion - - if [ "$phpversion" == "7.0" ] - then - ynh_die "Do not use ynh_install_php to install php7.0" - fi - - # Store the ID of this app and the version of php requested for it - echo "$YNH_APP_INSTANCE_NAME:$phpversion" | tee --append "/etc/php/ynh_app_version" - - # Add an extra repository for those packages - ynh_install_extra_repo --repo="https://packages.sury.org/php/ $(lsb_release -sc) main" --key="https://packages.sury.org/php/apt.gpg" --priority=995 --name=extra_php_version - - # Install requested dependencies from this extra repository. - # Install php-fpm first, otherwise php will install apache as a dependency. - ynh_add_app_dependencies --package="php${phpversion}-fpm" - ynh_add_app_dependencies --package="php$phpversion php${phpversion}-common $package" - - # Set php7.0 back as the default version for php-cli. - update-alternatives --set php /usr/bin/php7.0 - - # Pin this extra repository after packages are installed to prevent sury of doing shit - ynh_pin_repo --package="*" --pin="origin \"packages.sury.org\"" --priority=200 --name=extra_php_version - ynh_pin_repo --package="php7.0*" --pin="origin \"packages.sury.org\"" --priority=600 --name=extra_php_version --append - - # Advertise service in admin panel - yunohost service add php${phpversion}-fpm --log "/var/log/php${phpversion}-fpm.log" -} - -ynh_remove_php () { - # Get the version of php used by this app - local phpversion=$(ynh_app_setting_get $app php_version) - - if [ "$phpversion" == "7.0" ] || [ -z "$phpversion" ] - then - if [ "$phpversion" == "7.0" ] - then - ynh_print_err "Do not use ynh_remove_php to install php7.0" - fi - return 0 - fi - - # Remove the line for this app - sed --in-place "/$YNH_APP_INSTANCE_NAME:$phpversion/d" "/etc/php/ynh_app_version" - - # If no other app uses this version of php, remove it. - if ! grep --quiet "$phpversion" "/etc/php/ynh_app_version" - then - # Purge php dependences for this version. - ynh_package_autopurge "php$phpversion php${phpversion}-fpm php${phpversion}-common" - # Remove the service from the admin panel - yunohost service remove php${phpversion}-fpm - fi - - # If no other app uses alternate php versions, remove the extra repo for php - if [ ! -s "/etc/php/ynh_app_version" ] - then - ynh_secure_remove /etc/php/ynh_app_version - fi -} \ No newline at end of file