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

Add progression bar

This commit is contained in:
Maniack Crudelis 2019-01-30 15:56:18 +01:00
parent c10075940a
commit b9b3b2a99f
8 changed files with 184 additions and 2 deletions

View file

@ -629,6 +629,88 @@ ynh_clean_check_starting () {
#=================================================
# Print a message as INFO and show progression during an app script
#
# usage: ynh_script_progression --message=message [--weight=weight] [--time]
# | arg: -m, --message= - The text to print
# | arg: -w, --weight= - The weight for this progression. This value is 1 by default. Use a bigger value for a longer part of the script.
# | arg: -t, --time= - Print the execution time since the last call to this helper. Especially usefull to define weights.
# | arg: -l, --last= - Use for the last call of the helper, to fill te progression bar.
increment_progression=0
previous_weight=0
# Define base_time when the file is sourced
base_time=$(date +%s)
ynh_script_progression () {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [m]=message= [w]=weight= [t]=time [l]=last )
local message
local weight
local time
local last
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
weight=${weight:-1}
time=${time:-0}
last=${last:-0}
# Get execution time since the last $base_time
local exec_time=$(( $(date +%s) - $base_time ))
base_time=$(date +%s)
# Get the number of occurrences of 'ynh_script_progression' in the script. Except those are commented.
local helper_calls="$(grep --count "^[^#]*ynh_script_progression" $0)"
# Get the number of call with a weight value
local weight_calls=$(grep --perl-regexp --count "^[^#]*ynh_script_progression.*(--weight|-w )" $0)
# Get the weight of each occurrences of 'ynh_script_progression' in the script using --weight
local weight_valuesA="$(grep --perl-regexp "^[^#]*ynh_script_progression.*--weight" $0 | sed 's/.*--weight[= ]\([[:digit:]].*\)/\1/g')"
# Get the weight of each occurrences of 'ynh_script_progression' in the script using -w
local weight_valuesB="$(grep --perl-regexp "^[^#]*ynh_script_progression.*-w " $0 | sed 's/.*-w[= ]\([[:digit:]].*\)/\1/g')"
# Each value will be on a different line.
# Remove each 'end of line' and replace it by a '+' to sum the values.
local weight_values=$(( $(echo "$weight_valuesA" | tr '\n' '+') + $(echo "$weight_valuesB" | tr '\n' '+') 0 ))
# max_progression is a total number of calls to this helper.
# Less the number of calls with a weight value.
# Plus the total of weight values
local max_progression=$(( $helper_calls - $weight_calls + $weight_values ))
# Increment each execution of ynh_script_progression in this script by the weight of the previous call.
increment_progression=$(( $increment_progression + $previous_weight ))
# Store the weight of the current call in $previous_weight for next call
previous_weight=$weight
# Set the scale of the progression bar
local scale=20
# progress_string(1,2) should have the size of the scale.
local progress_string1="####################"
local progress_string0="...................."
# Reduce $increment_progression to the size of the scale
if [ $last -eq 0 ]
then
local effective_progression=$(( $increment_progression * $scale / $max_progression ))
# If last is specified, fill immediately the progression_bar
else
local effective_progression=$scale
fi
# Build $progression_bar from progress_string(1,2) according to $effective_progression
local progression_bar="${progress_string1:0:$effective_progression}${progress_string0:0:$(( $scale - $effective_progression ))}"
local print_exec_time=""
if [ $time -eq 1 ]
then
print_exec_time=" [$(date +%Hh%Mm,%Ss --date="0 + $exec_time sec")]"
fi
ynh_print_info "[$progression_bar] > ${message}${print_exec_time}"
}
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
# Send an email to inform the administrator
#
# usage: ynh_send_readme_to_admin --app_message=app_message [--recipients=recipients] [--type=type]

View file

@ -12,6 +12,7 @@ source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
ynh_script_progression --message="Retrieve arguments from the manifest"
# Get is_public
is_public=${YNH_ACTION_IS_PUBLIC}
@ -38,6 +39,12 @@ fi
#=================================================
# MOVE TO PUBLIC OR PRIVATE
#=================================================
if [ $is_public -eq 0 ]; then
public_private="private"
else
public_private="public"
fi
ynh_script_progression --message="Move the application to $public_private" --weight=3
if [ $is_public -eq 0 ]
then
@ -49,6 +56,7 @@ else
ynh_app_setting_set $app unprotected_uris "/"
fi
ynh_script_progression --message="Reconfigure SSOwat"
# Regen ssowat configuration
yunohost app ssowatconf
@ -58,5 +66,12 @@ ynh_app_setting_set $app is_public $is_public
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reload nginx"
ynh_systemd_action --action=reload --service_name=nginx
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Execution completed" --last

View file

@ -22,6 +22,7 @@ ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Load settings" --weight=3
app=$YNH_APP_INSTANCE_NAME
@ -33,6 +34,7 @@ domain=$(ynh_app_setting_get $app domain)
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Backup the app main dir" --weight=15
ynh_systemd_action --action=stop --service_name=jenkins
sleep 1
@ -43,6 +45,7 @@ ynh_backup "$final_path"
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Backup nginx configuration"
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
@ -57,6 +60,13 @@ ynh_backup /etc/default/$app
#=================================================
# CHECK JENKINS STARTING
#=================================================
ynh_script_progression --message="Restart Jenkins" --weight=20
# Wait for Jenkins to be fully started
ynh_systemd_action --line_match="Jenkins is fully up and running" --log_path="/var/log/$app/$app.log" --timeout="300"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Backup completed" --last

View file

@ -12,6 +12,7 @@ source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
ynh_script_progression --message="Retrieve arguments from the manifest" --weight=2
old_domain=$YNH_APP_OLD_DOMAIN
old_path=$YNH_APP_OLD_PATH
@ -24,12 +25,14 @@ app=$YNH_APP_INSTANCE_NAME
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Load settings" --weight=2
port=$(ynh_app_setting_get $app port)
#=================================================
# CHECK THE SYNTAX OF THE PATHS
#=================================================
ynh_script_progression --message="Check the syntax of the paths"
test -n "$old_path" || old_path="/"
test -n "$new_path" || new_path="/"
@ -39,6 +42,7 @@ old_path=$(ynh_normalize_url_path $old_path)
#=================================================
# ACTIVATE MAINTENANCE MODE
#=================================================
ynh_script_progression --message="Activate maintenance mode" --weight=2
path_url=$old_path
domain=$old_domain
@ -75,6 +79,7 @@ ynh_abort_if_errors
#=================================================
# MODIFY URL IN NGINX CONF
#=================================================
ynh_script_progression --message="Modify url in nginx configuration" --weight=5
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
@ -109,8 +114,9 @@ fi
#=================================================
# SPECIFIC MODIFICATIONS
#=================================================
# FIX JENKINS SETUP
# MODIFY JENKINS SETUP
#=================================================
ynh_script_progression --message="Modify jenkins setup"
if [ $change_path -eq 1 ]
then
@ -134,6 +140,7 @@ fi
#=================================================
# RESTART JENKINS IN BACKGROUND
#=================================================
ynh_script_progression --message="Restart Jenkins" --weight=30
# Wait for Jenkins to be fully started
ynh_systemd_action --action=restart --line_match="Jenkins is fully up and running" --log_path="/var/log/$app/$app.log" --timeout="300"
@ -141,13 +148,21 @@ ynh_systemd_action --action=restart --line_match="Jenkins is fully up and runnin
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reload nginx" --weight=2
ynh_systemd_action --action=reload --service_name=nginx
#=================================================
# DEACTIVE MAINTENANCE MODE
#=================================================
ynh_script_progression --message="Deactive maintenance mode" --weight=5
path_url=$old_path
domain=$old_domain
ynh_maintenance_mode_OFF
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Change of url completed" --last

View file

@ -30,6 +30,7 @@ ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
ynh_script_progression --message="Retrieve arguments from the manifest"
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
@ -40,6 +41,7 @@ app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
#=================================================
ynh_script_progression --message="Check if the app can be installed"
final_path=/var/lib/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
@ -53,6 +55,7 @@ ynh_webpath_register $app $domain $path_url
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Store settings from manifest" --weight=3
ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app path $path_url
@ -65,6 +68,7 @@ ynh_app_setting_set $app overwrite_nginx "1"
#=================================================
# FIND AND OPEN A PORT
#=================================================
ynh_script_progression --message="Find a free port" --weight=2
# Find a free port
port=$(ynh_find_port 8080)
@ -73,12 +77,14 @@ ynh_app_setting_set $app port $port
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Install dependencies" --weight=30
ynh_install_app_dependencies $app_depencencies
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configure nginx" --weight=2
# Create a dedicated nginx config
ynh_add_nginx_config
@ -88,6 +94,7 @@ ynh_add_nginx_config
#=================================================
# FIX THE PORT TO USE
#=================================================
ynh_script_progression --message="Fix the port to use" --weight=2
change_port() {
# Wait for the creation of the jenkins service file
@ -110,6 +117,7 @@ pid_change_port=$!
#=================================================
# INSTALL JENKINS
#=================================================
ynh_script_progression --message="Install Jenkins" --weight=30
# Download jenkins deb file and install it.
ynh_download_file --dest_dir="../conf"
@ -118,6 +126,7 @@ dpkg --install --force-confnew ../conf/jenkins.deb
#=================================================
# SETUP JENKINS
#=================================================
ynh_script_progression --message="Configure Jenkins"
# Ignore Setup Wizard
ynh_replace_string "-Djava.awt.headless=true" "& -Djenkins.install.runSetupWizard=false" /etc/default/jenkins
@ -131,6 +140,7 @@ fi
#=================================================
# FORCE PUBLIC ACCESS
#=================================================
ynh_script_progression --message="Force public access for the installation" --weight=5
# Jenkins has to be public, at least for jenkins-cli.jar
ynh_app_setting_set $app unprotected_uris "/"
@ -147,6 +157,7 @@ yunohost service add $app --log /var/log/$app/$app.log
#=================================================
# CHECK JENKINS STARTING
#=================================================
ynh_script_progression --message="Start Jenkins" --weight=25
config_OK=0
timeout=3600
@ -163,6 +174,8 @@ ynh_replace_string "<slaveAgentPort>0</slaveAgentPort>" "&\n<enabledAgentProtoco
# Wait for Jenkins to be fully started
ynh_systemd_action --action=restart --line_match="Jenkins is fully up and running" --log_path="/var/log/$app/$app.log" --timeout="$timeout"
ynh_script_progression --message="Install plugins" --weight=60
# If the log says that jenkins has started, install the plugins
wget -nv --no-check-certificate https://$domain$path_url/jnlpJars/jenkins-cli.jar -O /var/lib/jenkins/jenkins-cli.jar
for i in `seq 1 $timeout`
@ -212,12 +225,15 @@ $jenkins_cli install-plugin fstrigger
cp ../conf/config.xml /var/lib/jenkins/
chown jenkins: /var/lib/jenkins/config.xml
ynh_script_progression --message="Restart Jenkins" --weight=20
# Wait for Jenkins to be fully started
ynh_systemd_action --action=restart --line_match="Jenkins is fully up and running" --log_path="/var/log/$app/$app.log" --timeout="$timeout"
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Setup SSOwat" --weight=9
if [ $is_public -eq 0 ]
then
@ -245,4 +261,8 @@ You can also find some specific actions for this app by using the experimental a
If you're facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/jenkins_ynh"
ynh_send_readme_to_admin --app_message="$message" --recipients="root" --type="install"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation completed" --last

View file

@ -12,6 +12,7 @@ source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Load settings" --weight=4
app=$YNH_APP_INSTANCE_NAME
@ -33,6 +34,7 @@ fi
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Remove dependencies" --weight=20
ynh_apt purge jenkins
# Remove metapackage and its dependencies
@ -42,6 +44,13 @@ ynh_secure_remove "/var/lib/jenkins"
#=================================================
# REMOVE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Remove nginx configuration" --weight=2
# Remove the dedicated nginx config
ynh_remove_nginx_config
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Deletion completed" --last

View file

@ -27,6 +27,7 @@ ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Load settings" --weight=2
app=$YNH_APP_INSTANCE_NAME
@ -47,6 +48,7 @@ test ! -d $final_path \
#=================================================
# ACTIVATE MAINTENANCE MODE
#=================================================
ynh_script_progression --message="Activate maintenance mode" --weight=2
ynh_maintenance_mode_ON
@ -66,12 +68,14 @@ ynh_systemd_action --action=reload --service_name=nginx
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstall dependencies" --weight=20
ynh_install_app_dependencies $app_depencencies
#=================================================
# FIX THE PORT TO USE
#=================================================
ynh_script_progression --message="Fix the port to use"
change_port() {
# Wait for the creation of the jenkins service file
@ -94,6 +98,7 @@ pid_change_port=$!
#=================================================
# INSTALL JENKINS
#=================================================
ynh_script_progression --message="Install Jenkins" --weight=25
# Download jenkins deb file and install it.
ynh_download_file --dest_dir="../conf"
@ -102,6 +107,7 @@ dpkg --install --force-confnew ../conf/jenkins.deb
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restore the app main directory" --weight=4
ynh_restore_file "$final_path"
@ -121,6 +127,7 @@ yunohost service add $app --log "/var/log/$app/$app.log"
#=================================================
# CHECK JENKINS STARTING
#=================================================
ynh_script_progression --message="Restart Jenkins" --weight=20
# Wait for Jenkins to be fully started
ynh_systemd_action --action=restart --line_match="Jenkins is fully up and running" --log_path="/var/log/$app/$app.log" --timeout="3600"
@ -128,6 +135,7 @@ ynh_systemd_action --action=restart --line_match="Jenkins is fully up and runnin
#=================================================
# DEACTIVE MAINTENANCE MODE
#=================================================
ynh_script_progression --message="Deactive maintenance mode" --weight=8
ynh_maintenance_mode_OFF
@ -144,3 +152,9 @@ You can also find some specific actions for this app by using the experimental a
If you're facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/jenkins_ynh"
ynh_send_readme_to_admin --app_message="$message" --recipients="root" --type="restore"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed" --last

View file

@ -14,6 +14,7 @@ source _variables
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Load settings" --weight=4
app=$YNH_APP_INSTANCE_NAME
@ -32,6 +33,7 @@ upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensure downward compatibility"
# Fix is_public as a boolean
if [ "$is_public" = "Yes" ]; then
@ -62,6 +64,7 @@ fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backup the app before upgrading" --weight=40
# Backup the current version of the app
ynh_backup_before_upgrade
@ -76,6 +79,7 @@ ynh_abort_if_errors
#=================================================
# ACTIVATE MAINTENANCE MODE
#=================================================
ynh_script_progression --message="Activate maintenance mode" --weight=2
ynh_maintenance_mode_ON
@ -85,6 +89,7 @@ ynh_maintenance_mode_ON
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrade Jenkins" --weight=40
# Download jenkins deb file and install it.
ynh_download_file --dest_dir="../conf"
dpkg --install --force-confnew ../conf/jenkins.deb
@ -106,6 +111,7 @@ fi
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrade dependencies" --weight=12
ynh_install_app_dependencies $app_depencencies
@ -116,12 +122,14 @@ ynh_install_app_dependencies $app_depencencies
# Overwrite the nginx configuration only if it's allowed
if [ $overwrite_nginx -eq 1 ]
then
ynh_script_progression --message="Reconfigure nginx" --weight=4
ynh_add_nginx_config
fi
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Reconfigure SSOwat"
if [ $is_public -eq 1 ]
then
@ -133,12 +141,14 @@ fi
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reload nginx" --weight=2
ynh_systemd_action --action=reload --service_name=nginx
#=================================================
# CHECK JENKINS STARTING
#=================================================
ynh_script_progression --message="Restart Jenkins" --weight=25
# Wait for Jenkins to be fully started
ynh_systemd_action --action=restart --line_match="Jenkins is fully up and running" --log_path="/var/log/$app/$app.log" --timeout="3600"
@ -146,12 +156,14 @@ ynh_systemd_action --action=restart --line_match="Jenkins is fully up and runnin
#=================================================
# UPGRADE JENKINS-CLI.PHAR
#=================================================
ynh_script_progression --message="Upgrade jenkins-cli.phar"
wget -nv --no-check-certificate https://$domain$path_url/jnlpJars/jenkins-cli.jar -O /var/lib/jenkins/jenkins-cli.jar
#=================================================
# DEACTIVE MAINTENANCE MODE
#=================================================
ynh_script_progression --message="Deactive maintenance mode" --weight=6
ynh_maintenance_mode_OFF
@ -168,3 +180,8 @@ You can also find some specific actions for this app by using the experimental a
If you're facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/jenkins_ynh"
ynh_send_readme_to_admin --app_message="$message" --recipients="root" --type="upgrade"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade completed" --last