1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/calibreweb_ynh.git synced 2024-09-03 18:16:20 +02:00

Update scripts to new standard

This commit is contained in:
Krakinou 2020-04-19 18:06:43 +02:00
parent 125e62ab0c
commit ef218bf3ff
7 changed files with 158 additions and 95 deletions

View file

@ -78,8 +78,8 @@ sudo yunohost app upgrade calibreweb -u https://github.com/Yunohost-Apps/calibre
## Todo ## Todo
- [X] Multiinstance - [X] Multiinstance
- [X] Better Multimedia integration : Integrate in Yunohost.multimedia - [X] Better Multimedia integration : Integrate in Yunohost.multimedia
- [ ] rework LDAP integration to create user automatically - [X] rework LDAP integration to create user automatically
- [X] Package_check integration - [ ] Package_check integration
- [X] On backup/remove/upgrade : check for database location to update settings - [X] On backup/remove/upgrade : check for database location to update settings
- [ ] enable magic link - [ ] enable magic link
- [ ] Add cronjob to reload database - [ ] Add cronjob to reload database

View file

@ -2,6 +2,5 @@
PKG_DEPENDENCIES="sqlite3 python3-pip imagemagick" PKG_DEPENDENCIES="sqlite3 python3-pip imagemagick"
DOSSIER_MEDIA=/home/yunohost.multimedia DOSSIER_MEDIA=/home/yunohost.multimedia
create_dir=0
LOG_FILE=/var/log/$app/$app.log LOG_FILE=/var/log/$app/$app.log
ACCESS_LOG_FILE=/var/log/$app/$app-access.log ACCESS_LOG_FILE=/var/log/$app/$app-access.log

View file

@ -5,12 +5,8 @@
#================================================= #=================================================
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
if [ ! -e _common.sh ]; then
# Get the _common.sh file if it's not in the current directory source ../settings/scripts/_common.sh
cp ../settings/scripts/_common.sh ./_common.sh
chmod a+rx _common.sh
fi
source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
@ -23,7 +19,7 @@ ynh_abort_if_errors
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..." --time --weight=1
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get $app final_path) final_path=$(ynh_app_setting_get $app final_path)
@ -36,19 +32,33 @@ calibre_dir=$(sqlite3 $final_path/app.db "SELECT config_calibre_dir FROM setting
calibre_dir=${calibre_dir%/} calibre_dir=${calibre_dir%/}
ynh_app_setting_set $app calibre_dir $calibre_dir ynh_app_setting_set $app calibre_dir $calibre_dir
#================================================= #=================================================
# STANDARD BACKUP STEPS # STANDARD BACKUP STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --time --weight=1
ynh_systemd_action --service_name=$app --action="stop"
#================================================= #=================================================
# BACKUP THE APP MAIN DIR # BACKUP THE APP MAIN DIR
#================================================= #=================================================
ynh_script_progression --message="Backing up the main app directory..." --time --weight=1
#This will backup the app.db file at the same time #This will backup the app.db file at the same time
ynh_backup "$final_path" ynh_backup --src_path="$final_path"
#================================================= #=================================================
# BACKUP THE NGINX CONFIGURATION # BACKUP THE NGINX CONFIGURATION
#================================================= #=================================================
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" ynh_script_progression --message="Backing up nginx web server configuration..." --time --weight=1
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= #=================================================
@ -56,26 +66,33 @@ ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= #=================================================
# BACKUP LOGROTATE # BACKUP LOGROTATE
#================================================= #=================================================
ynh_script_progression --message="Backing up logrotate configuration..." --time --weight=1
ynh_backup "/etc/logrotate.d/$app" ynh_backup --src_path="/etc/logrotate.d/$app"
#================================================= #=================================================
# BACKUP SYSTEMD # BACKUP SYSTEMD
#================================================= #=================================================
ynh_script_progression --message="Backing up systemd configuration..." --time --weight=1
ynh_backup "/etc/systemd/system/$app.service" ynh_backup --src_path="/etc/systemd/system/$app.service"
#================================================= #=================================================
# BACKUP THE DATA DIRECTORY # BACKUP THE DATA DIRECTORY
#================================================= #=================================================
ynh_script_progression --message="Backing up data directory..."
backup_core_only=$(ynh_app_setting_get "$app" backup_core_only) ynh_backup --src_path="/home/yunohost.app/${app}/data" --is_big
# If backup_core_only have any value in the settings.yml file, do not backup the data directory
if [ ! -z $backup_core_only ]
then #=================================================
ynh_print_info "Backing up the library folder $calibre_dir" # START SYSTEMD SERVICE
ynh_backup "$calibre_dir" #=================================================
else ynh_script_progression --message="Starting a systemd service..." --time --weight=1
ynh_print_info "Data dir will not be saved, because backup_core_only is set." >&2
fi ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --time --last

View file

@ -38,7 +38,7 @@ source _settings.sh
#================================================= #=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#================================================= #=================================================
ynh_script_progression -t --message="Validating installation parameters..." ynh_script_progression --message="Validating installation parameters..."
final_path=/var/www/$app final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder" test ! -e "$final_path" || ynh_die "This path already contains a folder"
@ -54,7 +54,7 @@ ynh_webpath_register $app $domain $path_url
#================================================= #=================================================
# STORE SETTINGS FROM MANIFEST # STORE SETTINGS FROM MANIFEST
#================================================= #=================================================
ynh_script_progression -t --message="Storing installation settings..." ynh_script_progression --message="Storing installation settings..."
ynh_app_setting_set $app domain $domain ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app path $path_url ynh_app_setting_set $app path $path_url
@ -71,14 +71,14 @@ ynh_app_setting_set $app is_public $is_public
# Find a free port # Find a free port
port=$(ynh_find_port 8083) port=$(ynh_find_port 8083)
# Open this port # Open this port
ynh_script_progression -t --message="Opening port $port..." --weight=5 ynh_script_progression --message="Opening port $port..." --weight=5
yunohost firewall allow --no-upnp TCP $port 2>&1 yunohost firewall allow --no-upnp TCP $port 2>&1
ynh_app_setting_set $app port $port ynh_app_setting_set $app port $port
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
ynh_script_progression -t --message="Downloading sources to $final_path..." --weight=10 ynh_script_progression --message="Downloading sources to $final_path..." --weight=10
ynh_app_setting_set $app final_path $final_path ynh_app_setting_set $app final_path $final_path
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path" ynh_setup_source "$final_path"
@ -86,19 +86,21 @@ ynh_setup_source "$final_path"
#================================================= #=================================================
# INSTALL DEPENDENCIES # INSTALL DEPENDENCIES
#================================================= #=================================================
ynh_script_progression -t --message="Installing dependencies..." --weight=15
ynh_script_progression --message="Installing package dependencies..." --weight=15
ynh_install_app_dependencies $PKG_DEPENDENCIES ynh_install_app_dependencies $PKG_DEPENDENCIES
ynh_script_progression -t --message="Installing dependencies..." --weight=15
ynh_script_progression --message="Installing pip requirements ..." --weight=30
pip3 install --no-cache-dir --target $final_path/vendor -r $final_path/requirements.txt pip3 install --no-cache-dir --target $final_path/vendor -r $final_path/requirements.txt
ynh_script_progression -t --message="Installing dependencies..." --weight=40
ynh_script_progression --message="Installing pip additionnal requirements..." --weight=40
pip3 install --no-cache-dir --upgrade --target $final_path/vendor -r $final_path/optional-requirements.txt pip3 install --no-cache-dir --upgrade --target $final_path/vendor -r $final_path/optional-requirements.txt
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
#Cannot use empty string for X-script-name, causes an issue in the python prg #Cannot use empty string for X-script-name, causes an issue in the python prg
ynh_script_progression -t --message="Setting up system configuration..." --weight=5 ynh_script_progression --message="Setting up system configuration..." --weight=5
if [ $path_url = "/" ] ; then if [ $path_url = "/" ] ; then
@ -127,7 +129,7 @@ ynh_add_systemd_config
#================================================= #=================================================
# CREATE FILES AND DIRECTORIES # CREATE FILES AND DIRECTORIES
#================================================= #=================================================
ynh_script_progression -t --message="Creating files and directory..." ynh_script_progression --message="Creating files and directory..."
#Logic is as follow : if app is set to be publicly accessible, we will assume that the library should be set in "Share" multimedia directory #Logic is as follow : if app is set to be publicly accessible, we will assume that the library should be set in "Share" multimedia directory
# If app is set to be private but access is requested for all user, we will assume the same # If app is set to be private but access is requested for all user, we will assume the same
# If app is set to be private but access is limited to the admin user, we will set it inside his own multimedia directory. # If app is set to be private but access is limited to the admin user, we will set it inside his own multimedia directory.
@ -167,7 +169,7 @@ chown -R $app:$app /var/log/$app
#================================================= #=================================================
# SET SQLITE DATABASE SETTINGS # SET SQLITE DATABASE SETTINGS
#================================================= #=================================================
ynh_script_progression -t --message="Setting up database and settings..." ynh_script_progression --message="Setting up database and settings..."
#we need to start and stop the service so that initial app.db file is created and that we can set default data #we need to start and stop the service so that initial app.db file is created and that we can set default data
ynh_systemd_action ynh_systemd_action
@ -204,7 +206,7 @@ ynh_store_file_checksum "${final_path}/app.db"
# ADVERTISE SERVICE IN ADMIN PANEL # ADVERTISE SERVICE IN ADMIN PANEL
#================================================= #=================================================
yunohost service add $app --log "/var/log/$app/$app.log" yunohost service add $app --description "Browse eBook in the web" --log "/var/log/$app/$app.log"
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT
@ -222,10 +224,14 @@ if [ $public_library -eq 0 ]; then
fi fi
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_script_progression -t -l --message="Reload nginx and start $app..." ynh_script_progression --message="Reload nginx and start $app..."
systemctl reload nginx ynh_systemd_action --service_name=nginx --action=reload
ynh_systemd_action ynh_systemd_action
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last

View file

@ -12,6 +12,7 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..." --weight=2
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get $app domain)
@ -23,10 +24,10 @@ calibre_dir=$(ynh_app_setting_get $app calibre_dir)
# REMOVE SERVICE FROM ADMIN PANEL # REMOVE SERVICE FROM ADMIN PANEL
#================================================= #=================================================
# Remove a service from the admin panel, added by `yunohost service add` # Remove the service from the list of services known by Yunohost (added from `yunohost service add`)
if yunohost service status | grep -q $app if ynh_exec_warn_less yunohost service status $app >/dev/null
then then
echo "Remove $app service" ynh_script_progression --message="Removing $app service..." --time --weight=1
yunohost service remove $app yunohost service remove $app
fi fi
@ -37,7 +38,7 @@ fi
#================================================= #=================================================
# Remove the dedicated systemd config # Remove the dedicated systemd config
ynh_script_progression -t --message="Removing systemd..." ynh_script_progression --message="Stopping and removing the systemd service..."
ynh_remove_systemd_config ynh_remove_systemd_config
@ -47,7 +48,7 @@ ynh_remove_systemd_config
#================================================= #=================================================
# Remove metapackage and its dependencies # Remove metapackage and its dependencies
ynh_script_progression -t --message="Removing Dependencies..." ynh_script_progression --message="Removing Dependencies..."
ynh_remove_app_dependencies ynh_remove_app_dependencies
@ -56,15 +57,15 @@ ynh_remove_app_dependencies
#================================================= #=================================================
# Remove the app directory securely # Remove the app directory securely
ynh_script_progression -t --message="Removing $final_path..." ynh_script_progression --message="Removing $final_path..."
ynh_secure_remove "$final_path" ynh_secure_remove --file="$final_path"
#================================================= #=================================================
# REMOVE NGINX CONFIGURATION # REMOVE NGINX CONFIGURATION
#================================================= #=================================================
# Remove the dedicated nginx config # Remove the dedicated nginx config
ynh_script_progression -t --message="Removing Nginx Config..." ynh_script_progression --message="Removing nginx web server configuration..."
ynh_remove_nginx_config ynh_remove_nginx_config
#================================================= #=================================================
@ -72,6 +73,7 @@ ynh_remove_nginx_config
#================================================= #=================================================
# Remove the app-specific logrotate config # Remove the app-specific logrotate config
ynh_script_progression --message="Removing logrotate configuration..."
ynh_remove_logrotate ynh_remove_logrotate
#================================================= #=================================================
@ -80,14 +82,14 @@ ynh_remove_logrotate
if yunohost firewall list | grep -q "\- $port$" if yunohost firewall list | grep -q "\- $port$"
then then
ynh_script_progression -t --message="Closing port $port..." ynh_script_progression --message="Closing port $port..."
yunohost firewall disallow TCP $port 2>&1 yunohost firewall disallow TCP $port 2>&1
fi fi
#================================================= #=================================================
# SPECIFIC REMOVE # SPECIFIC REMOVE
#================================================= #=================================================
ynh_script_progression -t --message="Removing log and user $app..." ynh_script_progression --message="Removing log and user $app..."
# Remove the log files # Remove the log files
ynh_secure_remove "/var/log/$app/" ynh_secure_remove "/var/log/$app/"
@ -97,12 +99,12 @@ ynh_secure_remove "/var/log/$app/"
#================================================= #=================================================
# REMOVE DEDICATED USER # REMOVE DEDICATED USER
#================================================= #=================================================
ynh_script_progression --message="Removing the dedicated system user..."
# Delete a system user # Delete a system user
ynh_system_user_delete $app ynh_system_user_delete --username=$app
#================================================= #=================================================
# MESSAGE TO USER # MESSAGE TO USER
#================================================= #=================================================
ynh_script_progression --message="Removal of $app completed" --last
ynh_print_warn "!!!The library folder $calibre_dir was not deleted. Delete it manually if required!!!" ynh_print_warn "!!!The library folder $calibre_dir was not deleted. Delete it manually if required!!!"

View file

@ -6,12 +6,7 @@
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
if [ ! -e _common.sh ]; then source ../settings/scripts/_common.sh
# Get the _common.sh file if it's not in the current directory
cp ../settings/scripts/_common.sh ./_common.sh
chmod a+rx _common.sh
fi
source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
@ -24,7 +19,7 @@ ynh_abort_if_errors
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Loading settings..." --time --weight=1
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get $app domain)
@ -33,11 +28,12 @@ final_path=$(ynh_app_setting_get $app final_path)
calibre_dir=$(ynh_app_setting_get $app calibre_dir) calibre_dir=$(ynh_app_setting_get $app calibre_dir)
is_public=$(ynh_app_setting_get $app is_public) is_public=$(ynh_app_setting_get $app is_public)
port=$(ynh_app_setting_get $app port) port=$(ynh_app_setting_get $app port)
source ../settings/scripts/_settings.sh
#================================================= #=================================================
# CHECK IF THE APP CAN BE RESTORED # CHECK IF THE APP CAN BE RESTORED
#================================================= #=================================================
ynh_script_progression --message="Validating restoration parameters..." --time --weight=1
ynh_webpath_available $domain $path_url \ ynh_webpath_available $domain $path_url \
|| ynh_die "Path not available: ${domain}${path_url}" || ynh_die "Path not available: ${domain}${path_url}"
test ! -d $final_path \ test ! -d $final_path \
@ -48,14 +44,14 @@ test ! -d $final_path \
#================================================= #=================================================
# RESTORE THE NGINX CONFIGURATION # RESTORE THE NGINX CONFIGURATION
#================================================= #=================================================
ynh_print_info "Restore nginx settings" ynh_script_progression --message="Restoring nginx configuration..." --time --weight=1
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= #=================================================
# REOPEN PORT # REOPEN PORT
#================================================= #=================================================
ynh_print_info "Reopening port $port" ynh_script_progression --message="reopening port $port..." --weight=5
yunohost firewall allow --no-upnp TCP $port 2>&1 yunohost firewall allow --no-upnp TCP $port 2>&1
ynh_app_setting_set $app port $port ynh_app_setting_set $app port $port
@ -63,15 +59,17 @@ ynh_app_setting_set $app port $port
# RECREATE THE DEDICATED USER # RECREATE THE DEDICATED USER
#================================================= #=================================================
ynh_print_info "Restore user $app" ynh_script_progression --message="Recreating the dedicated system user..." --time --weight=1
# Create the dedicated user (if not existing) # Create the dedicated user (if not existing)
ynh_system_user_create $app ynh_system_user_create --username=$app
#================================================= #=================================================
# RESTORE THE APP MAIN DIR # RESTORE THE APP MAIN DIR
#================================================= #=================================================
ynh_print_info "Restore app directory $final_path" ynh_script_progression --message="Restoring the app main directory..." --time --weight=1
ynh_restore_file "$final_path"
ynh_restore_file --origin_path="$final_path"
#================================================= #=================================================
# RESTORE USER RIGHTS # RESTORE USER RIGHTS
@ -87,45 +85,43 @@ chown -R $app: $final_path
#================================================= #=================================================
# Define and install dependencies # Define and install dependencies
ynh_print_info "Installing dependencies and pip packages" ynh_script_progression --message="Reinstalling dependencies..." --time --weight=1
ynh_install_app_dependencies $PKG_DEPENDENCIES ynh_install_app_dependencies $PKG_DEPENDENCIES
#pip package not required as already in app directory #pip package not required as already in app directory
#pip install --target $final_path/vendor -r $final_path/requirements.txt #pip install --target $final_path/vendor -r $final_path/requirements.txt
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
yunohost service add $app --log "/var/log/$app/$app.log"
#================================================= #=================================================
# RESTORE SYSTEMD # RESTORE SYSTEMD
#================================================= #=================================================
ynh_script_progression --message="Restoring the systemd configuration..." --time --weight=1
ynh_restore_file "/etc/systemd/system/$app.service" ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service systemctl enable $app.service
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
yunohost service add $app --description "Browse eBook in the web" --log "/var/log/$app/$app.log"
#================================================= #=================================================
# RESTORE THE LOGROTATE CONFIGURATION # RESTORE THE LOGROTATE CONFIGURATION
#================================================= #=================================================
ynh_restore_file "/etc/logrotate.d/$app" ynh_restore_file --origin_path="/etc/logrotate.d/$app"
if [ ! -e /var/log/$app ]; then
mkdir /var/log/$app
fi
chown -R $app:$app /var/log/$app chown -R $app:$app /var/log/$app
#================================================= #=================================================
# RESTORE THE DATA DIRECTORY # RESTORE THE DATA DIRECTORY
#================================================= #=================================================
ynh_script_progression --message="Restoring data directory..." --weight=2
# The data directory will be restored only if it exists in the backup archive # The data directory will be restored only if it exists in the backup archive
# So only if it was backup previously. # So only if it was backup previously.
if [ -d "$YNH_BACKUP_DIR/apps/$app/backup/$calibre_dir" ] if [ -d "$YNH_BACKUP_DIR/apps/$app/backup/$calibre_dir" ]
then then
ynh_restore_file "$calibre_dir" ynh_restore_file --origin_path="$calibre_dir" --not_mandatory
else else
if [ ! -e "$calibre_dir" ]; then if [ ! -e "$calibre_dir" ]; then
ynh_print_info "Create calibre library folder $calibre_dir" ynh_print_info "Create calibre library folder $calibre_dir"
@ -149,7 +145,7 @@ ynh_app_setting_delete $app backup_core_only
if [ $is_public -eq 1 ] if [ $is_public -eq 1 ]
then then
# unprotected_uris allows SSO credentials to be passed anyway. # unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set $app unprotected_uris "/" ynh_permission_update --permission "main" --add visitors
fi fi
#================================================= #=================================================
@ -157,10 +153,21 @@ fi
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_print_info "Reload nginx and start $app" ynh_script_progression --message="Reloading nginx web server..." --time --weight=1
systemctl reload nginx ynh_systemd_action --service_name=nginx --action=reload
ynh_systemd_action -l "INFO in server: Starting Gevent server"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --time --weight=1
ynh_systemd_action --service_name=$app --action="start"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for $app" --time --last
#================================================= #=================================================
# WARNING FOR READ ACCESS # WARNING FOR READ ACCESS
#================================================= #=================================================

View file

@ -12,7 +12,7 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..." --time --weight=1
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get $app domain)
@ -22,6 +22,7 @@ is_public=$(ynh_app_setting_get $app is_public)
final_path=$(ynh_app_setting_get $app final_path) final_path=$(ynh_app_setting_get $app final_path)
language=$(ynh_app_setting_get $app language) language=$(ynh_app_setting_get $app language)
#Get settings from database in case it has been changed in the app #Get settings from database in case it has been changed in the app
calibre_dir=$(sqlite3 $final_path/app.db "SELECT config_calibre_dir FROM settings WHERE ID=1") calibre_dir=$(sqlite3 $final_path/app.db "SELECT config_calibre_dir FROM settings WHERE ID=1")
#Save it in settings so that it can be used back afterward #Save it in settings so that it can be used back afterward
@ -29,12 +30,17 @@ calibre_dir=${calibre_dir%/}
ynh_app_setting_set $app calibre_dir $calibre_dir ynh_app_setting_set $app calibre_dir $calibre_dir
port=$(ynh_app_setting_get $app port) port=$(ynh_app_setting_get $app port)
source _settings.sh
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#================================================= #=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#================================================= #=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --time --weight=1
# Backup the current version of the app # Backup the current version of the app
ynh_backup_before_upgrade ynh_backup_before_upgrade
ynh_clean_setup () { ynh_clean_setup () {
@ -45,7 +51,9 @@ ynh_clean_setup () {
ynh_abort_if_errors ynh_abort_if_errors
#Stop the app in case database is updated #Stop the app in case database is updated
ynh_systemd_action -a stop ynh_script_progression --message="Stopping a systemd service..." --time --weight=1
ynh_systemd_action --service_name=$app --action="stop"
#================================================= #=================================================
# CHECK THE PATH # CHECK THE PATH
@ -62,12 +70,18 @@ path_url=$(ynh_normalize_url_path $path_url)
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
ynh_print_info "Download and install new sources" ynh_print_info "Download and install new sources"
ynh_setup_source "$final_path" if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..." --time --weight=1
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
fi
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Upgrading nginx web server configuration..." --time --weight=1
if [ $path_url = "/" ] ; then if [ $path_url = "/" ] ; then
ynh_replace_string " proxy_set_header X-Script-Name" "# proxy_set_header X-Script-Name" ../conf/nginx.conf ynh_replace_string " proxy_set_header X-Script-Name" "# proxy_set_header X-Script-Name" ../conf/nginx.conf
fi fi
@ -78,16 +92,21 @@ ynh_add_nginx_config
#================================================= #=================================================
# UPGRADE DEPENDENCIES # UPGRADE DEPENDENCIES
#================================================= #=================================================
ynh_print_info "Download and install dependencies" ynh_script_progression --message="Installing package dependencies..." --weight=15
ynh_install_app_dependencies $PKG_DEPENDENCIES ynh_install_app_dependencies $PKG_DEPENDENCIES
ynh_script_progression --message="Installing pip requirements ..." --weight=30
pip3 install --no-cache-dir --target $final_path/vendor -r $final_path/requirements.txt pip3 install --no-cache-dir --target $final_path/vendor -r $final_path/requirements.txt
pip3 install --no-cache-dir --target $final_path/vendor -r $final_path/optional-requirements.txt
ynh_script_progression --message="Installing pip additionnal requirements..." --weight=40
pip3 install --no-cache-dir --upgrade --target $final_path/vendor -r $final_path/optional-requirements.txt
#================================================= #=================================================
# CREATE DEDICATED USER # CREATE DEDICATED USER
#================================================= #=================================================
# Create a dedicated user (if not existing) # Create a dedicated user (if not existing)
ynh_script_progression --message="Making sure dedicated system user exists..." --time --weight=1
ynh_system_user_create $app ynh_system_user_create $app
# Set permissions on app files (required to be able to update database) # Set permissions on app files (required to be able to update database)
@ -98,7 +117,7 @@ chown -R $app: $final_path
#================================================= #=================================================
#build multimedia directory #build multimedia directory
#================================================= #=================================================
ynh_script_progression --message="Create Multimedia dir..." --time --weight=1
#Create multimedia directory but we do not change the calibre_dir : It's the user to make this choice. #Create multimedia directory but we do not change the calibre_dir : It's the user to make this choice.
ynh_multimedia_build_main_dir ynh_multimedia_build_main_dir
ynh_multimedia_addaccess $app ynh_multimedia_addaccess $app
@ -106,7 +125,7 @@ ynh_multimedia_addaccess $app
#================================================= #=================================================
#Update database structure #Update database structure
#================================================= #=================================================
ynh_script_progression --message="Update database..." --time --weight=1
### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. ### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it. ### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it.
ynh_backup_if_checksum_is_different "$final_path/app.db" ynh_backup_if_checksum_is_different "$final_path/app.db"
@ -128,6 +147,7 @@ ynh_store_file_checksum "$final_path/app.db"
#================================================= #=================================================
# Use logrotate to manage app-specific logfile(s) # Use logrotate to manage app-specific logfile(s)
ynh_script_progression --message="Upgrading logrotate configuration..." --time --weight=1
ynh_use_logrotate --non-append ynh_use_logrotate --non-append
#================================================= #=================================================
@ -135,6 +155,7 @@ ynh_use_logrotate --non-append
#================================================= #=================================================
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_script_progression --message="Upgrading systemd configuration..." --time --weight=1
ynh_add_systemd_config ynh_add_systemd_config
#================================================= #=================================================
@ -169,6 +190,17 @@ fi
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_script_progression --message="Reloading nginx web server..." --time --weight=1
systemctl reload nginx ynh_systemd_action --service_name=nginx --action=reload
ynh_systemd_action -a restart #=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --time --weight=1
ynh_systemd_action --service_name=$app --action="start"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --time --last