diff --git a/scripts/backup b/scripts/backup index 8c43f5a..ffce7d0 100644 --- a/scripts/backup +++ b/scripts/backup @@ -15,6 +15,7 @@ source ../settings/scripts/experimental_helper.sh source ../settings/scripts/_common.sh # Retrieve app settings +ynh_script_progression --message="Loading installation settings..." domain=$(ynh_app_setting_get --app $app --key domain) #================================================= @@ -22,17 +23,23 @@ domain=$(ynh_app_setting_get --app $app --key domain) #================================================= # Copy the app source files +ynh_script_progression --message="Backing up code..." --weight=3 ynh_backup --src_path "$final_path" # Copy the data files +ynh_script_progression --message="Backing up user data..." --weight=10 ynh_backup --src_path "$DATADIR" +ynh_script_progression --message="Backing up configuration..." + # Copy the conf files ynh_backup --src_path "/etc/nginx/conf.d/${domain}.d/${app}.conf" ynh_backup --src_path "/etc/systemd/system/${app}.service" # Backup logs +ynh_script_progression --message="Backing up logs..." ynh_backup --src_path "/var/log/$app" # Dump the database +ynh_script_progression --message="Backing up database" ynh_mysql_dump_db "$dbname" > ./db.sql diff --git a/scripts/change_url b/scripts/change_url index a9962a3..713ffeb 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -14,7 +14,7 @@ ynh_abort_if_errors source ./experimental_helper.sh source ./_common.sh -cp -r /etc/yunohost/apps/${app}/conf ../ # Quick hack for https://github.com/YunoHost/yunohost/pull/427 +ynh_script_progression --message="Loading installation settings..." # RETRIEVE ARGUMENTS old_domain=$YNH_APP_OLD_DOMAIN @@ -32,6 +32,8 @@ upstream_version=$(ynh_app_setting_get $app upstream_version) # STANDARD MODIFICATIONS #================================================= +ynh_script_progression --message="Updating nginx configuration..." + # MODIFY URL IN NGINX CONF nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf @@ -48,9 +50,11 @@ fi config_nginx # Update gitea config +ynh_script_progression --message="Updating gitea configuration..." config_gitea # RELOAD services +ynh_script_progression --message="Starting services..." ynh_systemd_action -l "Serving \[::\]:$port with pid" -p "/var/log/$app/gitea.log" -a restart -t 10 sleep 1 diff --git a/scripts/install b/scripts/install index dec728c..e4d3df2 100644 --- a/scripts/install +++ b/scripts/install @@ -14,6 +14,8 @@ ynh_abort_if_errors source ./experimental_helper.sh source ./_common.sh +ynh_script_progression --message="Validating installation parameters..." + # Retrieve arguments domain=$YNH_APP_ARG_DOMAIN path_url=$(ynh_normalize_url_path $YNH_APP_ARG_PATH) @@ -32,6 +34,7 @@ ynh_user_exists "$admin" \ test ! -e "$final_path" || ynh_die --message "This path already contains a folder" # Generate random password and key +ynh_script_progression --message="Defining db password and key..." dbpass=$(ynh_string_random) key=$(ynh_string_random) @@ -39,6 +42,7 @@ key=$(ynh_string_random) port=$(ynh_find_port 6000) # Store Settings +ynh_script_progression --message="Storing installation settings..." ynh_app_setting_set --app $app --key mysqlpwd --value $dbpass ynh_app_setting_set --app $app --key adminusername --value $admin ynh_app_setting_set --app $app --key is_public --value $is_public @@ -49,42 +53,40 @@ ynh_app_setting_set --app $app --key web_port --value $port # STANDARD MODIFICATIONS #================================================= - -# Configure init script -ynh_add_systemd_config - -# Modify Nginx configuration file and copy it to Nginx conf directory -config_nginx - # Initialize database and store mysql password for upgrade +ynh_script_progression --message="Configuring MySQL database..." ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass" # Add users -# We can't use the official helper (for now) because we need to set the shell for the login -test getent passwd "$app" &>/dev/null || \ - useradd -d "$DATADIR" --system --user-group "$app" --shell /bin/bash || \ - ynh_die --message "Unable to create $app system account" -# Should be replaced by this when getops is available in the helper ynh_system_user_create (probably in Yunohost 3.5) -# ynh_system_user_create --username= $app --home_dir=/opt/yunohost/$app --use_shell +ynh_script_progression --message="Configuring system user..." +ynh_system_user_create --username= $app --home_dir=/opt/yunohost/$app --use_shell # create needed directories create_dir # Configure init script +ynh_script_progression --message="Configuring a systemd service..." --weight=2 ynh_add_systemd_config # Modify Nginx configuration file and copy it to Nginx conf directory +ynh_script_progression --message="Configuring nginx..." --weight=1 config_nginx # Configure gitea with app.ini file +ynh_script_progression --message="Configuring application, step 1/2..." config_gitea +ynh_script_progression --message="Installing sources files..." --weight=10 + # Install gitea ynh_setup_source $final_path source/$architecture # Set permissions +ynh_script_progression --message="Protecting directory" set_permission +ynh_script_progression --message="Configuring application, step 2/2..." + # Start gitea for building mysql tables systemctl start "$app".service @@ -100,6 +102,7 @@ ynh_replace_string --match_string "__APP__" --replace_string "$app" --target_fil ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ../conf/login_source.sql # SETUP FAIL2BAN +ynh_script_progression --message="Configuring fail2ban..." ynh_add_fail2ban_config --logpath "/var/log/$app/gitea.log" --failregex ".*Failed authentication attempt for .* from " --max_retry 5 #================================================= @@ -107,18 +110,22 @@ ynh_add_fail2ban_config --logpath "/var/log/$app/gitea.log" --failregex ".*Faile #================================================= # Unprotect root from SSO if public +ynh_script_progression --message="Protecting directory" set_access_settings # Add gitea to YunoHost's monitored services +ynh_script_progression --message="Register gitea service..." yunohost service add "$app" --log "/var/log/$app/gitea.log" # Configure logrotate +ynh_script_progression --message="Configuring log rotation..." ynh_use_logrotate "/var/log/$app" # Save Version ynh_app_setting_set --app $app --key upstream_version --value $(ynh_app_upstream_version) # Reload services +ynh_script_progression --message="Starting gitea services..." --weight=3 ynh_systemd_action -l "Serving \[::\]:$port with pid" -p "/var/log/$app/gitea.log" -t 10 sleep 1 diff --git a/scripts/remove b/scripts/remove index bcc5268..d6e18e3 100644 --- a/scripts/remove +++ b/scripts/remove @@ -11,41 +11,53 @@ source /usr/share/yunohost/helpers source ./experimental_helper.sh source ./_common.sh +ynh_script_progression --message="Loading installation settings..." + +# Retrieve domain from app settings +domain=$(ynh_app_setting_get --app $app --key domain) + #================================================= # STANDARD REMOVE #================================================= # Stop gitea +ynh_script_progression --message="Stoping services..." systemctl stop "$app".service # Drop MySQL database and user +ynh_script_progression --message="Removing databases..." ynh_mysql_drop_db "$dbname" 2>/dev/null ynh_mysql_drop_user "$dbuser" 2>/dev/null -# Retrieve domain from app settings -domain=$(ynh_app_setting_get --app $app --key domain) - # Delete app directory and configurations +ynh_script_progression --message="Removing code..." ynh_secure_remove --file="$final_path" +ynh_script_progression --message="Removing user data..." ynh_secure_remove --file="$DATADIR" +ynh_script_progression --message="Removing logs..." ynh_secure_remove --file="/var/log/$app" # Remove the app-specific logrotate config ynh_remove_logrotate # Remove nginx config +ynh_script_progression --message="Removing nginx configuration..." ynh_remove_nginx_config # Remove gitea user and data +ynh_script_progression --message="Removing the dedicated system user..." ynh_system_user_delete $app # Remove init script +ynh_script_progression --message="Removing systemd units..." ynh_remove_systemd_config # Remove monitor +ynh_script_progression --message="Removing gitea service..." yunohost service remove "$app" # Remove fail2ban config +ynh_script_progression --message="Removing fail2ban configuration..." ynh_remove_fail2ban_config true # Do not fail if remove after install error diff --git a/scripts/restore b/scripts/restore index fc7ddc5..3c1768e 100644 --- a/scripts/restore +++ b/scripts/restore @@ -14,6 +14,8 @@ ynh_abort_if_errors source ../settings/scripts/experimental_helper.sh source ../settings/scripts/_common.sh +ynh_script_progression --message="Loading settings..." + # Retrieve old app settings domain=$(ynh_app_setting_get --app $app --key domain) path_url=$(ynh_app_setting_get --app $app --key path) @@ -37,17 +39,15 @@ test ! -e "$final_path" || ynh_die --message "This path already contains a folde #================================================= # Add users -# We can't use the official helper (for now) because we need to set the shell for the login -test getent passwd "$app" &>/dev/null || \ - useradd -d "$DATADIR" --system --user-group "$app" --shell /bin/bash || \ - ynh_die --message "Unable to create $app system account" -# Should be replaced by this when getops is available in the helper ynh_system_user_create (probably in Yunohost 3.5) -# ynh_system_user_create --username= $app --home_dir=/opt/yunohost/$app --use_shell +ynh_script_progression --message="Configuring system user..." +ynh_system_user_create --username= $app --home_dir=/opt/yunohost/$app --use_shell # Restore all files +ynh_script_progression --message="Restoring files..." --weight=10 ynh_restore # Create and restore the database +ynh_script_progression --message="Restoring database..." --weight=3 ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass" ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./db.sql @@ -56,6 +56,7 @@ systemctl daemon-reload systemctl enable "$app".service # SETUP FAIL2BAN +ynh_script_progression --message="Configuring fail2ban..." ynh_add_fail2ban_config --logpath "/var/log/$app/gitea.log" --failregex ".*Failed authentication attempt for .* from " --max_retry 5 #================================================= @@ -63,15 +64,19 @@ ynh_add_fail2ban_config --logpath "/var/log/$app/gitea.log" --failregex ".*Faile #================================================= # Set permissions +ynh_script_progression --message="Protecting directory..." set_permission # Configure logrotate +ynh_script_progression --message="Configuring log rotation..." ynh_use_logrotate "/var/log/$app" # Add gitea to YunoHost's monitored services +ynh_script_progression --message="Register gitea service..." yunohost service add "$app" --log /var/log/"$app"/gitea.log # Reload services +ynh_script_progression --message="Reloading services..." systemctl reload nginx.service ynh_systemd_action -l "Serving \[::\]:$port with pid" -p "/var/log/$app/gitea.log" -t 10 sleep 1 diff --git a/scripts/upgrade b/scripts/upgrade index d097740..fca861e 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -15,6 +15,7 @@ source ./experimental_helper.sh source ./_common.sh # Retrieve app settings +ynh_script_progression --message="Loading installation settings..." domain=$(ynh_app_setting_get --app $app --key domain) path_url=$(ynh_normalize_url_path $(ynh_app_setting_get --app $app --key path)) dbpass=$(ynh_app_setting_get --app $app --key mysqlpwd) @@ -25,12 +26,14 @@ port=$(ynh_app_setting_get --app $app --key web_port) upstream_version=$(ynh_app_setting_get --app $app --key upstream_version) # Backup the current version of the app +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=10 ynh_backup_before_upgrade ynh_clean_setup () { ynh_restore_upgradebackup } # Stop service +ynh_script_progression --message="Stoping services..." systemctl stop "$app".service #================================================= @@ -83,6 +86,8 @@ fi # STANDARD UPGRADE STEPS #================================================= +ynh_script_progression --message="Configuring application..." + # Clean template to fix issue : https://github.com/gogits/gogs/issues/4585 ynh_secure_remove --file="/opt/$app/templates" @@ -90,15 +95,19 @@ ynh_secure_remove --file="/opt/$app/templates" config_gitea # Configure init script +ynh_script_progression --message="Updating systemd units..." ynh_add_systemd_config # Modify Nginx configuration file and copy it to Nginx conf directory +ynh_script_progression --message="Configuring nginx..." --weight=1 config_nginx #================================================= # DB migration #================================================= +ynh_script_progression --message="Upgrading database and sources..." --weight=6 + # Before the version 1.7 the upstream version was not stored # The way to find the version for the install < 1.7 is to parse the binary file to find which version is installed if [ -z ${upstream_version:-} ]; then @@ -165,6 +174,7 @@ esac ynh_setup_source $final_path source/$architecture # SETUP FAIL2BAN +ynh_script_progression --message="Configuring fail2ban..." ynh_add_fail2ban_config --logpath "/var/log/$app/gitea.log" --failregex ".*Failed authentication attempt for .* from " --max_retry 5 #================================================= @@ -172,15 +182,18 @@ ynh_add_fail2ban_config --logpath "/var/log/$app/gitea.log" --failregex ".*Faile #================================================= # Set permissions +ynh_script_progression --message="Protecting directory" set_permission # Save Version ynh_app_setting_set --app $app --key upstream_version --value $(ynh_app_upstream_version) # Unprotect root from SSO if public +ynh_script_progression --message="Configuring permissions..." set_access_settings # Reload services +ynh_script_progression --message="Starting gitea services..." --weight=3 ynh_systemd_action -l "Serving \[::\]:$port with pid" -p "/var/log/$app/gitea.log" -t 10 sleep 1