From a8c53c080e1f42f1b876e60fd47fdae2d8b5bcd9 Mon Sep 17 00:00:00 2001 From: aymhce Date: Mon, 25 Sep 2017 21:53:41 +0200 Subject: [PATCH] add comment blocks #21 --- scripts/backup | 27 +++++++++++++++++++-- scripts/install | 63 +++++++++++++++++++++++++++++++++++++++++++++---- scripts/remove | 25 ++++++++++++++++++++ scripts/restore | 44 +++++++++++++++++++++++++++++++--- scripts/upgrade | 41 ++++++++++++++++++++++++++++++++ 5 files changed, 191 insertions(+), 9 deletions(-) diff --git a/scripts/backup b/scripts/backup index 9c53a57..76aa69b 100755 --- a/scripts/backup +++ b/scripts/backup @@ -2,18 +2,41 @@ set -eu +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + . /usr/share/yunohost/helpers + +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + ynh_abort_if_errors -app=$YNH_APP_INSTANCE_NAME +#================================================= +# LOAD SETTINGS +#================================================= +app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get "$app" domain) path=$(ynh_app_setting_get "$app" path) admin=$(ynh_app_setting_get "$app" admin) +#================================================= +# BACKUP THE APP MAIN DIR +#================================================= + ynh_backup "/var/www/$app" "sources" 1 +#================================================= +# BACKUP THE NGINX CONFIGURATION +#================================================= + ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "conf/nginx.conf" +#================================================= +# BACKUP THE MYSQL DATABASE +#================================================= + ynh_mysql_dump_db "$app" > db.sql -#ynh_backup "db.sql" "db.sql" diff --git a/scripts/install b/scripts/install index 21ef53f..3984f41 100644 --- a/scripts/install +++ b/scripts/install @@ -2,32 +2,60 @@ set -eu +#================================================= +# RETRIEVE ARGUMENTS FROM THE MANIFEST +#================================================= + # Retrieve arguments app=$YNH_APP_INSTANCE_NAME domain=$YNH_APP_ARG_DOMAIN path=$YNH_APP_ARG_PATH admin_ampache=$YNH_APP_ARG_ADMIN +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + # Source helpers . /usr/share/yunohost/helpers . _common + +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + ynh_abort_if_errors +#================================================= +# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS +#================================================= + # Check if admin exists sudo yunohost user list --json | grep -qi "\"username\": \"$admin_ampache\"" || ynh_die "wrong admin username" -ynh_app_setting_set $app admin $admin_ampache - # Check domain/path availability path=$(ynh_normalize_url_path $path) ynh_webpath_available $domain $path ynh_webpath_register $app $domain $path +#================================================= +# STORE SETTINGS FROM MANIFEST +#================================================= + +ynh_app_setting_set $app admin $admin_ampache + +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= + # get sources and copy files to the right place ampache_ynh_getsources - sudo cp ../conf/admin.sql /tmp/ +#================================================= +# CREATE A MYSQL DATABASE +#================================================= + # Generate random password db_pwd=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{24\}\).*/\1/p') @@ -36,6 +64,10 @@ ynh_app_setting_set $app mysqlpwd $db_pwd ynh_mysql_setup_db "$app" "$app" "$db_pwd" ynh_mysql_connect_as "$app" "$db_pwd" "$app" < "$final_path/sql/ampache.sql" +#================================================= +# MODIFY A CONFIG FILE +#================================================= + # Change variables in Ampache configuration ampache_ynh_prepareconfig @@ -43,24 +75,47 @@ sudo sed -i "s/yunoadmin/$admin_ampache/g" /tmp/admin.sql random_key=db_pwd=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{24\}\).*/\1/p') sudo sed -i "s@RANDOMKEYTOCHANGE@$random_key@g" $final_path/config/ampache.cfg.php +#================================================= +# NGINX CONFIGURATION +#================================================= + # Modify Nginx configuration file and copy it to Nginx conf directory ampache_ynh_preparenginx +#================================================= +# INSTALL DEPENDENCIES +#================================================= + # Install dependency sudo apt-get update sudo apt-get install libav-tools -y +#================================================= +# SPECIFIC SETUP +#================================================= + # Ampache installation ampache_ynh_install +#================================================= +# RELOAD NGINX +#================================================= + # Reload Nginx and regenerate SSOwat conf ampache_ynh_reloadservices +#================================================= +# SETUP APPLICATION WITH CURL +#================================================= + # Pre config ampache ampache_ynh_doconfig - ynh_mysql_connect_as "$app" "$db_pwd" "$app" < /tmp/admin.sql +#================================================= +# CLEANING +#================================================= + # Clean install sudo rm -rf ../ampache-$version sudo rm /tmp/admin.sql diff --git a/scripts/remove b/scripts/remove index 4858599..979a55f 100644 --- a/scripts/remove +++ b/scripts/remove @@ -2,17 +2,42 @@ set -u +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + . /usr/share/yunohost/helpers +#================================================= +# LOAD SETTINGS +#================================================= + app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) +#================================================= +# REMOVE THE MYSQL DATABASE +#================================================= + ynh_mysql_drop_db $app ynh_mysql_drop_user $app +#================================================= +# REMOVE APP MAIN DIR +#================================================= + # Remove sources sudo rm -rf /var/www/$app +#================================================= +# REMOVE NGINX CONFIGURATION +#================================================= + # Remove Nginx configuration and reload Nginx conf sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf + +#================================================= +# RELOAD NGINX +#================================================= + sudo service nginx reload diff --git a/scripts/restore b/scripts/restore index c7e1639..7d74d47 100755 --- a/scripts/restore +++ b/scripts/restore @@ -2,33 +2,71 @@ set -eu +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + . /usr/share/yunohost/helpers + +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + ynh_abort_if_errors -app=$YNH_APP_INSTANCE_NAME +#================================================= +# LOAD SETTINGS +#================================================= +app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get "$app" domain) path=$(ynh_app_setting_get "$app" path) admin=$(ynh_app_setting_get "$app" admin) +#================================================= +# CHECK IF THE APP CAN BE RESTORED +#================================================= + # Check domain/path availability test ! -d /var/www/$app \ || ynh_die "There is already a directory: /var/www/$app " +#================================================= +# CHECK THE PATH +#================================================= + path=$(ynh_normalize_url_path $path) -#ynh_webpath_available $domain $path -#ynh_webpath_register $app $domain $path + +#================================================= +# REINSTALL DEPENDENCIES +#================================================= # Install dependency sudo apt-get update sudo apt-get install libav-tools -y +#================================================= +# RESTORE THE APP MAIN DIR +#================================================= + sudo cp -a ./sources "/var/www/$app" +#================================================= +# RESTORE THE NGINX CONFIGURATION +#================================================= + sudo cp -a ./conf/nginx.conf "/etc/nginx/conf.d/$domain.d/$app.conf" +#================================================= +# RESTORE THE MYSQL DATABASE +#================================================= + db_pwd=$(ynh_app_setting_get $app mysqlpwd) ynh_mysql_setup_db $app $app $db_pwd ynh_mysql_connect_as $app $db_pwd $app < ./db.sql +#================================================= +# RELOAD NGINX +#================================================= + sudo service nginx reload diff --git a/scripts/upgrade b/scripts/upgrade index e9b5969..6a9de09 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -2,10 +2,23 @@ set -eu +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + . /usr/share/yunohost/helpers . _common + +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + ynh_abort_if_errors +#================================================= +# LOAD SETTINGS +#================================================= + # Retrieve arguments app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) @@ -13,25 +26,53 @@ path=$(ynh_app_setting_get $app path) db_pwd=$(ynh_app_setting_get $app mysqlpwd) admin_ampache=$(ynh_app_setting_get $app admin) +#================================================= +# CHECK THE PATH +#================================================= + path=$(ynh_normalize_url_path $path) +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= + # Get sources and copy files to the right place ampache_ynh_getsources # Change variables in Ampache configuration ampache_ynh_prepareconfig +#================================================= +# NGINX CONFIGURATION +#================================================= + # Modify Nginx configuration file and copy it to Nginx conf directory ampache_ynh_preparenginx +#================================================= +# SPECIFIC SETUP +#================================================= + # Ampache installation ampache_ynh_install +#================================================= +# RELOAD NGINX +#================================================= + # Reload Nginx and regenerate SSOwat conf ampache_ynh_reloadservices +#================================================= +# SETUP APPLICATION WITH CURL +#================================================= + # Pre config ampache ampache_ynh_doconfig +#================================================= +# CLEANING +#================================================= + # Clean install sudo rm -rf ../ampache-$version