1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/calibreweb_ynh.git synced 2024-09-03 18:16:20 +02:00
This commit is contained in:
Krakinou 2021-06-06 13:18:44 +02:00
parent 437ddb2a47
commit 71e93da3a0
5 changed files with 58 additions and 61 deletions

View file

@ -17,7 +17,7 @@
setup_public=1 setup_public=1
upgrade=1 upgrade=1
#Last version #Last version
upgrade=1 from_commit=69b86b123ddb3b13e25f39df32bc17a872d67e5e upgrade=1 from_commit=daf9f864b4f4adde4130c9d000ecc87f5d44ca42
#v0.6.6 #v0.6.6
# upgrade=1 from_commit=11f5b96df7d8850beff47f9904745fa53a6f7ed9 # upgrade=1 from_commit=11f5b96df7d8850beff47f9904745fa53a6f7ed9
backup_restore=1 backup_restore=1

View file

@ -1,3 +0,0 @@
nickname=\'$admin\',
locale=\'$language\',
mature_content=0

View file

@ -4,6 +4,6 @@ PKG_DEPENDENCIES="sqlite3 libldap2-dev libsasl2-dev python3-dev imagemagick pyth
DOSSIER_MEDIA=/home/yunohost.multimedia DOSSIER_MEDIA=/home/yunohost.multimedia
#These var are used in init_calibre_db_settings conf file #These var are used in init_calibre_db_settings conf file
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

@ -27,12 +27,19 @@ public_library=$YNH_APP_ARG_PUBLIC_LIBRARY
#when initializing the conf file of the app #when initializing the conf file of the app
source _common.sh source _common.sh
#if app is public, we assume library is public #if app is public, we assume library is public
if [ $is_public -eq 1 ]; then if [ $is_public -eq 1 ]; then
public_library=1 public_library=1
fi fi
if [ $is_public -eq 1 ]; then #app is public, library is public
calibre_dir=$DOSSIER_MEDIA/share/eBook
elif [ $is_public -eq 0 ] && [ $public_library -eq 1 ]; then #app is private, library is public
calibre_dir=$DOSSIER_MEDIA/share/eBook
else #app is private, library is private
calibre_dir=$DOSSIER_MEDIA/$admin/eBook
fi
#================================================= #=================================================
# MANAGE SCRIPT FAILURE # MANAGE SCRIPT FAILURE
#================================================= #=================================================
@ -79,6 +86,12 @@ ynh_app_setting_set $app port $port
#================================================= #=================================================
ynh_script_progression --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
#Set settings constant initializer of the app
ynh_add_config --template="../sources/patches/app-config_sql.py.patch.src" --destination="../sources/patches/app-config_sql.py.patch"
ynh_add_config --template="../sources/patches/app-ub.py.patch.src" --destination="../sources/patches/app-ub.py.patch"
ynh_add_config --template="../sources/patches/app-constants.py.patch.src" --destination="../sources/patches/app-constants.py.patch"
# 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"
@ -143,13 +156,6 @@ ynh_script_progression --message="Creating files and directory..." --weight=5
ynh_multimedia_build_main_dir ynh_multimedia_build_main_dir
ynh_multimedia_addaccess $app ynh_multimedia_addaccess $app
if [ $is_public -eq 1 ]; then #app is public, library is public
calibre_dir=$DOSSIER_MEDIA/share/eBook
elif [ $is_public -eq 0 ] && [ $public_library -eq 1 ]; then #app is private, library is public
calibre_dir=$DOSSIER_MEDIA/share/eBook
else #app is private, library is private
calibre_dir=$DOSSIER_MEDIA/$admin/eBook
fi
#Check if metadata.db file exists. If not create it (empty library) #Check if metadata.db file exists. If not create it (empty library)
if [ ! -e "$calibre_dir"/metadata.db ]; then if [ ! -e "$calibre_dir"/metadata.db ]; then
@ -177,20 +183,20 @@ ynh_script_progression --message="Setting up database and settings..." --weight=
#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
#If port 8083 is already in use (ex for second instance), then service start will fail, which is expected : so we do not want #If port 8083 is already in use (ex for second instance), then service start will fail, which is expected : so we do not want
#to set $port on the line match. "server on" will be displayed in case the port is already in use and should be ok to spot the fact that the database is initialized. #to set $port on the line match. "server on" will be displayed in case the port is already in use and should be ok to spot the fact that the database is initialized.
ynh_systemd_action --service_name=$app --action="start" --line_match="Starting Gevent server on" --log_path="$final_path/calibre-web.log" -t 30 #ynh_systemd_action --service_name=$app --action="start" --line_match="Starting Gevent server on" --log_path="$final_path/calibre-web.log" -t 30
#sleep required on low spec like raspberryPi #sleep required on low spec like raspberryPi
sleep 2s #sleep 2s
#remove unwanted calibre-web.log #remove unwanted calibre-web.log
ynh_secure_remove --file="$final_path/calibre-web.log" #ynh_secure_remove --file="$final_path/calibre-web.log"
ynh_systemd_action --service_name=$app --action="stop" #ynh_systemd_action --service_name=$app --action="stop"
#set database settings as per conf file #set database settings as per conf file
conf="\"UPDATE settings SET $(. <(echo -E echo $(<../conf/init_calibre_db_settings))), $(. <(echo -E echo $(<../conf/init_calibre_db_ldap_settings))) WHERE ID=1\"" #conf="\"UPDATE settings SET $(. <(echo -E echo $(<../conf/init_calibre_db_settings))), $(. <(echo -E echo $(<../conf/init_calibre_db_ldap_settings))) WHERE ID=1\""
eval sqlite3 $final_path/app.db "$conf" #eval sqlite3 $final_path/app.db "$conf"
conf="\"UPDATE user SET $(. <(echo -E echo $(<../conf/init_calibre_db_user))) WHERE ID=1\"" #conf="\"UPDATE user SET $(. <(echo -E echo $(<../conf/init_calibre_db_user))) WHERE ID=1\""
eval sqlite3 $final_path/app.db "$conf" #eval sqlite3 $final_path/app.db "$conf"
#Update Imagick policy as per https://github.com/janeczku/calibre-web/wiki/FAQ#what-to-do-if-cover-pictures-are-not-extracted-from-pdf-files #Update Imagick policy as per https://github.com/janeczku/calibre-web/wiki/FAQ#what-to-do-if-cover-pictures-are-not-extracted-from-pdf-files
ynh_replace_string --match_string="<policy domain="coder" rights="none" pattern="PDF" />" \ ynh_replace_string --match_string="<policy domain="coder" rights="none" pattern="PDF" />" \
@ -204,7 +210,7 @@ ynh_replace_string --match_string="<policy domain="coder" rights="none" pattern=
#================================================= #=================================================
# Calculate and store the config file checksum into the app settings # Calculate and store the config file checksum into the app settings
ynh_store_file_checksum "${final_path}/app.db" #ynh_store_file_checksum "${final_path}/app.db"
#================================================= #=================================================
# INTEGRATE SERVICE IN YUNOHOST # INTEGRATE SERVICE IN YUNOHOST

View file

@ -10,7 +10,6 @@ version_gt() {
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
@ -59,13 +58,6 @@ else #on est encore en 0.6.0
current_upstream_app_version='0.6.0' current_upstream_app_version='0.6.0'
fi fi
#Close unwanted open port in firewall
if yunohost firewall list | grep -q "\- $port$"
then
ynh_script_progression --message="Closing port $port as it shouldn't be open..."
yunohost firewall disallow TCP $port 2>&1
fi
#================================================= #=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
@ -90,12 +82,23 @@ ynh_script_progression --message="Stopping a systemd service..." --weight=2
ynh_systemd_action --service_name=$app --action="stop" ynh_systemd_action --service_name=$app --action="stop"
#================================================= #=================================================
# STANDARD UPGRADE STEPS # ENSURE DOWNWARD COMPATIBILITY
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
ynh_script_progression --message="Downward Compatibility checks..." --weight=1
#Close unwanted open port in firewall
if yunohost firewall list | grep -q "\- $port$"
then
ynh_script_progression --message="Closing port $port as it shouldn't be open..."
yunohost firewall disallow TCP $port 2>&1
fi
# If language was set delete it
if [ ! -z "$language" ]; then
ynh_app_setting_delete --app=$app --key=language
#fi
#binaries version is 0.6.0, we need to go throught upgrade to 0.6.6 so that app.db is correctly updated, otherwise database is corrupted #binaries version is 0.6.0, we need to go throught upgrade to 0.6.6 so that app.db is correctly updated, otherwise database is corrupted
#set database settings as per conf file : restart server so that app.db is regenerated, then add new ldap & log settings
if version_gt "0.6.6" "$current_upstream_app_version" && [ "$current_upstream_package_version" == "0.6.0" ] && [ "$upgrade_type" == "UPGRADE_APP" ]; then if version_gt "0.6.6" "$current_upstream_app_version" && [ "$current_upstream_package_version" == "0.6.0" ] && [ "$upgrade_type" == "UPGRADE_APP" ]; then
ynh_script_progression --message="Upgrading from $current_upstream_app_version to 0.6.6..." --weight=50 ynh_script_progression --message="Upgrading from $current_upstream_app_version to 0.6.6..." --weight=50
ynh_setup_source --dest_dir="$final_path" --source_id="app066" ynh_setup_source --dest_dir="$final_path" --source_id="app066"
@ -106,13 +109,28 @@ if version_gt "0.6.6" "$current_upstream_app_version" && [ "$current_upstream_pa
#sleep required on low spec like raspberryPi #sleep required on low spec like raspberryPi
sleep 2s sleep 2s
ynh_systemd_action --service_name=$app --action="stop" ynh_systemd_action --service_name=$app --action="stop"
conf="\"UPDATE settings SET $(. <(echo -E echo $(<../conf/init_calibre_db_settings))), $(. <(echo -E echo $(<../conf/init_calibre_db_ldap_settings))) WHERE ID=1\""
eval sqlite3 $final_path/app.db "$conf"
current_upstream_app_version="0.6.6" current_upstream_app_version="0.6.6"
#remove unwanted entry in settings db
fi fi
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ] if [ "$upgrade_type" == "UPGRADE_APP" ]
then then
ynh_script_progression --message="Upgrading source files from $current_upstream_app_version to $new_upstream_package_version..." --weight=10 ynh_script_progression --message="Upgrading source files from $current_upstream_app_version to $new_upstream_package_version..." --weight=10
#Set settings constant initializer of the app
ynh_add_config --template="../sources/patches/app-config_sql.py.patch.src" --destination="../sources/patches/app-config_sql.py.patch"
ynh_add_config --template="../sources/patches/app-ub.py.patch.src" --destination="../sources/patches/app-ub.py.patch"
ynh_add_config --template="../sources/patches/app-constants.py.patch.src" --destination="../sources/patches/app-constants.py.patch"
# 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 --dest_dir="$final_path" ynh_setup_source --dest_dir="$final_path"
fi fi
@ -168,37 +186,13 @@ ynh_script_progression --message="Create Multimedia dir..." --weight=1
ynh_multimedia_build_main_dir ynh_multimedia_build_main_dir
ynh_multimedia_addaccess $app ynh_multimedia_addaccess $app
#=================================================
#Update database structure
#=================================================
ynh_script_progression --message="Update database..." --weight=1
### 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.
ynh_backup_if_checksum_is_different "$final_path/app.db"
#set database settings as per conf file : restart server so that app.db is regenerated, then add new ldap & log settings
if [ "$current_upstream_app_version" == '0.6.6' ]; then
ynh_systemd_action --service_name=$app --action="start" --line_match="server on " --log_path="$final_path/calibre-web.log" -t 30
else
ynh_systemd_action --service_name=$app --action="start" --line_match="Starting Gevent server on" -t 30
fi
#sleep required on low spec like raspberryPi
sleep 2s
#remove unwanted calibre-web.log
ynh_secure_remove --file="$final_path/calibre-web.log"
ynh_systemd_action --service_name=$app --action="stop"
conf="\"UPDATE settings SET $(. <(echo -E echo $(<../conf/init_calibre_db_settings))), $(. <(echo -E echo $(<../conf/init_calibre_db_ldap_settings))) WHERE ID=1\""
eval sqlite3 $final_path/app.db "$conf"
#Update Imagick policy as per https://github.com/janeczku/calibre-web/wiki/FAQ#what-to-do-if-cover-pictures-are-not-extracted-from-pdf-files #Update Imagick policy as per https://github.com/janeczku/calibre-web/wiki/FAQ#what-to-do-if-cover-pictures-are-not-extracted-from-pdf-files
ynh_script_progression --message="Update Imagick policy..." --weight=1
ynh_replace_string --match_string="<policy domain="coder" rights="none" pattern="PDF" />" \ ynh_replace_string --match_string="<policy domain="coder" rights="none" pattern="PDF" />" \
--replace_string="<policy domain="coder" rights="read" pattern="PDF" />" \ --replace_string="<policy domain="coder" rights="read" pattern="PDF" />" \
--target_file="/etc/ImageMagick-6/policy.xml" --target_file="/etc/ImageMagick-6/policy.xml"
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum "$final_path/app.db"
#================================================= #=================================================
# SETUP LOGROTATE # SETUP LOGROTATE