1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/minidlna_ynh.git synced 2024-09-03 19:36:34 +02:00

Add progression bar

This commit is contained in:
Maniack Crudelis 2019-01-30 16:46:48 +01:00
parent 5622c8d744
commit be7ea84d8f
9 changed files with 164 additions and 2 deletions

View file

@ -629,6 +629,84 @@ 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}"
}
# 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"
app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID}
@ -33,6 +34,7 @@ fi
#=================================================
# RE-INSTALL MINIDLNA FROM BACKPORTS
#=================================================
ynh_script_progression --message="Re-install minidlna from backports" --weight=9
# Remove the current version of minidlna
ynh_package_remove minidlna
@ -45,3 +47,9 @@ ynh_replace_string "__CODENAME__" "$codename" /etc/yunohost/apps/$app/conf/minid
cp -a /etc/yunohost/apps/$app/conf/minidlna.list /etc/apt/sources.list.d/
ynh_apt update
ynh_package_install -t $codename-backports minidlna
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Execution completed" --last

View file

@ -31,6 +31,7 @@ fi
#=================================================
# RE-INSTALL MINIDLNA FROM STABLE
#=================================================
ynh_script_progression --message="Re-install minidlna from stable" --weight=9
# Remove the current version of minidlna
ynh_package_remove minidlna
@ -38,3 +39,9 @@ ynh_secure_remove "/etc/apt/sources.list.d/minidlna.list"
ynh_apt update
ynh_package_install minidlna
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Execution completed" --last

View file

@ -12,6 +12,7 @@ source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
ynh_script_progression --message="Retrieve arguments from the manifest"
app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID}
@ -26,8 +27,9 @@ app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID}
#=================================================
# SPECIFIC ACTION
#=================================================
# LIST ALL PADS FROM THE DATABASE
# RESET THE DATABASE
#=================================================
ynh_script_progression --message="Reset the database" --weight=9
# Get the last value for `db_dir` in the config file of minidlna
db_directory=$(tac /etc/minidlna.conf | grep --max-count=1 "db_dir=" | cut -d'=' -f 2)
@ -35,3 +37,9 @@ db_directory=$(tac /etc/minidlna.conf | grep --max-count=1 "db_dir=" | cut -d'='
ynh_systemd_action --action=stop --service_name=minidlna
ynh_secure_remove "$db_directory/files.db"
ynh_systemd_action --action=start --service_name=minidlna
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Execution completed" --last

View file

@ -19,6 +19,7 @@ ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Load settings"
app=$YNH_APP_INSTANCE_NAME
@ -32,17 +33,26 @@ version=$(ynh_app_setting_get $app version)
if [ $version = "B" ]
then
ynh_script_progression --message="Backup of the APT source"
ynh_backup "/etc/apt/sources.list.d/minidlna.list"
fi
#=================================================
# BACKUP OF INOTIFY'S CONFIG
#=================================================
ynh_script_progression --message="Backup of inotify's config"
ynh_backup "/etc/sysctl.d/90-inotify_minidlna.conf"
#=================================================
# BACKUP OF MINIDLNA CONFIGURATION
#=================================================
ynh_script_progression --message="Backup of minidlna configuration"
ynh_backup "/etc/minidlna.conf"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Backup completed" --last

View file

@ -19,6 +19,7 @@ ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
ynh_script_progression --message="Retrieve arguments from the manifest"
version="$YNH_APP_ARG_VERSION"
app=$YNH_APP_INSTANCE_NAME
@ -26,13 +27,15 @@ app=$YNH_APP_INSTANCE_NAME
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Store settings from manifest" --weight=2
ynh_app_setting_set $app version ${version:0:1}
ynh_app_setting_set $app overwrite_settings "1"
#=================================================
# CHECK THE DEBIAN'S CODENAME
# CHECK DEBIAN'S CODENAME
#=================================================
ynh_script_progression --message="Check debian's codename"
codename=$(ynh_debian_release)
test -z "$codename" && (ynh_die "codename empty")
@ -42,6 +45,7 @@ test -z "$codename" && (ynh_die "codename empty")
#=================================================
# FIND AND OPEN A PORT
#=================================================
ynh_script_progression --message="Find and open a port" --weight=15
# Find a free port
port=$(ynh_find_port 48200)
@ -55,6 +59,7 @@ ynh_app_setting_set $app port $port
#=================================================
# CREATE YUNOHOST.MULTIMEDIA DIRECTORY
#=================================================
ynh_script_progression --message="Create yunohost.multimedia directory" --weight=8
ynh_multimedia_build_main_dir
@ -63,6 +68,7 @@ ynh_multimedia_build_main_dir
#=================================================
# INSTALL MINIDLNA
#=================================================
ynh_script_progression --message="Install minidlna" --weight=45
if [ ${version:0:1} = "B" ]
then
@ -81,6 +87,7 @@ ynh_app_setting_set $app version ${version:0:1}
#=================================================
# INCREASE INOTIFY'S LIMITS
#=================================================
ynh_script_progression --message="Increase inotify's limits"
# Increase the maximum number of files inotify can monitor.
cp -a ../conf/90-inotify_minidlna.conf /etc/sysctl.d/
@ -98,6 +105,7 @@ yunohost service add minidlna --log "/var/log/minidlna.log"
#=================================================
# CONFIGURE MINIDLNA
#=================================================
ynh_script_progression --message="Configure MiniDLNA" --weight=2
ynh_replace_string "^#*media_dir=.*" "media_dir=/home/yunohost.multimedia/share" /etc/minidlna.conf
ynh_replace_string "^#*port=.*" "port=$port" /etc/minidlna.conf
@ -115,6 +123,7 @@ ynh_store_file_checksum "/etc/minidlna.conf"
#=================================================
# RESTART MINIDLNA
#=================================================
ynh_script_progression --message="Restart MiniDLNA" --weight=4
ynh_systemd_action --action=restart --service_name=minidlna
@ -137,3 +146,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/minidlna_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=2
app=$YNH_APP_INSTANCE_NAME
@ -33,6 +34,7 @@ fi
#=================================================
# CLOSE PORTS
#=================================================
ynh_script_progression --message="Close ports" --weight=15
ynh_exec_fully_quiet yunohost firewall disallow TCP $port
ynh_exec_fully_quiet yunohost firewall disallow UDP 1900
@ -42,6 +44,7 @@ ynh_exec_fully_quiet yunohost firewall disallow UDP 1900
#=================================================
# REMOVE MINIDNLA
#=================================================
ynh_script_progression --message="Remove MiniDLNA" --weight=6
ynh_apt purge minidlna
ynh_secure_remove "/etc/apt/sources.list.d/minidlna.list"
@ -49,6 +52,7 @@ ynh_secure_remove "/etc/apt/sources.list.d/minidlna.list"
#=================================================
# REMOVE INOTIFY'S CONFIG
#=================================================
ynh_script_progression --message="Remove inotify's config"
if [ -e "/etc/sysctl.d/90-inotify_minidlna.conf" ]; then
ynh_print_info "Delete kernel config" >&2
@ -58,3 +62,9 @@ if [ -e "/etc/sysctl.d/90-inotify_minidlna.conf" ]; then
sysctl -p /etc/sysctl.d/90-inotify_minidlna.conf
fi
fi
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Deletion completed" --last

View file

@ -19,6 +19,7 @@ ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Load settings"
app=$YNH_APP_INSTANCE_NAME
@ -30,6 +31,7 @@ port=$(ynh_app_setting_get $app port)
#=================================================
# OPEN PORTS
#=================================================
ynh_script_progression --message="Open ports" --weight=15
ynh_exec_fully_quiet yunohost firewall allow --no-upnp TCP $port
# Discovery Protocol SSDP for UPNP.
@ -38,12 +40,14 @@ ynh_exec_fully_quiet yunohost firewall allow --no-upnp UDP 1900
#=================================================
# CREATE YUNOHOST.MULTIMEDIA DIRECTORY
#=================================================
ynh_script_progression --message="Create yunohost.multimedia directory" --weight=6
ynh_multimedia_build_main_dir
#=================================================
# INSTALL MINIDLNA
#=================================================
ynh_script_progression --message="Install minidlna" --weight=45
if [ ${version:0:1} = "B" ]
then
@ -62,6 +66,7 @@ fi
#=================================================
# RESTORE INOTIFY'S CONFIG
#=================================================
ynh_script_progression --message="Restore inotify's config"
ynh_restore_file "/etc/sysctl.d/90-inotify_minidlna.conf"
if ! IS_PACKAGE_CHECK; then
@ -71,6 +76,7 @@ fi
#=================================================
# RESTORE MINIDLNA CONFIGURATION
#=================================================
ynh_script_progression --message="Restore MiniDLNA configuration" --weight=7
# Delete the current config of minidlna, in order to replace it by the version from the backup
ynh_secure_remove "/etc/minidlna.conf"
@ -102,3 +108,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/minidlna_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

@ -12,6 +12,7 @@ source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Load settings" --weight=2
app=$YNH_APP_INSTANCE_NAME
@ -30,6 +31,7 @@ upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensure downward compatibility"
# If overwrite_settings doesn't exist, create it
if [ -z "$overwrite_settings" ]; then
@ -52,6 +54,7 @@ fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backup the app before upgrading" --weight=2
# Backup the current version of the app
ynh_backup_before_upgrade
@ -65,12 +68,14 @@ ynh_abort_if_errors
#=================================================
# UPGRADE THE YUNOHOST.MULTIMEDIA DIRECTORY
#=================================================
ynh_script_progression --message="Upgrade the yunohost.multimedia directory" --weight=3
ynh_multimedia_build_main_dir
#=================================================
# UPGRADE MINIDLNA
#=================================================
ynh_script_progression --message="Upgrade MiniDLNA" --weight=3
if [ $version = "B" ]
then
@ -89,6 +94,7 @@ fi
#=================================================
# INCREASE INOTIFY'S LIMITS
#=================================================
ynh_script_progression --message="Increase inotify's limits" --weight=2
# Increase the maximum number of files inotify can monitor.
cp -a ../conf/90-inotify_minidlna.conf /etc/sysctl.d/
@ -106,6 +112,7 @@ yunohost service add minidlna --log "/var/log/minidlna.log"
#=================================================
# CONFIGURE MINIDLNA
#=================================================
ynh_script_progression --message="Reconfigure MiniDLNA" --weight=2
# Overwrite the settings config file only if it's allowed
if [ $overwrite_settings -eq 1 ]
@ -126,6 +133,7 @@ fi
#=================================================
# RESTART MINIDLNA'S SERVICE
#=================================================
ynh_script_progression --message="Restart MiniDLNA" --weight=7
ynh_systemd_action --action=restart --service_name=minidlna
@ -148,3 +156,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/minidlna_ynh"
ynh_send_readme_to_admin --app_message="$message" --recipients="root" --type="upgrade"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade completed" --last