diff --git a/.project b/.project deleted file mode 100644 index 0675d93..0000000 --- a/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - calibre_ynh - - - - - - org.python.pydev.PyDevBuilder - - - - - - org.python.pydev.pythonNature - - diff --git a/conf/app.src b/conf/app.src index 862bfcc..6dc434a 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,3 +1,3 @@ -SOURCE_URL=https://github.com/janeczku/calibre-web/archive/06fde4fcd00fcd067a58939e1d9eabee62a86913.zip -SOURCE_SUM=81aa6e95837569e9ebdb6da73529d8cbb33dfde65fd07a384ae6cc79dcfe5afa +SOURCE_URL=https://github.com/janeczku/calibre-web/archive/0297823bda98de2dcfecf7fb5d3a612938f88ea3.zip +SOURCE_SUM=776fbee7906217f70ea1f84e0ce467a2a793750b4890f460add96e22e1bc253e SOURCE_FORMAT=zip diff --git a/scripts/_common.sh b/scripts/_common.sh index c694803..9b6ac98 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,19 +1,10 @@ #!/bin/bash -get_db() { - # $1 = nom de la table - # cette ligne de malade : - # 1/ Recupere le schém de la table user - # 2/ En extrait les noms de champs (en prenant le premier mot après la tabulation) - # 3/ en supprime les clé UNIQUE, PRIMARY et CHECK dont on ne veut pas - # 4/ remplace la liste avec retour à la ligne par une liste séparé par des virgules - # 5/ Enlève la dernière virgule - sqlite3 $final_path/app.db ".schema $1" | awk '/\t/ {print $1}' | grep -v -e "UNIQUE" -e "PRIMARY" -e "CHECK" -e "FOREIGN" | awk '{printf "%s, ", $0}' | head -c -2 -} - -version_gt() { - test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"; -} +PKG_DEPENDENCIES="sqlite3 python-dev libldap2-dev libsasl2-dev libssl-dev python3-pip imagemagick" +#PKG_DEPENDENCIES="sqlite3 python3-pip imagemagick" +DOSSIER_MEDIA=/home/yunohost.multimedia +LOG_FILE=/var/log/$app/$app.log +ACCESS_LOG_FILE=/var/log/$app/$app-access.log #================================================= diff --git a/scripts/_settings.sh b/scripts/_settings.sh deleted file mode 100644 index 9cc863e..0000000 --- a/scripts/_settings.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -PKG_DEPENDENCIES="sqlite3 python-dev libldap2-dev libsasl2-dev libssl-dev python3-pip imagemagick" -DOSSIER_MEDIA=/home/yunohost.multimedia -LOG_FILE=/var/log/$app/$app.log -ACCESS_LOG_FILE=/var/log/$app/$app-access.log \ No newline at end of file diff --git a/scripts/backup b/scripts/backup index 4f57ae1..bfd842f 100755 --- a/scripts/backup +++ b/scripts/backup @@ -6,7 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= -source ../settings/scripts/_common.sh + source /usr/share/yunohost/helpers #================================================= @@ -19,9 +19,9 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --time --weight=1 -app=$YNH_APP_INSTANCE_NAME +ynh_script_progression --message="Loading installation settings..." --weight=1 +app=$YNH_APP_INSTANCE_NAME final_path=$(ynh_app_setting_get $app final_path) path_url=$(ynh_app_setting_get $app path) domain=$(ynh_app_setting_get $app domain) @@ -32,6 +32,7 @@ calibre_dir=$(sqlite3 $final_path/app.db "SELECT config_calibre_dir FROM setting calibre_dir=${calibre_dir%/} ynh_app_setting_set $app calibre_dir $calibre_dir +source ../settings/scripts/_common.sh #================================================= @@ -39,7 +40,7 @@ ynh_app_setting_set $app calibre_dir $calibre_dir #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --time --weight=1 +ynh_script_progression --message="Stopping a systemd service..." --weight=1 ynh_systemd_action --service_name=$app --action="stop" @@ -48,7 +49,7 @@ ynh_systemd_action --service_name=$app --action="stop" # BACKUP THE APP MAIN DIR #================================================= -ynh_script_progression --message="Backing up the main app directory..." --time --weight=1 +ynh_script_progression --message="Backing up the main app directory..." --weight=1 #This will backup the app.db file at the same time ynh_backup --src_path="$final_path" @@ -56,7 +57,7 @@ ynh_backup --src_path="$final_path" # BACKUP THE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Backing up nginx web server configuration..." --time --weight=1 +ynh_script_progression --message="Backing up nginx web server configuration..." --weight=1 ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" @@ -66,13 +67,13 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # BACKUP LOGROTATE #================================================= -ynh_script_progression --message="Backing up logrotate configuration..." --time --weight=1 +ynh_script_progression --message="Backing up logrotate configuration..." --weight=1 ynh_backup --src_path="/etc/logrotate.d/$app" #================================================= # BACKUP SYSTEMD #================================================= -ynh_script_progression --message="Backing up systemd configuration..." --time --weight=1 +ynh_script_progression --message="Backing up systemd configuration..." --weight=1 ynh_backup --src_path="/etc/systemd/system/$app.service" @@ -87,12 +88,13 @@ ynh_backup --src_path="$calibre_dir" --is_big #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --time --weight=1 +ynh_script_progression --message="Starting a systemd service..." --weight=5 -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name=$app --action="start" -t 20 +sleep 2s #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --time --last \ No newline at end of file +ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --last \ No newline at end of file diff --git a/scripts/change_url b/scripts/change_url index 1afabc0..d813374 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -6,7 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= -source _common.sh + source /usr/share/yunohost/helpers #================================================= @@ -26,6 +26,7 @@ ynh_script_progression --message="Loading installation settings..." --weight=1 # Needed for helper "ynh_add_nginx_config" final_path=$(ynh_app_setting_get $app final_path) port=$(ynh_app_setting_get $app port) +source _common.sh #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP @@ -116,9 +117,10 @@ fi #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 +ynh_script_progression --message="Starting a systemd service..." --weight=2 -ynh_systemd_action --service_name=$app --action="start" -l "Starting Tornado server on :8083" -t 20 +ynh_systemd_action --service_name=$app --action="start" -t 20 +sleep 2s #================================================= # RELOAD NGINX #================================================= diff --git a/scripts/install b/scripts/install index 830ae51..735547d 100755 --- a/scripts/install +++ b/scripts/install @@ -6,16 +6,8 @@ # IMPORT GENERIC HELPERS #================================================= -source _common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= @@ -32,7 +24,19 @@ public_library=$7 if [ $is_public -eq 1 ]; then public_library=1 fi -source _settings.sh +source _common.sh + + + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors #================================================= @@ -229,7 +233,8 @@ fi #================================================= ynh_script_progression --message="Reload nginx and start $app..." --weight=5 ynh_systemd_action --service_name=nginx --action=reload -ynh_systemd_action -l "Starting Tornado server on :8083" -t 20 +ynh_systemd_action --service_name=$app --action=start -t 20 +sleep 2s #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index 68341c0..33e2e6b 100755 --- a/scripts/remove +++ b/scripts/remove @@ -6,7 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= -source _common.sh + source /usr/share/yunohost/helpers #================================================= @@ -20,6 +20,8 @@ port=$(ynh_app_setting_get $app port) final_path=$(ynh_app_setting_get $app final_path) calibre_dir=$(ynh_app_setting_get $app calibre_dir) +source _common.sh + #================================================= # REMOVE SERVICE FROM ADMIN PANEL #================================================= diff --git a/scripts/restore b/scripts/restore index 9600b95..46b2922 100755 --- a/scripts/restore +++ b/scripts/restore @@ -6,7 +6,6 @@ # IMPORT GENERIC HELPERS #================================================= -source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers #================================================= @@ -19,7 +18,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading settings..." --time --weight=1 +ynh_script_progression --message="Loading settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) @@ -28,12 +27,12 @@ final_path=$(ynh_app_setting_get $app final_path) calibre_dir=$(ynh_app_setting_get $app calibre_dir) is_public=$(ynh_app_setting_get $app is_public) port=$(ynh_app_setting_get $app port) -source ../settings/scripts/_settings.sh +source ../settings/scripts/_common.sh #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= -ynh_script_progression --message="Validating restoration parameters..." --time --weight=1 +ynh_script_progression --message="Validating restoration parameters..." --weight=1 ynh_webpath_available $domain $path_url \ || ynh_die "Path not available: ${domain}${path_url}" test ! -d $final_path \ @@ -44,7 +43,7 @@ test ! -d $final_path \ #================================================= # RESTORE THE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Restoring nginx configuration..." --time --weight=1 +ynh_script_progression --message="Restoring nginx configuration..." --weight=1 ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= @@ -59,7 +58,7 @@ ynh_app_setting_set $app port $port # RECREATE THE DEDICATED USER #================================================= -ynh_script_progression --message="Recreating the dedicated system user..." --time --weight=1 +ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 # Create the dedicated user (if not existing) ynh_system_user_create --username=$app @@ -67,7 +66,7 @@ ynh_system_user_create --username=$app #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring the app main directory..." --time --weight=1 +ynh_script_progression --message="Restoring the app main directory..." --weight=1 ynh_restore_file --origin_path="$final_path" @@ -85,7 +84,7 @@ chown -R $app: $final_path #================================================= # Define and install dependencies -ynh_script_progression --message="Reinstalling dependencies..." --time --weight=1 +ynh_script_progression --message="Reinstalling dependencies..." --weight=15 ynh_install_app_dependencies $PKG_DEPENDENCIES #pip package not required as already in app directory #pip install --target $final_path/vendor -r $final_path/requirements.txt @@ -93,7 +92,7 @@ ynh_install_app_dependencies $PKG_DEPENDENCIES #================================================= # RESTORE SYSTEMD #================================================= -ynh_script_progression --message="Restoring the systemd configuration..." --time --weight=1 +ynh_script_progression --message="Restoring the systemd configuration..." --weight=1 ynh_restore_file --origin_path="/etc/systemd/system/$app.service" systemctl enable $app.service @@ -153,21 +152,22 @@ fi #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." --time --weight=1 +ynh_script_progression --message="Reloading nginx web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --time --weight=1 +ynh_script_progression --message="Starting a systemd service..." --weight=2 -ynh_systemd_action --service_name=$app --action="start" -l "Starting Tornado server on :8083" -t 20 +ynh_systemd_action --service_name=$app --action="start" -t 20 +sleep 2s #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed for $app" --time --last +ynh_script_progression --message="Restoration completed for $app" --last #================================================= # WARNING FOR READ ACCESS #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index d92fcef..d49abd9 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,12 +1,15 @@ #!/bin/bash +version_gt() { + test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"; +} + #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= -source _common.sh source /usr/share/yunohost/helpers #================================================= @@ -23,7 +26,6 @@ is_public=$(ynh_app_setting_get $app is_public) final_path=$(ynh_app_setting_get $app final_path) language=$(ynh_app_setting_get $app language) - #Get settings from database in case it has been changed in the app and save it in settings so that it can be used back afterward calibre_dir=$(sqlite3 $final_path/app.db "SELECT config_calibre_dir FROM settings WHERE ID=1") calibre_dir=${calibre_dir%/} @@ -32,7 +34,7 @@ ynh_app_setting_set $app calibre_dir $calibre_dir upload=$(sqlite3 $final_path/app.db "SELECT config_uploading FROM settings WHERE ID=1") ynh_app_setting_set $app upload $upload -source _settings.sh +source _common.sh #================================================= # CHECK VERSION @@ -137,7 +139,7 @@ fi #================================================= # Create a dedicated user (if not existing) -ynh_script_progression --message="Making sure dedicated system user exists..." --time --weight=1 +ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 ynh_system_user_create $app # Set permissions on app files (required to be able to update database) @@ -148,7 +150,7 @@ chown -R $app: $final_path #================================================= #build multimedia directory #================================================= -ynh_script_progression --message="Create Multimedia dir..." --time --weight=1 +ynh_script_progression --message="Create Multimedia dir..." --weight=1 #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_addaccess $app @@ -156,7 +158,7 @@ ynh_multimedia_addaccess $app #================================================= #Update database structure #================================================= -ynh_script_progression --message="Update database..." --time --weight=1 +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" @@ -178,7 +180,7 @@ ynh_store_file_checksum "$final_path/app.db" #================================================= # Use logrotate to manage app-specific logfile(s) -ynh_script_progression --message="Upgrading logrotate configuration..." --time --weight=1 +ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1 ynh_use_logrotate --non-append @@ -187,7 +189,7 @@ ynh_use_logrotate --non-append #================================================= # Create a dedicated systemd config -ynh_script_progression --message="Upgrading systemd configuration..." --time --weight=1 +ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 ynh_add_systemd_config #================================================= @@ -222,18 +224,19 @@ fi #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." --time --weight=1 +ynh_script_progression --message="Reloading nginx web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --time --weight=1 +ynh_script_progression --message="Starting a systemd service..." --weight=2 -ynh_systemd_action --service_name=$app --action="start" -l "Starting Tornado server on :8083" -t 20 +ynh_systemd_action --service_name=$app --action="start" -t 20 +sleep 2s #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --time --last +ynh_script_progression --message="Upgrade of $app completed" --last diff --git a/sources/patches/app-web.patch b/sources/patches/app-web.patch index a4e1866..492d5e2 100644 --- a/sources/patches/app-web.patch +++ b/sources/patches/app-web.patch @@ -1,30 +1,52 @@ ---- a/cps/web.py 2020-04-18 11:48:34.000000000 +0200 -+++ b/cps/web.py 2020-04-19 13:42:18.719536869 +0200 -@@ -1206,6 +1206,13 @@ +--- a/cps/web.py 2020-05-01 13:54:41.755888435 +0200 ++++ b/cps/web.py" 2020-05-01 14:03:01.337768210 +0200 +@@ -281,6 +281,10 @@ + if not config.db_configured and request.endpoint not in ( + 'admin.basic_configuration', 'login') and '/static/' not in request.path: + return redirect(url_for('admin.basic_configuration')) ++#Début Modif Yunohost 1/4 ++ if config.config_login_type == constants.LOGIN_LDAP and services.ldap: ++ import_ldap_users() ++#Fin Modif Yunohost 1/4 + + + @app.route('/import_ldap_users') +@@ -313,7 +317,10 @@ + log.warning("Could Not Parse LDAP User: %s", user) + continue + if ub.session.query(ub.User).filter(ub.User.nickname == user.lower()).first(): +- log.warning("LDAP User: %s Already in Database", user) ++# Début Modif Yunohost 2/4 ++# log.warning("LDAP User: %s Already in Database", user) ++ log.debug("LDAP User: %s Already in Database", user) ++#Fin Modif Yunohost 2/4 + continue + user_data = services.ldap.get_object_details(user=user, + group=None, +@@ -1216,6 +1223,10 @@ if not config.db_configured: log.debug(u"Redirect to initial configuration") return redirect(url_for('admin.basic_configuration')) ++#Début Modif Yunohost 3/4 + if config.config_login_type == constants.LOGIN_LDAP and services.ldap: + import_ldap_users() -+ auth_user = request.headers.get('X-Remote-User') -+ if auth_user: -+ user = ub.session.query(ub.User).filter(func.lower(ub.User.nickname) == auth_user.strip().lower()).first() -+ log.info("Login of user %s", user.nickname) -+ login_user(user) ++#Fin Modif Yunohost 3/4 if current_user is not None and current_user.is_authenticated: return redirect(url_for('web.index')) if config.config_login_type == constants.LOGIN_LDAP and not services.ldap: -@@ -1284,8 +1291,11 @@ - logout_user() +@@ -1290,8 +1301,13 @@ if feature_support['oauth'] and (config.config_login_type == 2 or config.config_login_type == 3): logout_oauth_user() -- log.debug(u"User logged out") + log.debug(u"User logged out") - return redirect(url_for('web.login')) -+ auth_user = request.headers.get('X-Remote-User') -+ if auth_user: +- ++#Début Modif Yunohost 4/4 ++# return redirect(url_for('web.login')) ++ if config.config_login_type == constants.LOGIN_LDAP and services.ldap: + return redirect(request.host_url) + else: + return redirect(url_for('web.login')) - ++#Fin Modif Yunohost 4/4 @web.route('/remote/login') + @remote_login_required