mirror of
https://github.com/YunoHost-Apps/mygpo_ynh.git
synced 2024-09-03 19:55:52 +02:00
[enh] Make use of YunoHost helpers and harden set options
This commit is contained in:
parent
94f4472ab2
commit
4fa6a82d8d
5 changed files with 123 additions and 86 deletions
|
@ -1,26 +1,31 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
|
# Exit on command errors and treat unset variables as an error
|
||||||
set -e
|
set -eu
|
||||||
|
|
||||||
|
# See comments in install script
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
# The first argument is the backup directory location for the app
|
# Source YunoHost helpers
|
||||||
# from where the script is executed and which will be compressed afterward
|
. /usr/share/yunohost/helpers
|
||||||
backup_dir=$YNH_APP_BACKUP_DIR
|
|
||||||
|
|
||||||
# Backup sources & data
|
# Backup sources & data
|
||||||
sudo cp -a "/var/www/${app}" ./sources
|
# Note: the last argument is where to save this path, see the restore script.
|
||||||
|
ynh_backup "/var/www/${app}" "sources"
|
||||||
|
|
||||||
# Backup mysql database if needed
|
# If a MySQL database is used:
|
||||||
# db_pwd=$(sudo yunohost app setting $app mysqlpwd)
|
#
|
||||||
# sudo mysqldump -u $app -p$db_pwd $app > ./dump.sql
|
# # Dump the database
|
||||||
|
# dbname=$app
|
||||||
|
# dbuser=$app
|
||||||
|
# dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
||||||
|
# mysqldump -u "$dbuser" -p"$dbpass" --no-create-db "$dbname" > ./dump.sql
|
||||||
|
|
||||||
# Copy NGINX configuration
|
# Copy NGINX configuration
|
||||||
domain=$(sudo yunohost app setting "$app" domain)
|
domain=$(ynh_app_setting_get "$app" domain)
|
||||||
sudo cp -a "/etc/nginx/conf.d/${domain}.d/${app}.conf" ./nginx.conf
|
ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf"
|
||||||
|
|
||||||
# If a dedicated php-fpm process is used :
|
# If a dedicated php-fpm process is used:
|
||||||
# Copy dedicated php-fpm process to backup folder
|
|
||||||
#
|
#
|
||||||
#sudo cp -a "/etc/php5/fpm/pool.d/${app}.conf" ./php-fpm.conf
|
# # Copy PHP-FPM pool configuration
|
||||||
|
# ynh_backup "/etc/php5/fpm/pool.d/${app}.conf" "php-fpm.conf"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
|
# Exit on command errors and treat unset variables as an error
|
||||||
set -e
|
set -eu
|
||||||
|
|
||||||
# This is a multi-instance app, meaning it can be installed several times independently
|
# This is 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 id of the app as stated in the manifest is available as $YNH_APP_ID
|
||||||
|
@ -22,14 +22,17 @@ admin=$YNH_APP_ARG_ADMIN
|
||||||
is_public=$YNH_APP_ARG_IS_PUBLIC
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
||||||
language=$YNH_APP_ARG_LANGUAGE
|
language=$YNH_APP_ARG_LANGUAGE
|
||||||
|
|
||||||
|
# Source YunoHost helpers
|
||||||
|
. /usr/share/yunohost/helpers
|
||||||
|
|
||||||
# Save app settings
|
# Save app settings
|
||||||
sudo yunohost app setting $app admin -v "$admin"
|
ynh_app_setting_set "$app" admin "$admin"
|
||||||
sudo yunohost app setting $app is_public -v "$is_public"
|
ynh_app_setting_set "$app" is_public "$is_public"
|
||||||
sudo yunohost app setting $app language -v "$language"
|
ynh_app_setting_set "$app" language "$language"
|
||||||
|
|
||||||
# Check domain/path availability
|
# Check domain/path availability
|
||||||
sudo yunohost app checkurl $domain$path -a $app \
|
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
||||||
|| (echo "Path not available: $domain$path" && exit 1)
|
|| ynh_die "Path not available: ${domain}${path}"
|
||||||
|
|
||||||
# Copy source files
|
# Copy source files
|
||||||
final_path=/var/www/$app
|
final_path=/var/www/$app
|
||||||
|
@ -41,10 +44,18 @@ sudo cp -a ../sources/. $final_path
|
||||||
sudo chown -R root:root $final_path
|
sudo chown -R root:root $final_path
|
||||||
|
|
||||||
# If your app use a MySQL database you can use these lines to bootstrap
|
# If your app use a MySQL database you can use these lines to bootstrap
|
||||||
# a database, an associated user and save the password in app settings
|
# a database, an associated user and save the password in app settings.
|
||||||
# db_pwd=$(openssl rand -hex 15)
|
#
|
||||||
# sudo yunohost app initdb $app -p $db_pwd
|
# # Generate MySQL password and create database
|
||||||
# sudo yunohost app setting $app mysqlpwd -v $db_pwd
|
# dbuser=$app
|
||||||
|
# dbname=$app
|
||||||
|
# dbpass=$(ynh_string_random 12)
|
||||||
|
# ynh_app_setting_set "$app" mysqlpwd "$dbpass"
|
||||||
|
# ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
||||||
|
#
|
||||||
|
# # Load initial SQL into the new database
|
||||||
|
# ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" \
|
||||||
|
# < "../sources/sql/mysql.init.sql"
|
||||||
|
|
||||||
# Modify Nginx configuration file and copy it to Nginx conf directory
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
||||||
sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf
|
sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf
|
||||||
|
@ -52,31 +63,31 @@ sed -i "s@YNH_WWW_ALIAS@$final_path/@g" ../conf/nginx.conf
|
||||||
# If a dedicated php-fpm process is used:
|
# If a dedicated php-fpm process is used:
|
||||||
# Don't forget to modify ../conf/nginx.conf accordingly or your app will not work!
|
# Don't forget to modify ../conf/nginx.conf accordingly or your app will not work!
|
||||||
#
|
#
|
||||||
#sudo sed -i "s@YNH_WWW_APP@$app@g" ../conf/nginx.conf
|
# sudo sed -i "s@YNH_WWW_APP@$app@g" ../conf/nginx.conf
|
||||||
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
||||||
|
|
||||||
# If a dedicated php-fpm process is used:
|
# If a dedicated php-fpm process is used:
|
||||||
# Adjustment and copy dedicated php-fpm conf file
|
|
||||||
# Don't forget to modify ../conf/php-fpm.conf accordingly or your app will not work!
|
# Don't forget to modify ../conf/php-fpm.conf accordingly or your app will not work!
|
||||||
#
|
#
|
||||||
#sed -i "s@YNH_WWW_APP@$app@g" ../conf/php-fpm.conf
|
# # Modify PHP-FPM pool configuration and copy it to the pool directory
|
||||||
#sed -i "s@YNH_WWW_ALIAS@$final_path/@g" ../conf/php-fpm.conf
|
# sed -i "s@YNH_WWW_APP@$app@g" ../conf/php-fpm.conf
|
||||||
#finalphpconf=/etc/php5/fpm/pool.d/$app.conf
|
# sed -i "s@YNH_WWW_ALIAS@$final_path/@g" ../conf/php-fpm.conf
|
||||||
#sudo cp ../conf/php-fpm.conf $finalphpconf
|
# finalphpconf=/etc/php5/fpm/pool.d/$app.conf
|
||||||
#sudo chown root: $finalphpconf
|
# sudo cp ../conf/php-fpm.conf $finalphpconf
|
||||||
#sudo chmod 644 $finalphpconf
|
# sudo chown root: $finalphpconf
|
||||||
|
# sudo chmod 644 $finalphpconf
|
||||||
|
|
||||||
# If app is public, add url to SSOWat conf as skipped_uris
|
# If app is public, add url to SSOWat conf as skipped_uris
|
||||||
if [[ $is_public -eq 1 ]];
|
if [[ $is_public -eq 1 ]];
|
||||||
then
|
then
|
||||||
# unprotected_uris allows SSO credentials to be passed anyway.
|
# unprotected_uris allows SSO credentials to be passed anyway.
|
||||||
sudo yunohost app setting $app unprotected_uris -v "/"
|
ynh_app_setting_set "$app" unprotected_uris "/"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# If dedicated php-fpm process:
|
# If a dedicated php-fpm process is used:
|
||||||
#
|
#
|
||||||
#sudo service php5-fpm reload
|
# sudo service php5-fpm reload
|
||||||
|
|
||||||
# Restart services
|
# Restart services
|
||||||
sudo service nginx reload
|
sudo service nginx reload
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# The last argument is the app instance name
|
# See comments in install script
|
||||||
app=${!#}
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
# Retrieve arguments
|
# Source YunoHost helpers
|
||||||
domain=$(sudo yunohost app setting $app domain)
|
. /usr/share/yunohost/helpers
|
||||||
path=$(sudo yunohost app setting $app path)
|
|
||||||
admin=$(sudo yunohost app setting $app admin)
|
# Retrieve app settings
|
||||||
is_public=$(sudo yunohost app setting $app is_public)
|
domain=$(ynh_app_setting_get "$app" domain)
|
||||||
|
|
||||||
# Remove sources
|
# Remove sources
|
||||||
sudo rm -rf /var/www/$app
|
sudo rm -rf /var/www/$app
|
||||||
|
@ -15,14 +15,18 @@ sudo rm -rf /var/www/$app
|
||||||
# Remove configuration files
|
# Remove configuration files
|
||||||
sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf
|
sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf
|
||||||
|
|
||||||
# If a database is used, remove it
|
# If a dedicated php-fpm process is used:
|
||||||
# root_pwd=$(sudo cat /etc/yunohost/mysql)
|
|
||||||
# mysql -u root -p$root_pwd -e "DROP DATABASE $app ; DROP USER $app@localhost ;"
|
|
||||||
|
|
||||||
# If a dedicated php-fpm process is used :
|
|
||||||
#
|
#
|
||||||
#sudo rm -f /etc/php5/fpm/pool.d/$app.conf
|
# sudo rm -f /etc/php5/fpm/pool.d/$app.conf
|
||||||
#sudo service php5-fpm reload
|
# sudo service php5-fpm reload
|
||||||
|
|
||||||
|
# If a MySQL database is used:
|
||||||
|
#
|
||||||
|
# # Drop MySQL database and user
|
||||||
|
# dbname=$app
|
||||||
|
# dbuser=$app
|
||||||
|
# ynh_mysql_drop_db "$dbname" || true
|
||||||
|
# ynh_mysql_drop_user "$dbuser" || true
|
||||||
|
|
||||||
# Restart services
|
# Restart services
|
||||||
sudo service nginx reload
|
sudo service nginx reload
|
||||||
|
|
|
@ -1,13 +1,24 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
|
# Note: each files and directories you've saved using the ynh_backup helper
|
||||||
set -e
|
# will be located in the current directory, regarding the last argument.
|
||||||
|
|
||||||
|
# Exit on command errors and treat unset variables as an error
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
# See comments in install script
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
# The first argument is the backup directory location of the app
|
# Source YunoHost helpers
|
||||||
# from where the script is executed
|
. /usr/share/yunohost/helpers
|
||||||
backup_dir=$YNH_APP_BACKUP_DIR
|
|
||||||
|
# Retrieve old app settings
|
||||||
|
domain=$(ynh_app_setting_get "$app" domain)
|
||||||
|
path=$(ynh_app_setting_get "$app" path)
|
||||||
|
|
||||||
|
# Check domain/path availability
|
||||||
|
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
||||||
|
|| ynh_die "Path not available: ${domain}${path}"
|
||||||
|
|
||||||
# Restore sources & data
|
# Restore sources & data
|
||||||
final_path="/var/www/${app}"
|
final_path="/var/www/${app}"
|
||||||
|
@ -17,20 +28,23 @@ sudo cp -a ./sources "$final_path"
|
||||||
# you may need to make some file and/or directory writeable by www-data (nginx user)
|
# you may need to make some file and/or directory writeable by www-data (nginx user)
|
||||||
sudo chown -R root:root "$final_path"
|
sudo chown -R root:root "$final_path"
|
||||||
|
|
||||||
# Restore mysql database if needed
|
# If a MySQL database is used:
|
||||||
# db_pwd=$(sudo yunohost app setting $app mysqlpwd)
|
#
|
||||||
# sudo mysql -u $app -p$db_pwd $app < ./dump.sql
|
# # Create and restore the database
|
||||||
|
# dbname=$app
|
||||||
|
# dbuser=$app
|
||||||
|
# dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
||||||
|
# ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
||||||
|
# ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./dump.sql
|
||||||
|
|
||||||
# Restore NGINX configuration
|
# Restore NGINX configuration
|
||||||
domain=$(sudo yunohost app setting "$app" domain)
|
|
||||||
sudo cp -a ./nginx.conf "/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
sudo cp -a ./nginx.conf "/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
||||||
|
|
||||||
# If a dedicated php-fpm process is used :
|
# If a dedicated php-fpm process is used:
|
||||||
# Copy dedicated php-fpm process from backup folder to the right location
|
|
||||||
# And restart service
|
|
||||||
#
|
#
|
||||||
#sudo cp -a ./php-fpm.conf "/etc/php5/fpm/pool.d/${app}.conf"
|
# # Copy PHP-FPM pool configuration and reload the service
|
||||||
#sudo service php5-fpm reload
|
# sudo cp -a ./php-fpm.conf "/etc/php5/fpm/pool.d/${app}.conf"
|
||||||
|
# sudo service php5-fpm reload
|
||||||
|
|
||||||
# Restart webserver
|
# Restart webserver
|
||||||
sudo service nginx reload
|
sudo service nginx reload
|
||||||
|
|
|
@ -1,17 +1,20 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
|
# Exit on command errors and treat unset variables as an error
|
||||||
set -e
|
set -eu
|
||||||
|
|
||||||
# See comments in install script
|
# See comments in install script
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
# Retrieve arguments
|
# Source YunoHost helpers
|
||||||
domain=$(sudo yunohost app setting $app domain)
|
. /usr/share/yunohost/helpers
|
||||||
path=$(sudo yunohost app setting $app path)
|
|
||||||
admin=$(sudo yunohost app setting $app admin)
|
# Retrieve app settings
|
||||||
is_public=$(sudo yunohost app setting $app is_public)
|
domain=$(ynh_app_setting_get "$app" domain)
|
||||||
language=$(sudo yunohost app setting $app language)
|
path=$(ynh_app_setting_get "$app" path)
|
||||||
|
admin=$(ynh_app_setting_get "$app" admin)
|
||||||
|
is_public=$(ynh_app_setting_get "$app" is_public)
|
||||||
|
language=$(ynh_app_setting_get "$app" language)
|
||||||
|
|
||||||
# Remove trailing "/" for next commands
|
# Remove trailing "/" for next commands
|
||||||
path=${path%/}
|
path=${path%/}
|
||||||
|
@ -28,33 +31,33 @@ sudo chown -R root:root $final_path
|
||||||
# Modify Nginx configuration file and copy it to Nginx conf directory
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
||||||
sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf
|
sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf
|
||||||
sed -i "s@YNH_WWW_ALIAS@$final_path/@g" ../conf/nginx.conf
|
sed -i "s@YNH_WWW_ALIAS@$final_path/@g" ../conf/nginx.conf
|
||||||
# If a dedicated php-fpm process is used :
|
# If a dedicated php-fpm process is used:
|
||||||
#
|
#
|
||||||
#sudo sed -i "s@YNH_WWW_APP@$app@g" ../conf/nginx.conf
|
# sudo sed -i "s@YNH_WWW_APP@$app@g" ../conf/nginx.conf
|
||||||
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
||||||
|
|
||||||
# If a dedicated php-fpm process is used :
|
# If a dedicated php-fpm process is used:
|
||||||
# Adjustment and copy dedicated php-fpm conf file
|
|
||||||
#
|
#
|
||||||
#sed -i "s@YNH_WWW_APP@$app@g" ../conf/php-fpm.conf
|
# # Modify PHP-FPM pool configuration and copy it to the pool directory
|
||||||
#sed -i "s@YNH_WWW_ALIAS@$final_path/@g" ../conf/php-fpm.conf
|
# sed -i "s@YNH_WWW_APP@$app@g" ../conf/php-fpm.conf
|
||||||
#finalphpconf=/etc/php5/fpm/pool.d/$app.conf
|
# sed -i "s@YNH_WWW_ALIAS@$final_path/@g" ../conf/php-fpm.conf
|
||||||
#sudo cp ../conf/php-fpm.conf $finalphpconf
|
# finalphpconf=/etc/php5/fpm/pool.d/$app.conf
|
||||||
#sudo chown root: $finalphpconf
|
# sudo cp ../conf/php-fpm.conf $finalphpconf
|
||||||
#sudo chmod 644 $finalphpconf
|
# sudo chown root: $finalphpconf
|
||||||
|
# sudo chmod 644 $finalphpconf
|
||||||
|
|
||||||
# If app is public, add url to SSOWat conf as skipped_uris
|
# If app is public, add url to SSOWat conf as skipped_uris
|
||||||
if [[ $is_public -eq 1 ]];
|
if [[ $is_public -eq 1 ]];
|
||||||
then
|
then
|
||||||
# See install script
|
# See install script
|
||||||
sudo yunohost app setting $app unprotected_uris -v "/"
|
ynh_app_setting_set "$app" unprotected_uris "/"
|
||||||
# Remove old settings
|
# Remove old settings
|
||||||
sudo yunohost app setting $app skipped_uris -d
|
ynh_app_setting_delete "$app" skipped_uris
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If a dedicated php-fpm process is used :
|
# If a dedicated php-fpm process is used:
|
||||||
#
|
#
|
||||||
#sudo service php5-fpm restart
|
# sudo service php5-fpm restart
|
||||||
|
|
||||||
# Restart services
|
# Restart services
|
||||||
sudo service nginx reload
|
sudo service nginx reload
|
||||||
|
|
Loading…
Reference in a new issue