1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/my_webapp_ynh.git synced 2024-09-03 19:46:26 +02:00

Normalization from example_ynh

This commit is contained in:
Maniack Crudelis 2019-05-07 13:10:14 +02:00
parent b371fdbe8a
commit cccc014552
10 changed files with 152 additions and 178 deletions

View file

@ -38,9 +38,9 @@ of your custom Web application inside.
#### Supported architectures #### Supported architectures
* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/my_webapp%20%28Official%29.svg)](https://ci-apps.yunohost.org/ci/apps/my_webapp/) * x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/my_webapp%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/my_webapp/)
* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/my_webapp%20%28Official%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/my_webapp/) * ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/my_webapp%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/my_webapp/)
* Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/ci/logs/my_webapp%20%28Official%29.svg)](https://ci-stretch.nohost.me/ci/apps/my_webapp/) * Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/ci/logs/my_webapp%20%28Apps%29.svg)](https://ci-stretch.nohost.me/ci/apps/my_webapp/)
## Limitations ## Limitations

View file

@ -19,17 +19,7 @@
port_already_use=0 port_already_use=0
change_url=1 change_url=1
;;; Levels ;;; Levels
Level 1=auto Level 5=auto
Level 2=auto
Level 3=auto
Level 4=na
# Level 5: https://github.com/YunoHost-Apps/my_webapp_ynh/issues/15
Level 5=1
Level 6=auto
Level 7=auto
Level 8=0
Level 9=0
Level 10=0
;;; Options ;;; Options
Email= Email=
Notification=none Notification=none

View file

@ -14,7 +14,7 @@
"email": "apps@yunohost.org" "email": "apps@yunohost.org"
}, },
"requirements": { "requirements": {
"yunohost": ">= 3.2.0" "yunohost": ">= 3.5.0"
}, },
"multi_instance": true, "multi_instance": true,
"services": [ "services": [

View file

@ -1,13 +1 @@
#!/bin/bash #!/bin/bash
# ============= FUTURE YUNOHOST HELPER =============
# Delete a file checksum from the app settings
#
# $app should be defined when calling this helper
#
# usage: ynh_remove_file_checksum file
# | arg: file - The file for which the checksum will be deleted
ynh_delete_file_checksum () {
local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_'
ynh_app_setting_delete $app $checksum_setting_name
}

View file

@ -6,6 +6,7 @@
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
@ -18,49 +19,49 @@ ynh_abort_if_errors
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_print_info "Loading installation settings..." ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get $app final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
db_name=$(ynh_app_setting_get $app db_name) db_name=$(ynh_app_setting_get --app=$app --key=db_name)
with_mysql=$(ynh_app_setting_get $app with_mysql) with_mysql=$(ynh_app_setting_get --app=$app --key=with_mysql)
#================================================= #=================================================
# STANDARD BACKUP STEPS # STANDARD BACKUP STEPS
#================================================= #=================================================
# BACKUP THE APP MAIN DIR # BACKUP THE APP MAIN DIR
#================================================= #=================================================
ynh_print_info "Backing up the main app directory..." ynh_script_progression --message="Backing up the main app directory..."
ynh_backup "$final_path" ynh_backup --src_path="$final_path"
#================================================= #=================================================
# BACKUP THE NGINX CONFIGURATION # BACKUP THE NGINX CONFIGURATION
#================================================= #=================================================
ynh_print_info "Backing up nginx web server configuration..." ynh_script_progression --message="Backing up nginx web server configuration..."
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 # BACKUP THE PHP-FPM CONFIGURATION
#================================================= #=================================================
ynh_print_info "Backing up php-fpm configuration..." ynh_script_progression --message="Backing up php-fpm configuration..."
ynh_backup "/etc/php/7.0/fpm/pool.d/$app.conf" ynh_backup --src_path="/etc/php/7.0/fpm/pool.d/$app.conf"
#================================================= #=================================================
# BACKUP THE MYSQL DATABASE # BACKUP THE MYSQL DATABASE
#================================================= #=================================================
if [ $with_mysql -eq 1 ]; then if [ $with_mysql -eq 1 ]; then
ynh_print_info "Backing up the MySQL database..." ynh_script_progression --message="Backing up the MySQL database..."
ynh_mysql_dump_db "$db_name" > db.sql ynh_mysql_dump_db --database="$db_name" > db.sql
fi fi
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --last

View file

@ -24,18 +24,10 @@ app=$YNH_APP_INSTANCE_NAME
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..."
# Needed for helper "ynh_add_nginx_config" # 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 THE SYNTAX OF THE PATHS
#=================================================
test -n "$old_path" || old_path="/"
test -n "$new_path" || new_path="/"
new_path=$(ynh_normalize_url_path $new_path)
old_path=$(ynh_normalize_url_path $old_path)
#================================================= #=================================================
# CHECK WHICH PARTS SHOULD BE CHANGED # CHECK WHICH PARTS SHOULD BE CHANGED
@ -58,6 +50,7 @@ fi
#================================================= #=================================================
# MODIFY URL IN NGINX CONF # MODIFY URL IN NGINX CONF
#================================================= #=================================================
ynh_script_progression --message="Updating nginx web server configuration..." --weight=2
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
@ -65,7 +58,7 @@ nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
if [ $change_path -eq 1 ] if [ $change_path -eq 1 ]
then then
# Make a backup of the original nginx config file if modified # 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 # Set global variables for nginx helper
domain="$old_domain" domain="$old_domain"
path_url="$new_path" path_url="$new_path"
@ -77,10 +70,10 @@ fi
if [ $change_domain -eq 1 ] if [ $change_domain -eq 1 ]
then then
# Delete file checksum for the old conf file location # 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 mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
# Store file checksum for the new config file location # 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 fi
#================================================= #=================================================
@ -88,5 +81,12 @@ fi
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_script_progression --message="Reloading nginx web server..."
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

View file

@ -33,34 +33,33 @@ app_nb=$YNH_APP_INSTANCE_NUMBER
#================================================= #=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#================================================= #=================================================
ynh_print_info "Validating installation parameters..." ynh_script_progression --message="Validating installation parameters..." --weight=2
final_path=/var/www/$app 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"
# Check password strength # Check password strength
[[ ${#password} -gt 5 ]] || ynh_die \ if [ ${#password} -le 5 ]
"The password is too weak, it must be longer than 5 characters" then
ynh_die --message="The password is too weak, it must be longer than 5 characters"
# Normalize the url path syntax fi
path_url=$(ynh_normalize_url_path $path_url)
# Register (book) web path # 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 # STORE SETTINGS FROM MANIFEST
#================================================= #=================================================
ynh_print_info "Storing installation settings..." ynh_script_progression --message="Storing installation settings..."
user=webapp${app_nb} user=webapp${app_nb}
ynh_app_setting_set $app domain $domain ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set $app path $path_url ynh_app_setting_set --app=$app --key=path --value=$path_url
ynh_app_setting_set $app is_public $is_public ynh_app_setting_set --app=$app --key=is_public --value=$is_public
ynh_app_setting_set $app with_mysql $with_mysql ynh_app_setting_set --app=$app --key=with_mysql --value=$with_mysql
ynh_app_setting_set $app password "$password" ynh_app_setting_set --app=$app --key=password --value="$password"
ynh_app_setting_set $app user $user ynh_app_setting_set --app=$app --key=user --value=$user
ynh_app_setting_set $app final_path $final_path ynh_app_setting_set --app=$app --key=final_path --value=$final_path
#================================================= #=================================================
# STANDARD MODIFICATIONS # STANDARD MODIFICATIONS
@ -69,16 +68,17 @@ ynh_app_setting_set $app final_path $final_path
#================================================= #=================================================
if [ $with_mysql -eq 1 ]; then if [ $with_mysql -eq 1 ]; then
ynh_print_info "Creating a MySQL database..." ynh_script_progression --message="Creating a MySQL database..." --weight=2
db_name=$(ynh_sanitize_dbid $app)
ynh_app_setting_set $app db_name $db_name db_name=$(ynh_sanitize_dbid --db_name=$app)
ynh_mysql_setup_db $db_name $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
fi fi
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
ynh_print_info "Configuring nginx web server..." ynh_script_progression --message="Configuring nginx web server..." --weight=2
# Create a dedicated nginx config # Create a dedicated nginx config
ynh_add_nginx_config ynh_add_nginx_config
@ -86,10 +86,10 @@ ynh_add_nginx_config
#================================================= #=================================================
# CREATE DEDICATED USER # CREATE DEDICATED USER
#================================================= #=================================================
ynh_print_info "Configuring system user..." ynh_script_progression --message="Configuring system user..."
# Create a standard user (not a system user for sftp) # Create a standard user (not a system user for sftp)
ynh_system_user_exists "$user" || \ ynh_system_user_exists --username=$user || \
useradd -d "$final_path" -M --user-group "$user" useradd -d "$final_path" -M --user-group "$user"
# Add the password to this user # Add the password to this user
chpasswd <<< "${user}:${password}" chpasswd <<< "${user}:${password}"
@ -99,7 +99,7 @@ chpasswd <<< "${user}:${password}"
#================================================= #=================================================
# CONFIGURE SSH # CONFIGURE SSH
#================================================= #=================================================
ynh_print_info "Configuring ssh..." ynh_script_progression --message="Configuring ssh..."
# Harden SSH connection for the user # Harden SSH connection for the user
echo "##-> ${app} echo "##-> ${app}
@ -112,14 +112,14 @@ Match User ${user}
X11Forwarding no X11Forwarding no
##<- ${app}" | tee -a /etc/ssh/sshd_config >/dev/null ##<- ${app}" | tee -a /etc/ssh/sshd_config >/dev/null
systemctl reload ssh ynh_systemd_action --service_name=ssh --action=reload
#================================================= #=================================================
# MODIFY A CONFIG FILE # MODIFY A CONFIG FILE
#================================================= #=================================================
ynh_replace_string "__DOMAIN__" "$domain" ../sources/www/index.html ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file=../sources/www/index.html
ynh_replace_string "__USER__" "$user" ../sources/www/index.html ynh_replace_string --match_string="__USER__" --replace_string="$user" --target_file=../sources/www/index.html
if [ $with_mysql -eq 1 ]; then if [ $with_mysql -eq 1 ]; then
# Store the database access # Store the database access
@ -133,10 +133,10 @@ cp -r ../sources "$final_path"
#================================================= #=================================================
# PHP-FPM CONFIGURATION # PHP-FPM CONFIGURATION
#================================================= #=================================================
ynh_print_info "Configuring php-fpm..." ynh_script_progression --message="Configuring php-fpm..." --weight=2
# Create a dedicated php-fpm config # Create a dedicated php-fpm config
ynh_replace_string "__USER__" "$user" "../conf/php-fpm.conf" ynh_replace_string --match_string="__USER__" --replace_string="$user" --target_file="../conf/php-fpm.conf"
ynh_add_fpm_config ynh_add_fpm_config
#================================================= #=================================================
@ -153,23 +153,23 @@ chown root: "$final_path"
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT
#================================================= #=================================================
ynh_print_info "Configuring SSOwat..." ynh_script_progression --message="Configuring SSOwat..."
# Make app public if necessary # Make app public if necessary
if [ $is_public -eq 1 ] if [ $is_public -eq 1 ]
then then
ynh_app_setting_set $app skipped_uris "/" ynh_app_setting_set --app=$app --key=skipped_uris --value="/"
fi fi
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_print_info "Reloading nginx web server..." ynh_script_progression --message="Reloading nginx web server..."
systemctl reload nginx ynh_systemd_action --service_name=nginx --action=reload
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_print_info "Installation of $app completed" ynh_script_progression --message="Installation of $app completed" --last

View file

@ -12,17 +12,17 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_print_info "Loading installation settings..." ynh_script_progression --message="Loading installation settings..." --weight=2
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
with_mysql=$(ynh_app_setting_get $app with_mysql) with_mysql=$(ynh_app_setting_get --app=$app --key=with_mysql)
user=$(ynh_app_setting_get $app user) user=$(ynh_app_setting_get --app=$app --key=user)
db_name=$(ynh_app_setting_get $app db_name) db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name db_user=$db_name
final_path=$(ynh_app_setting_get $app final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#================================================= #=================================================
# STANDARD REMOVE # STANDARD REMOVE
@ -31,24 +31,24 @@ final_path=$(ynh_app_setting_get $app final_path)
#================================================= #=================================================
if [ $with_mysql -eq 1 ]; then if [ $with_mysql -eq 1 ]; then
ynh_print_info "Removing the MySQL database" ynh_script_progression --message="Removing the MySQL database..." --weight=2
# Remove a database if it exists, along with the associated user # Remove a database if it exists, along with the associated user
ynh_mysql_remove_db $db_user $db_name ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name
fi fi
#================================================= #=================================================
# REMOVE APP MAIN DIR # REMOVE APP MAIN DIR
#================================================= #=================================================
ynh_print_info "Removing app main directory" ynh_script_progression --message="Removing app main directory..."
# Remove the app directory securely # Remove the app directory securely
ynh_secure_remove "$final_path" ynh_secure_remove --file="$final_path"
#================================================= #=================================================
# REMOVE NGINX CONFIGURATION # REMOVE NGINX CONFIGURATION
#================================================= #=================================================
ynh_print_info "Removing nginx web server configuration" ynh_script_progression --message="Removing nginx web server configuration..." --weight=2
# Remove the dedicated nginx config # Remove the dedicated nginx config
ynh_remove_nginx_config ynh_remove_nginx_config
@ -56,7 +56,7 @@ ynh_remove_nginx_config
#================================================= #=================================================
# REMOVE PHP-FPM CONFIGURATION # REMOVE PHP-FPM CONFIGURATION
#================================================= #=================================================
ynh_print_info "Removing php-fpm configuration" ynh_script_progression --message="Removing php-fpm configuration..."
# Remove the dedicated php-fpm config # Remove the dedicated php-fpm config
ynh_remove_fpm_config ynh_remove_fpm_config
@ -66,23 +66,23 @@ ynh_remove_fpm_config
#================================================= #=================================================
# REMOVE THE CUSTOM SSH CONFIG # REMOVE THE CUSTOM SSH CONFIG
#================================================= #=================================================
ynh_print_info "Removing the custom ssh config" ynh_script_progression --message="Removing the custom ssh config"
sed -i "/##-> ${app}/,/##<- ${app}/d" /etc/ssh/sshd_config sed -i "/##-> ${app}/,/##<- ${app}/d" /etc/ssh/sshd_config
systemctl reload ssh ynh_systemd_action --service_name=ssh --action=reload
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
#================================================= #=================================================
# REMOVE DEDICATED USER # REMOVE DEDICATED USER
#================================================= #=================================================
ynh_print_info "Removing the dedicated system user" ynh_script_progression --message="Removing the dedicated system user..."
# Delete an user # Delete a system user
ynh_system_user_delete $user ynh_system_user_delete --username=$app
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_print_info "Removal of $app completed" ynh_script_progression --message="Removal of $app completed" --last

View file

@ -6,6 +6,7 @@
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
@ -18,27 +19,27 @@ ynh_abort_if_errors
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_print_info "Loading settings..." ynh_script_progression --message="Loading settings..." --weight=2
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get $app path) path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get $app final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get $app db_name) db_name=$(ynh_app_setting_get --app=$app --key=db_name)
with_mysql=$(ynh_app_setting_get $app with_mysql) with_mysql=$(ynh_app_setting_get --app=$app --key=with_mysql)
password=$(ynh_app_setting_get $app password) password=$(ynh_app_setting_get --app=$app --key=password)
user=$(ynh_app_setting_get $app user) user=$(ynh_app_setting_get --app=$app --key=user)
#================================================= #=================================================
# CHECK IF THE APP CAN BE RESTORED # CHECK IF THE APP CAN BE RESTORED
#================================================= #=================================================
ynh_print_info "Validating restoration parameters..." ynh_script_progression --message="Validating restoration parameters..." --weight=2
ynh_webpath_available $domain $path_url \ ynh_webpath_available --domain=$domain --path_url=$path_url \
|| ynh_die "Path not available: ${domain}${path_url}" || ynh_die --message="Path not available: ${domain}${path_url}"
test ! -d $final_path \ 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 # STANDARD RESTORATION STEPS
@ -46,33 +47,34 @@ test ! -d $final_path \
# RESTORE THE NGINX CONFIGURATION # RESTORE 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 # RESTORE THE APP MAIN DIR
#================================================= #=================================================
ynh_print_info "Restoring the app main directory..." ynh_script_progression --message="Restoring the app main directory..."
ynh_restore_file "$final_path" ynh_restore_file --origin_path="$final_path"
#================================================= #=================================================
# RESTORE THE MYSQL DATABASE # RESTORE THE MYSQL DATABASE
#================================================= #=================================================
if [ $with_mysql -eq 1 ]; then if [ $with_mysql -eq 1 ]; then
ynh_print_info "Restoring the mysql database..." ynh_script_progression --message="Restoring the MySQL database..."
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
ynh_mysql_setup_db $db_name $db_name $db_pwd db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql 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
fi fi
#================================================= #=================================================
# RECREATE THE DEDICATED USER # RECREATE THE DEDICATED USER
#================================================= #=================================================
ynh_print_info "Recreating the dedicated system user..." ynh_script_progression --message="Recreating the dedicated system user..." --weight=2
# Create a standard user (not a system user for sftp) # Create a standard user (not a system user for sftp)
ynh_system_user_exists "$user" || \ ynh_system_user_exists --username=$user || \
useradd -d "$final_path" -M --user-group "$user" useradd -d "$final_path" -M --user-group "$user"
# Add the password to this user # Add the password to this user
chpasswd <<< "${user}:${password}" chpasswd <<< "${user}:${password}"
@ -91,14 +93,14 @@ chown root: "$final_path"
# RESTORE THE PHP-FPM CONFIGURATION # RESTORE THE PHP-FPM CONFIGURATION
#================================================= #=================================================
ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf" ynh_restore_file --origin_path="/etc/php/7.0/fpm/pool.d/$app.conf"
#================================================= #=================================================
# SPECIFIC RESTORATION # SPECIFIC RESTORATION
#================================================= #=================================================
# CONFIGURE SSH # CONFIGURE SSH
#================================================= #=================================================
ynh_print_info "Configuring ssh..." ynh_script_progression --message="Configuring ssh..."
# Harden SSH connection for the user # Harden SSH connection for the user
echo "##-> ${app} echo "##-> ${app}
@ -111,20 +113,20 @@ Match User ${user}
X11Forwarding no X11Forwarding no
##<- ${app}" | tee -a /etc/ssh/sshd_config >/dev/null ##<- ${app}" | tee -a /etc/ssh/sshd_config >/dev/null
systemctl reload ssh ynh_systemd_action --service_name=ssh --action=reload
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
#================================================= #=================================================
# RELOAD NGINX AND PHP-FPM # RELOAD NGINX AND PHP-FPM
#================================================= #=================================================
ynh_print_info "Reloading nginx web server and php-fpm..." ynh_script_progression --message="Reloading nginx web server and php-fpm..."
systemctl reload php7.0-fpm ynh_systemd_action --service_name=php7.0-fpm --action=reload
systemctl reload nginx ynh_systemd_action --service_name=nginx --action=reload
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_print_info "Restoration completed for $app" ynh_script_progression --message="Restoration completed for $app" --last

View file

@ -12,58 +12,49 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_print_info "Loading installation settings..." ynh_script_progression --message="Loading installation settings..." --weight=2
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get $app path) path_url=$(ynh_app_setting_get --app=$app --key=path)
is_public=$(ynh_app_setting_get $app is_public) is_public=$(ynh_app_setting_get --app=$app --key=is_public)
final_path=$(ynh_app_setting_get $app final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get $app db_name) db_name=$(ynh_app_setting_get --app=$app --key=db_name)
with_mysql=$(ynh_app_setting_get $app with_mysql) with_mysql=$(ynh_app_setting_get --app=$app --key=with_mysql)
password=$(ynh_app_setting_get $app password) password=$(ynh_app_setting_get --app=$app --key=password)
user=$(ynh_app_setting_get $app user) user=$(ynh_app_setting_get --app=$app --key=user)
#================================================= #=================================================
# ENSURE DOWNWARD COMPATIBILITY # ENSURE DOWNWARD COMPATIBILITY
#================================================= #=================================================
ynh_print_info "Ensuring downward compatibility..." ynh_script_progression --message="Ensuring downward compatibility..."
# Fix is_public as a boolean value # Fix is_public as a boolean value
if [ "$is_public" = "Yes" ]; then if [ "$is_public" = "Yes" ]; then
ynh_app_setting_set $app is_public 1 ynh_app_setting_set --app=$app --key=is_public --value=1
is_public=1 is_public=1
elif [ "$is_public" = "No" ]; then elif [ "$is_public" = "No" ]; then
ynh_app_setting_set $app is_public 0 ynh_app_setting_set --app=$app --key=is_public --value=0
is_public=0
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 is_public=0
fi fi
# If db_name doesn't exist, create it # If db_name doesn't exist, create it
if [ -z $db_name ]; then if [ -z "$db_name" ]; then
db_name=$(ynh_sanitize_dbid $app) db_name=$(ynh_sanitize_dbid --db_name=$app)
ynh_app_setting_set $app db_name $db_name ynh_app_setting_set --app=$app --key=db_name --value=$db_name
fi fi
# If final_path doesn't exist, create it # If final_path doesn't exist, create it
if [ -z $final_path ]; then if [ -z "$final_path" ]; then
final_path=/var/www/$app final_path=/var/www/$app
ynh_app_setting_set $app final_path $final_path ynh_app_setting_set --app=$app --key=final_path --value=$final_path
fi fi
#================================================= #=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#================================================= #=================================================
ynh_print_info "Backing up the app before upgrading (may take a while)..." ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=3
# Backup the current version of the app # Backup the current version of the app
ynh_backup_before_upgrade ynh_backup_before_upgrade
@ -79,7 +70,7 @@ ynh_abort_if_errors
#================================================= #=================================================
# Normalize the URL path syntax # Normalize the URL path syntax
path_url=$(ynh_normalize_url_path $path_url) path_url=$(ynh_normalize_url_path --path_url=$path_url)
#================================================= #=================================================
# STANDARD UPGRADE STEPS # STANDARD UPGRADE STEPS
@ -87,11 +78,12 @@ path_url=$(ynh_normalize_url_path $path_url)
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
modified_config=$(ynh_backup_if_checksum_is_different "/etc/nginx/conf.d/$domain.d/$app.conf") modified_config=$(ynh_backup_if_checksum_is_different --file="/etc/nginx/conf.d/$domain.d/$app.conf")
# Replace nginx config only if it wasn't modified. # Replace nginx config only if it wasn't modified.
if [ -z "$modified_config" ] if [ -z "$modified_config" ]
then then
ynh_print_info "Upgrading nginx web server configuration..." ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=2
# Create a dedicated nginx config # Create a dedicated nginx config
ynh_add_nginx_config ynh_add_nginx_config
fi fi
@ -99,10 +91,10 @@ fi
#================================================= #=================================================
# CREATE DEDICATED USER # CREATE DEDICATED USER
#================================================= #=================================================
ynh_print_info "Making sure dedicated system user exists..." ynh_script_progression --message="Making sure dedicated system user exists..." --weight=2
# Create a standard user (not a system user for sftp) # Create a standard user (not a system user for sftp)
ynh_system_user_exists "$user" || \ ynh_system_user_exists --username=$user || \
useradd -d "$final_path" -M --user-group "$user" useradd -d "$final_path" -M --user-group "$user"
# Add the password to this user # Add the password to this user
chpasswd <<< "${user}:${password}" chpasswd <<< "${user}:${password}"
@ -115,13 +107,14 @@ usermod -g "$user" "$user"
# PHP-FPM CONFIGURATION # PHP-FPM CONFIGURATION
#================================================= #=================================================
modified_config=$(ynh_backup_if_checksum_is_different "/etc/php5/fpm/pool.d/$app.conf") modified_config=$(ynh_backup_if_checksum_is_different --file="/etc/php5/fpm/pool.d/$app.conf")
# Replace nginx config only if it wasn't modified. # Replace nginx config only if it wasn't modified.
if [ -z "$modified_config" ] if [ -z "$modified_config" ]
then then
ynh_print_info "Upgrading php-fpm configuration..." ynh_script_progression --message="Upgrading php-fpm configuration..." --weight=2
# Create a dedicated php-fpm config # Create a dedicated php-fpm config
ynh_replace_string "__USER__" "$user" "../conf/php-fpm.conf" ynh_replace_string --match_string="__USER__" --replace_string="$user" --target_file="../conf/php-fpm.conf"
ynh_add_fpm_config ynh_add_fpm_config
fi fi
@ -130,7 +123,7 @@ fi
#================================================= #=================================================
# CONFIGURE SSH # CONFIGURE SSH
#================================================= #=================================================
ynh_print_info "Configuring ssh..." ynh_script_progression --message="Configuring ssh..." --time --weight=1
# Remove the previous config for upgrading it # Remove the previous config for upgrading it
sed -i "/##-> ${app}/,/##<- ${app}/d" /etc/ssh/sshd_config sed -i "/##-> ${app}/,/##<- ${app}/d" /etc/ssh/sshd_config
@ -145,7 +138,7 @@ Match User ${user}
X11Forwarding no X11Forwarding no
##<- ${app}" | tee -a /etc/ssh/sshd_config >/dev/null ##<- ${app}" | tee -a /etc/ssh/sshd_config >/dev/null
systemctl reload ssh ynh_systemd_action --service_name=ssh --action=reload
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
@ -160,23 +153,23 @@ chown root: "$final_path"
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT
#================================================= #=================================================
ynh_print_info "Upgrading SSOwat configuration..." ynh_script_progression --message="Upgrading SSOwat configuration..."
# Make app public if necessary # Make app public if necessary
if [ $is_public -eq 1 ] if [ $is_public -eq 1 ]
then then
ynh_app_setting_set $app skipped_uris "/" ynh_app_setting_set --app=$app --key=skipped_uris --value="/"
fi fi
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_print_info "Reloading nginx web server..." ynh_script_progression --message="Reloading nginx web server..."
systemctl reload nginx ynh_systemd_action --service_name=nginx --action=reload
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_print_info "Upgrade of $app completed" ynh_script_progression --message="Upgrade of $app completed" --last