From 9f455f999a5a645f0fc4faa6f341df0ab228a29a Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Sat, 6 Nov 2021 19:10:24 +0100 Subject: [PATCH] Fix --- conf/app.ini | 2 +- manifest.json | 6 ++---- scripts/backup | 12 ++++++------ scripts/install | 38 ++++++++++++++++++-------------------- scripts/remove | 3 ++- scripts/restore | 15 +++++++-------- scripts/upgrade | 43 +++++++++++++++++++++++-------------------- 7 files changed, 59 insertions(+), 60 deletions(-) diff --git a/conf/app.ini b/conf/app.ini index 7e6a99a..70cac47 100644 --- a/conf/app.ini +++ b/conf/app.ini @@ -163,7 +163,7 @@ DSA = 1024 DB_TYPE = mysql HOST = 127.0.0.1:3306 NAME = __DB_NAME__ -USER = __DB_NAME__ +USER = __DB_USER__ PASSWD = __DB_PWD__ ; For "postgres" only, either "disable", "require" or "verify-full" SSL_MODE = disable diff --git a/manifest.json b/manifest.json index db9ffaf..5bebb5d 100644 --- a/manifest.json +++ b/manifest.json @@ -29,8 +29,7 @@ "install" : [ { "name": "domain", - "type": "domain", - "example": "domain.org" + "type": "domain" }, { "name": "path", @@ -40,8 +39,7 @@ }, { "name": "admin", - "type": "user", - "example": "johndoe" + "type": "user" }, { "name": "is_public", diff --git a/scripts/backup b/scripts/backup index b9bc0ec..24f4cef 100644 --- a/scripts/backup +++ b/scripts/backup @@ -46,6 +46,12 @@ ynh_backup --src_path="/home/$app" ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" +#================================================= +# BACKUP LOGROTATE +#================================================= + +ynh_backup --src_path="/etc/logrotate.d/$app" + #================================================= # BACKUP SYSTEMD #================================================= @@ -58,12 +64,6 @@ ynh_backup --src_path="/etc/systemd/system/$app.service" ynh_backup --src_path="/var/log/$app" -#================================================= -# BACKUP LOGROTATE -#================================================= - -ynh_backup --src_path="/etc/logrotate.d/$app" - #================================================= # BACKUP THE MYSQL DATABASE #================================================= diff --git a/scripts/install b/scripts/install index c2d959d..9058155 100644 --- a/scripts/install +++ b/scripts/install @@ -96,22 +96,27 @@ chmod -R o-rwx "$final_path" chown -R $app:www-data "$final_path" #================================================= -# CREAT DIRECTORIES +# CREATE DATA DIRECTORY #================================================= +ynh_script_progression --message="Creating a data directory..." --weight=1 -mkdir -p "/home/$app" +datadir=/home/yunohost.app/$app +ynh_app_setting_set --app=$app --key=datadir --value=$datadir -DATADIR="/home/$app" +mkdir -p $datadir + +chmod 750 "$datadir" +chmod -R o-rwx "$datadir" +chown -R $app:www-data "$datadir" REPO_PATH="/home/$app/repositories" -DATA_PATH="/home/$app/data" +DATA_PATH="/home/yunohost.app/$app/data" # create needed directories mkdir -p "$final_path/data" mkdir -p "$final_path/custom/conf/auth.d" -mkdir -p "/home/$app/data/avatars" -mkdir -p "/home/$app/data/attachments" -mkdir -p "/var/log/$app" +mkdir -p "/home/yunohost.app/$app/data/avatars" +mkdir -p "/home/yunohost.app/$app/data/attachments" #================================================= # STANDARD MODIFICATIONS @@ -138,7 +143,8 @@ fi ynh_replace_string --match_string="__REPOS_PATH__" --replace_string="$REPO_PATH" --target_file="$final_path/custom/conf/app.ini" ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$final_path/custom/conf/app.ini" -ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_user" --target_file="$final_path/custom/conf/app.ini" +ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="$final_path/custom/conf/app.ini" +ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$final_path/custom/conf/app.ini" ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/custom/conf/app.ini" ynh_replace_string --match_string="__KEY__" --replace_string="$(ynh_string_random)" --target_file="$final_path/custom/conf/app.ini" ynh_replace_string --match_string="__DATA_PATH__" --replace_string="$DATA_PATH" --target_file="$final_path/custom/conf/app.ini" @@ -170,13 +176,12 @@ ynh_add_nginx_config #================================================= # GENERIC FINALIZATION #================================================= -# SECURE FILES AND DIRECTORIES +# SETUP LOGROTATE #================================================= +ynh_script_progression --message="Configuring log rotation..." --weight=1 -chown -R $app: "/home/$app" -chown -R $app: "/var/log/$app" -chmod u=rwX,g=rX,o= "/home/$app" -chmod u=rwX,g=rX,o= "/var/log/$app" +# Use logrotate to manage application logfile(s) +ynh_use_logrotate #================================================= # INTEGRATE SERVICE IN YUNOHOST @@ -185,13 +190,6 @@ ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 yunohost service add $app --description="Lightweight Git forge" --log="/var/log/$app/$app.log" -#================================================= -# SETUP LOGROTATE -#================================================= -ynh_script_progression --message="Configuring log rotation..." --weight=1 - -ynh_use_logrotate - #================================================= # START SYSTEMD SERVICE #================================================= diff --git a/scripts/remove b/scripts/remove index a0bbe42..d729e03 100644 --- a/scripts/remove +++ b/scripts/remove @@ -21,6 +21,7 @@ port=$(ynh_app_setting_get --app=$app --key=port) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name final_path=$(ynh_app_setting_get --app=$app --key=final_path) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) #================================================= # STANDARD REMOVE @@ -63,7 +64,7 @@ ynh_secure_remove --file="$final_path" # REMOVE VARIOUS FILES #================================================= -ynh_secure_remove --file="/home/$app" +ynh_secure_remove --file="$datadir" ynh_secure_remove --file="/var/log/$app" diff --git a/scripts/restore b/scripts/restore index ff9ef4a..df3061c 100644 --- a/scripts/restore +++ b/scripts/restore @@ -39,8 +39,6 @@ admin=$(ynh_app_setting_get --app=$app --key=admin) #================================================= ynh_script_progression --message="Validating restoration parameters..." --weight=2 -ynh_webpath_available --domain=$domain --path_url=$path_url \ - || ynh_die --message="Path not available: ${domain}${path_url}" test ! -d $final_path \ || ynh_die --message="There is already a directory: $final_path " @@ -89,6 +87,13 @@ ynh_script_progression --message="Restoring the systemd configuration..." --weig ynh_restore_file --origin_path="/etc/systemd/system/$app.service" systemctl enable $app.service --quiet +#================================================= +# RESTORE THE LOGROTATE CONFIGURATION +#================================================= +ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1 + +ynh_restore_file --origin_path="/etc/logrotate.d/$app" + #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= @@ -103,12 +108,6 @@ ynh_script_progression --message="Starting a systemd service..." --weight=3 ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" -#================================================= -# RESTORE THE LOGROTATE CONFIGURATION -#================================================= - -ynh_restore_file --origin_path="/etc/logrotate.d/$app" - #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 0f31634..b50a68a 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -27,6 +27,8 @@ db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) admin=$(ynh_app_setting_get --app=$app --key=admin) port=$(ynh_app_setting_get --app=$app --key=port) architecture=$(ynh_detect_arch) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) + #================================================= # CHECK VERSION @@ -34,18 +36,6 @@ architecture=$(ynh_detect_arch) upgrade_type=$(ynh_check_app_version_changed) -#================================================= -# ENSURE DOWNWARD COMPATIBILITY -#================================================= -ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 - -# Cleaning legacy permissions -if ynh_legacy_permissions_exists; then - ynh_legacy_permissions_delete_all - - ynh_app_setting_delete --app=$app --key=is_public -fi - #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= @@ -60,6 +50,18 @@ 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 + +# Cleaning legacy permissions +if ynh_legacy_permissions_exists; then + ynh_legacy_permissions_delete_all + + ynh_app_setting_delete --app=$app --key=is_public +fi + #================================================= # STANDARD UPGRADE STEPS #================================================= @@ -82,7 +84,7 @@ ynh_secure_remove --file="/opt/$app/templates" ynh_script_progression --message="Setting up source files..." --weight=3 REPO_PATH="/home/$app/repositories" -DATA_PATH="/home/$app/data" +DATA_PATH="$datadir/data" ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Download, check integrity, uncompress and patch the source from app.src @@ -105,7 +107,8 @@ fi ynh_replace_string --match_string="__REPOS_PATH__" --replace_string="$REPO_PATH" --target_file="$final_path/custom/conf/app.ini" ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$final_path/custom/conf/app.ini" -ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_user" --target_file="$final_path/custom/conf/app.ini" +ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$final_path/custom/conf/app.ini" +ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="$final_path/custom/conf/app.ini" ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/custom/conf/app.ini" ynh_replace_string --match_string="__KEY__" --replace_string="$(ynh_string_random)" --target_file="$final_path/custom/conf/app.ini" ynh_replace_string --match_string="__DATA_PATH__" --replace_string="$DATA_PATH" --target_file="$final_path/custom/conf/app.ini" @@ -140,14 +143,14 @@ ynh_script_progression --message="Upgrading NGINX web server configuration..." - ynh_add_nginx_config #================================================= -# SECURE FILES AND DIRECTORIES +# GENERIC FINALIZATION #================================================= +# SETUP LOGROTATE +#================================================= +ynh_script_progression --message="Configuring log rotation..." --weight=1 -# Set permissions to app files -chown -R $app:$app "/home/$app" -chown -R $app:$app "/var/log/$app" -chmod u=rwX,g=rX,o= "/home/$app" -chmod u=rwX,g=rX,o= "/var/log/$app" +# Use logrotate to manage application logfile(s) +ynh_use_logrotate #================================================= # INTEGRATE SERVICE IN YUNOHOST