From 36502f3dec57b1667690dbf789def6050068a3f5 Mon Sep 17 00:00:00 2001 From: Krakinou Date: Wed, 27 Feb 2019 22:58:27 +0100 Subject: [PATCH 01/18] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 6e11a54..87bb001 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ chmod o+rw path/to/library * Do not use a Nextcloud folder. It's all right if the folder is an external storage in Nextcloud but not if it's an internal one : Changing the data in the library will cause trouble with the sync * "Magic link feature is not yet available * Change to library made outside calibreweb are not automatically updated in calibreweb. It is required to disconnect and reconnect to see the changes +* OPDS is not yet working ## Links @@ -82,6 +83,7 @@ sudo yunohost app upgrade calibreweb -u https://github.com/Yunohost-Apps/calibre - [X] On backup/remove/upgrade : check for database location to update settings - [ ] enable magic link - [ ] Add cronjob to reload database +- [ ] OPDS activation ## LICENSE From 156f03fbc13e3ea2a32786a540be6ba193ea350d Mon Sep 17 00:00:00 2001 From: Krakinou Date: Tue, 29 Oct 2019 09:42:24 +0100 Subject: [PATCH 02/18] Better Description as per #20 --- manifest.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manifest.json b/manifest.json index f68076e..0c1fe88 100644 --- a/manifest.json +++ b/manifest.json @@ -3,8 +3,8 @@ "id": "calibreweb", "packaging_format": 1, "description": { - "en": "Calibre-web for Yunohost", - "fr": "Calibre-web pour Yunohost" + "en": "Clean interface for browsing, reading and downloading eBooks", + "fr": "Interface simplifié pour parcourir, lire et charger des eBooks" }, "version": "0.96.0~ynh3", "url": "https://github.com/janeczku/calibre-web", From 342bec25af256e982b9f84ae26f42b9715e93595 Mon Sep 17 00:00:00 2001 From: Krakinou Date: Tue, 29 Oct 2019 09:44:40 +0100 Subject: [PATCH 03/18] Update description from #19 --- manifest.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manifest.json b/manifest.json index 0c1fe88..3c0ebb7 100644 --- a/manifest.json +++ b/manifest.json @@ -3,8 +3,8 @@ "id": "calibreweb", "packaging_format": 1, "description": { - "en": "Clean interface for browsing, reading and downloading eBooks", - "fr": "Interface simplifié pour parcourir, lire et charger des eBooks" + "en": "Browsing, reading and downloading eBooks using a Calibre database", + "fr": "Explorer, lire et télécharger des eBooks à partir d'une base de données Calibre" }, "version": "0.96.0~ynh3", "url": "https://github.com/janeczku/calibre-web", From 9b36148e767a20f530f1dc987a246cb350222123 Mon Sep 17 00:00:00 2001 From: Krakinou Date: Sun, 12 Apr 2020 13:46:13 +0200 Subject: [PATCH 04/18] Initial commit to 0.6.6 --- README.md | 2 +- conf/app.src | 6 +- conf/init_calibre_db_ldap_settings | 12 +++- manifest.json | 4 +- scripts/install | 1 + sources/patches/app-admin.patch | 11 +++ sources/patches/app-config.patch | 24 ------- sources/patches/app-ub.patch | 103 ----------------------------- sources/patches/app-web.patch | 94 +++----------------------- 9 files changed, 37 insertions(+), 220 deletions(-) create mode 100644 sources/patches/app-admin.patch delete mode 100644 sources/patches/app-config.patch delete mode 100644 sources/patches/app-ub.patch diff --git a/README.md b/README.md index 87bb001..41c45f4 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ sudo yunohost app upgrade calibreweb -u https://github.com/Yunohost-Apps/calibre ## Todo - [X] Multiinstance - [X] Better Multimedia integration : Integrate in Yunohost.multimedia -- [X] User and possibly LDAP integration, http auth +- [ ] rework LDAP integration to create user automatically - [X] Package_check integration - [X] On backup/remove/upgrade : check for database location to update settings - [ ] enable magic link diff --git a/conf/app.src b/conf/app.src index a7a76d1..355f00c 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,3 +1,3 @@ -SOURCE_URL=https://github.com/janeczku/calibre-web/archive/d81cb2927abcba3c4d198ecce9dca78550f676e1.zip -SOURCE_SUM=e9c8a9a63ceb509f8482d73ed6d044eca8e96961c485fd395e73e93b8ea09a68 -SOURCE_FORMAT=zip \ No newline at end of file +SOURCE_URL=https://github.com/janeczku/calibre-web/archive/7c89f0b5b97678c8b93a484ee7e5acf746240938.zip +SOURCE_SUM=7127c42c2573d85a56da41ea705944a724742e9059a6c138de9cfd78424cce88 +SOURCE_FORMAT=zip diff --git a/conf/init_calibre_db_ldap_settings b/conf/init_calibre_db_ldap_settings index d16c8e9..6652c9f 100644 --- a/conf/init_calibre_db_ldap_settings +++ b/conf/init_calibre_db_ldap_settings @@ -1,3 +1,9 @@ -config_use_ldap=1, -config_ldap_provider_url=\'localhost:389\', -config_ldap_dn=\'uid=%s,ou=users,dc=yunohost,dc=org\' \ No newline at end of file +config_login_type=1, +config_ldap_provider_url=\'localhost\', +config_ldap_port=389, +config_ldap_schema=\'ldap\', +config_ldap_serv_username=\'toto\', +config_ldap_serv_password=\'titi\', +config_ldap_dn=\'ou=users,dc=yunohost,dc=org\', +config_ldap_user_object=\'uid=%s\', +config_ldap_openldap=1 \ No newline at end of file diff --git a/manifest.json b/manifest.json index 3c0ebb7..043e31f 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Browsing, reading and downloading eBooks using a Calibre database", "fr": "Explorer, lire et télécharger des eBooks à partir d'une base de données Calibre" }, - "version": "0.96.0~ynh3", + "version": "0.96.6~ynh4", "url": "https://github.com/janeczku/calibre-web", "license": "free", "maintainer": { @@ -14,7 +14,7 @@ "email": "misterl56@hotmail.com" }, "requirements": { - "yunohost": ">= 3.0.0" + "yunohost": ">= 3.7.1" }, "multi_instance": true, "services": [ diff --git a/scripts/install b/scripts/install index 7aebc70..adbc154 100755 --- a/scripts/install +++ b/scripts/install @@ -87,6 +87,7 @@ ynh_setup_source "$final_path" ynh_print_info "Installing dependencies and pip packages" ynh_install_app_dependencies $PKG_DEPENDENCIES pip install --target $final_path/vendor -r $final_path/requirements.txt +pip install --target $final_path/vendor -r $final_path/optional-requirements.txt #================================================= # NGINX CONFIGURATION diff --git a/sources/patches/app-admin.patch b/sources/patches/app-admin.patch new file mode 100644 index 0000000..32dc2a4 --- /dev/null +++ b/sources/patches/app-admin.patch @@ -0,0 +1,11 @@ +--- a/cps/admin.py 2020-04-12 12:51:28.100811662 +0200 ++++ b/cps/admin.py 2020-02-23 09:08:01.000000000 +0100 +@@ -43,7 +43,7 @@ + from .web import admin_required, render_title_template, before_request, unconfigured, login_required_if_no_ano + + feature_support = { +- 'ldap': bool(services.ldap), ++ 'ldap': False, # bool(services.ldap), + 'goodreads': bool(services.goodreads_support) + } + \ No newline at end of file diff --git a/sources/patches/app-config.patch b/sources/patches/app-config.patch deleted file mode 100644 index c816372..0000000 --- a/sources/patches/app-config.patch +++ /dev/null @@ -1,24 +0,0 @@ ---- a/cps/templates/config_edit.html 2019-01-12 09:01:08.000000000 +0100 -+++ b/cps/templates/config_edit.html 2019-01-13 11:21:11.000000000 +0100 -@@ -162,6 +162,21 @@ - - - {% endif %} -+
-+ -+ -+
-+
-+
-+ -+ -+
-+
-+ -+ -+
-+
-+ - - - diff --git a/sources/patches/app-ub.patch b/sources/patches/app-ub.patch deleted file mode 100644 index 16f7494..0000000 --- a/sources/patches/app-ub.patch +++ /dev/null @@ -1,103 +0,0 @@ ---- a/cps/ub.py 2019-01-16 17:50:51.000000000 +0100 -+++ b/cps/ub.py 2019-01-30 22:23:29.709075421 +0100 -@@ -148,6 +148,16 @@ - def __repr__(self): - return '' % self.nickname - -+#Yunohost Integration - 1 -+ #Login via LDAP method -+ @staticmethod -+ def try_login(username, password): -+ conn = get_ldap_connection() -+ conn.simple_bind_s( -+ config.config_ldap_dn.replace("%s", username), -+ password -+ ) -+#END Yunohost Integration - 1 - - # Baseclass for Users in Calibre-Web, settings which are depending on certain users are stored here. It is derived from - # User Base (all access methods are declared there) -@@ -268,8 +278,8 @@ - domain = Column(String) - - def __repr__(self): -- return u"".format(self.domain) -- -+ return u"".format(self.domain) -+ - - # Baseclass for representing settings in app.db with email server settings and Calibre database settings - # (application settings) -@@ -306,6 +316,11 @@ - config_use_goodreads = Column(Boolean) - config_goodreads_api_key = Column(String) - config_goodreads_api_secret = Column(String) -+#Yunohost Integration - 2 -+ config_use_ldap = Column(Boolean) -+ config_ldap_provider_url = Column(String) -+ config_ldap_dn = Column(String) -+#END Yunohost Integration - 2 - config_mature_content_tags = Column(String) - config_logfile = Column(String) - config_ebookconverter = Column(Integer, default=0) -@@ -379,6 +394,11 @@ - self.config_use_goodreads = data.config_use_goodreads - self.config_goodreads_api_key = data.config_goodreads_api_key - self.config_goodreads_api_secret = data.config_goodreads_api_secret -+#Yunohost Integration - 3 -+ self.config_use_ldap = data.config_use_ldap -+ self.config_ldap_provider_url = data.config_ldap_provider_url -+ self.config_ldap_dn = data.config_ldap_dn -+#END Yunohost Integration - 3 - if data.config_mature_content_tags: - self.config_mature_content_tags = data.config_mature_content_tags - else: -@@ -555,7 +575,7 @@ - conn.execute("ALTER TABLE Settings ADD column `config_use_google_drive` INTEGER DEFAULT 0") - conn.execute("ALTER TABLE Settings ADD column `config_google_drive_folder` String DEFAULT ''") - conn.execute("ALTER TABLE Settings ADD column `config_google_drive_watch_changes_response` String DEFAULT ''") -- session.commit() -+ session.commit() - try: - session.query(exists().where(Settings.config_columns_to_ignore)).scalar() - except exc.OperationalError: -@@ -624,6 +644,16 @@ - conn.execute("ALTER TABLE Settings ADD column `config_goodreads_api_key` String DEFAULT ''") - conn.execute("ALTER TABLE Settings ADD column `config_goodreads_api_secret` String DEFAULT ''") - try: -+#Yunohost Integration - 4 -+ session.query(exists().where(Settings.config_use_ldap)).scalar() -+ except exc.OperationalError: -+ conn = engine.connect() -+ conn.execute("ALTER TABLE Settings ADD column `config_use_ldap` INTEGER DEFAULT 0") -+ conn.execute("ALTER TABLE Settings ADD column `config_ldap_provider_url` String DEFAULT ''") -+ conn.execute("ALTER TABLE Settings ADD column `config_ldap_dn` String DEFAULT ''") -+ session.commit() -+ try: -+#END Yunohost Integration - 4 - session.query(exists().where(Settings.config_mature_content_tags)).scalar() - except exc.OperationalError: - conn = engine.connect() -@@ -668,7 +698,6 @@ - conn.execute("ALTER TABLE Settings ADD column `config_theme` INTEGER DEFAULT 0") - session.commit() - -- - # Remove login capability of user Guest - conn = engine.connect() - conn.execute("UPDATE user SET password='' where nickname = 'Guest' and password !=''") -@@ -778,6 +807,14 @@ - migrate_Database() - clean_database() - -+#Yunohost Integration - 5 -+#get LDAP connection -+def get_ldap_connection(): -+ import ldap -+ conn = ldap.initialize('ldap://{}'.format(config.config_ldap_provider_url)) -+ return conn -+#END Yunohost Integration - 5 -+ - # Generate global Settings Object accessible from every file - config = Config() - searched_ids = {} diff --git a/sources/patches/app-web.patch b/sources/patches/app-web.patch index c1e03e0..e529dd4 100644 --- a/sources/patches/app-web.patch +++ b/sources/patches/app-web.patch @@ -1,85 +1,11 @@ ---- a/cps/web.py 2019-01-27 08:32:26.000000000 +0100 -+++ b/cps/web.py 2019-02-02 12:38:12.364323004 +0100 -@@ -78,6 +78,9 @@ - import server - from reverseproxy import ReverseProxied - from updater import updater_thread -+#Yunohost LDAP integration - 1 -+vlogout = 0 -+#END Yunohost LDAP integration -1 +--- a/cps/web.py 2020-04-12 12:52:23.940774100 +0200 ++++ b/cps/web.py 2020-02-23 09:08:01.000000000 +0100 +@@ -53,7 +53,7 @@ + from .redirect import redirect_back - try: - from googleapiclient.errors import HttpError -@@ -2256,10 +2259,36 @@ - return redirect(url_for('basic_configuration')) - if current_user is not None and current_user.is_authenticated: - return redirect(url_for('index')) -+#Yunohost integration - 2 -+ auth_user = request.headers.get('X-Remote-User') -+ global vlogout -+ if auth_user and config.config_use_ldap and not vlogout: -+ vlogout = 0 -+ user = ub.session.query(ub.User).filter(func.lower(ub.User.nickname) == auth_user.strip().lower()).first() -+ login_user(user, remember=True) -+ flash(_(u"you are now logged in as: '%(nickname)s'", nickname=user.nickname), category="success") -+ return redirect(url_for("index")) -+#END Yunohost integration - 2 - if request.method == "POST": - form = request.form.to_dict() - user = ub.session.query(ub.User).filter(func.lower(ub.User.nickname) == form['username'].strip().lower()).first() -- if user and check_password_hash(user.password, form['password']) and user.nickname is not "Guest": -+#Yunohost integration - 3 -+# if user and check_password_hash(user.password, form['password']) and user.nickname is not "Guest": -+#END Yunohost integration - 3 -+#Yunohost Integration - 4 -+ if config.config_use_ldap and user: -+ import ldap -+ try: -+ ub.User.try_login(form['username'], form['password']) -+ login_user(user, remember=True) -+ flash(_(u"you are now logged in as: '%(nickname)s'", nickname=user.nickname), category="success") -+ return redirect_back(url_for("index")) -+ except ldap.INVALID_CREDENTIALS: -+ ipAdress = request.headers.get('X-Forwarded-For', request.remote_addr) -+ app.logger.info('LDAP Login failed for user "' + form['username'] + '" IP-adress: ' + ipAdress) -+ flash(_(u"Wrong Username or Password"), category="error") -+ elif user and check_password_hash(user.password, form['password']) and user.nickname is not "Guest": -+#End Yunohost Integration - 4 - login_user(user, remember=True) - flash(_(u"you are now logged in as: '%(nickname)s'", nickname=user.nickname), category="success") - return redirect_back(url_for("index")) -@@ -2280,6 +2309,10 @@ - @login_required - def logout(): - if current_user is not None and current_user.is_authenticated: -+#Yunohost Integration - 5 -+ global vlogout -+ vlogout = 1 -+#End Yunohost integration - 5 - logout_user() - return redirect(url_for('login')) - -@@ -2987,6 +3020,23 @@ - if "config_ebookconverter" in to_save: - content.config_ebookconverter = int(to_save["config_ebookconverter"]) - -+#Yunohost Integration - 6 -+ #LDAP configuration, -+ if "config_use_ldap" in to_save and to_save["config_use_ldap"] == "on": -+ if not "config_ldap_provider_url" in to_save or not "config_ldap_dn" in to_save: -+ ub.session.commit() -+ flash(_(u'Please enter a LDAP provider and a DN'), category="error") -+ return render_title_template("config_edit.html", content=config, origin=origin, -+ gdrive=gdriveutils.gdrive_support, gdriveError=gdriveError, -+ goodreads=goodreads_support, title=_(u"Basic Configuration"), -+ page="config") -+ else: -+ content.config_use_ldap = 1 -+ content.config_ldap_provider_url = to_save["config_ldap_provider_url"] -+ content.config_ldap_dn = to_save["config_ldap_dn"] -+ db_change = True -+#END Yunohost integration - 6 -+ - # Remote login configuration - content.config_remote_login = ("config_remote_login" in to_save and to_save["config_remote_login"] == "on") - if not content.config_remote_login: + feature_support = { +- 'ldap': bool(services.ldap), ++ 'ldap': False, # bool(services.ldap), + 'goodreads': bool(services.goodreads_support) + } + \ No newline at end of file From 67df4298963e43449c4b90a7e0022c5c7d58c8c8 Mon Sep 17 00:00:00 2001 From: Krakinou Date: Sun, 12 Apr 2020 14:02:28 +0200 Subject: [PATCH 05/18] Patch upside down --- sources/patches/app-admin.patch | 8 ++++---- sources/patches/app-web.patch | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sources/patches/app-admin.patch b/sources/patches/app-admin.patch index 32dc2a4..8486e78 100644 --- a/sources/patches/app-admin.patch +++ b/sources/patches/app-admin.patch @@ -1,11 +1,11 @@ ---- a/cps/admin.py 2020-04-12 12:51:28.100811662 +0200 -+++ b/cps/admin.py 2020-02-23 09:08:01.000000000 +0100 +--- a/cps/admin.py 2020-02-23 09:08:01.000000000 +0100 ++++ b/cps/admin.py 2020-04-12 12:51:28.100811662 +0200 @@ -43,7 +43,7 @@ from .web import admin_required, render_title_template, before_request, unconfigured, login_required_if_no_ano feature_support = { -- 'ldap': bool(services.ldap), -+ 'ldap': False, # bool(services.ldap), +- 'ldap': False, # bool(services.ldap), ++ 'ldap': bool(services.ldap), 'goodreads': bool(services.goodreads_support) } \ No newline at end of file diff --git a/sources/patches/app-web.patch b/sources/patches/app-web.patch index e529dd4..fe45177 100644 --- a/sources/patches/app-web.patch +++ b/sources/patches/app-web.patch @@ -1,11 +1,11 @@ ---- a/cps/web.py 2020-04-12 12:52:23.940774100 +0200 -+++ b/cps/web.py 2020-02-23 09:08:01.000000000 +0100 +--- a/cps/web.py 2020-02-23 09:08:01.000000000 +0100 ++++ b/cps/web.py 2020-04-12 12:52:23.940774100 +0200 @@ -53,7 +53,7 @@ from .redirect import redirect_back feature_support = { -- 'ldap': bool(services.ldap), -+ 'ldap': False, # bool(services.ldap), +- 'ldap': False, # bool(services.ldap), ++ 'ldap': bool(services.ldap), 'goodreads': bool(services.goodreads_support) } \ No newline at end of file From 90297a89101a28fe5e130fd67d35913b801a85f8 Mon Sep 17 00:00:00 2001 From: Krakinou Date: Sun, 12 Apr 2020 14:24:18 +0200 Subject: [PATCH 06/18] New log files --- conf/init_calibre_db_settings | 5 ++++- conf/systemd.service | 2 +- scripts/install | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/conf/init_calibre_db_settings b/conf/init_calibre_db_settings index b54e177..2853f5d 100644 --- a/conf/init_calibre_db_settings +++ b/conf/init_calibre_db_settings @@ -8,4 +8,7 @@ config_use_goodreads=0, config_logfile=\'\', config_converterpath=\'\', config_calibre=\'\', -config_uploading=\'$upload\', +config_logfile=\'/var/log/calibreweb/calibreweb.log\', +config_access_log=1, +config_access_logfile=\'/var/log/calibreweb/calibreweb-access.log\', +config_uploading=\'$upload\' \ No newline at end of file diff --git a/conf/systemd.service b/conf/systemd.service index 2fbfa40..4b60a68 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -7,7 +7,7 @@ Type=simple User=__APP__ Group=__APP__ WorkingDirectory=__FINALPATH__/ -ExecStart=/bin/sh -c '/usr/bin/python __FINALPATH__/cps.py >> /var/log/__APP__/__APP__.log 2>&1' +ExecStart=/bin/sh -c '/usr/bin/python __FINALPATH__/cps.py' [Install] WantedBy=multi-user.target diff --git a/scripts/install b/scripts/install index adbc154..91c7b31 100755 --- a/scripts/install +++ b/scripts/install @@ -254,4 +254,4 @@ fi #================================================= ynh_print_info "Reload nginx and start $app" systemctl reload nginx -ynh_systemd_action -l "INFO in server: Starting Gevent server" +ynh_systemd_action From 0f7ae5b41d587529da86d00c5567857044ea06d3 Mon Sep 17 00:00:00 2001 From: Krakinou Date: Mon, 13 Apr 2020 12:28:59 +0200 Subject: [PATCH 07/18] Update to Python3.5 --- conf/init_calibre_db_ldap_settings | 4 +- conf/init_calibre_db_settings | 4 +- conf/systemd.service | 2 +- scripts/_common.sh | 82 ------------------- scripts/_settings.sh | 7 ++ scripts/install | 17 ++-- scripts/restore | 3 +- scripts/upgrade | 12 +-- .../patches/app-optional-requirements.patch | 37 +++++++++ 9 files changed, 69 insertions(+), 99 deletions(-) create mode 100644 scripts/_settings.sh create mode 100644 sources/patches/app-optional-requirements.patch diff --git a/conf/init_calibre_db_ldap_settings b/conf/init_calibre_db_ldap_settings index 6652c9f..b0f6871 100644 --- a/conf/init_calibre_db_ldap_settings +++ b/conf/init_calibre_db_ldap_settings @@ -2,8 +2,8 @@ config_login_type=1, config_ldap_provider_url=\'localhost\', config_ldap_port=389, config_ldap_schema=\'ldap\', -config_ldap_serv_username=\'toto\', -config_ldap_serv_password=\'titi\', +config_ldap_serv_username=\'nicolas\', +config_ldap_serv_password=\'eXVub2hvc3RfZGV2\', config_ldap_dn=\'ou=users,dc=yunohost,dc=org\', config_ldap_user_object=\'uid=%s\', config_ldap_openldap=1 \ No newline at end of file diff --git a/conf/init_calibre_db_settings b/conf/init_calibre_db_settings index 2853f5d..24690a0 100644 --- a/conf/init_calibre_db_settings +++ b/conf/init_calibre_db_settings @@ -8,7 +8,7 @@ config_use_goodreads=0, config_logfile=\'\', config_converterpath=\'\', config_calibre=\'\', -config_logfile=\'/var/log/calibreweb/calibreweb.log\', +config_logfile=\'$LOG_FILE\', config_access_log=1, -config_access_logfile=\'/var/log/calibreweb/calibreweb-access.log\', +config_access_logfile=\'$ACCESS_LOG_FILE\', config_uploading=\'$upload\' \ No newline at end of file diff --git a/conf/systemd.service b/conf/systemd.service index 4b60a68..d166c60 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -7,7 +7,7 @@ Type=simple User=__APP__ Group=__APP__ WorkingDirectory=__FINALPATH__/ -ExecStart=/bin/sh -c '/usr/bin/python __FINALPATH__/cps.py' +ExecStart=/bin/sh -c '/usr/bin/python3.5 __FINALPATH__/cps.py' [Install] WantedBy=multi-user.target diff --git a/scripts/_common.sh b/scripts/_common.sh index 6d2551a..349ee53 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,9 +1,5 @@ #!/bin/bash -PKG_DEPENDENCIES="sqlite3 python-pip imagemagick" -DOSSIER_MEDIA=/home/yunohost.multimedia -create_dir=0 - get_db() { # $1 = nom de la table # cette ligne de malade : @@ -20,84 +16,6 @@ get_db() { # TO BE DELETED WHEN RELEASED #================================================= -#================================================= -#YNH_SYSTEMD_ACTION -#================================================= - -# Start (or other actions) a service, print a log in case of failure and optionnaly wait until the service is completely started -# -# usage: ynh_system_reload service_name [action] -# | arg: -n, --service_name= - Name of the service to reload. Default : $app -# | arg: -a, --action= - Action to perform with systemctl. Default: start -# | arg: -l, --line_match= - Line to match - The line to find in the log to attest the service have finished to boot. -# If not defined it don't wait until the service is completely started. -# | arg: -p, --log_path= - Log file - Path to the log file. Default : /var/log/$app/$app.log -# | arg: -t, --timeout= - Timeout - The maximum time to wait before ending the watching. Default : 300 seconds. -# | arg: -e, --length= - Length of the error log : Default : 20 -ynh_systemd_action() { - # Declare an array to define the options of this helper. - declare -Ar args_array=( [n]=service_name= [a]=action= [l]=line_match= [p]=log_path= [t]=timeout= [e]=length= ) - local service_name - local action - local line_match - local length - local log_path - local timeout - - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - - local service_name="${service_name:-$app}" - local action=${action:-start} - local log_path="${log_path:-/var/log/$service_name/$service_name.log}" - local length=${length:-20} - local timeout=${timeout:-300} - local wait_starting=true - - if [[ -z "${line_match:-}" ]] - then - wait_starting=false - fi - - ynh_clean_check_starting () { - # Stop the execution of tail. - kill -s 15 $pid_tail 2>&1 - ynh_secure_remove "$templog" 2>&1 - } - - echo "Starting of $service_name" >&2 - systemctl $action $service_name || ( journalctl --lines=$length -u $service_name >&2 && false) - - if $wait_starting - then - # Following the starting of the app in its log - local templog="$(mktemp)" - tail -F -n1 "$log_path" > "$templog" & - # Get the PID of the tail command - local pid_tail=$! - - local i=0 - for i in $(seq 1 $timeout) - do - # Read the log until the sentence is found, that means the app finished to start. Or run until the timeout - if grep --quiet "$line_match" "$templog" - then - echo "The service $service_name has correctly started." >&2 - break - fi - echo -n "." >&2 - sleep 1 - done - if [ $i -eq $timeout ] - then - echo "The service $service_name didn't fully started before the timeout." >&2 - journalctl --lines=$length -u $service_name >&2 - fi - - echo "" - ynh_clean_check_starting - fi -} #================================================= diff --git a/scripts/_settings.sh b/scripts/_settings.sh new file mode 100644 index 0000000..79faedc --- /dev/null +++ b/scripts/_settings.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +PKG_DEPENDENCIES="sqlite3 python3-pip imagemagick" +DOSSIER_MEDIA=/home/yunohost.multimedia +create_dir=0 +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/install b/scripts/install index 91c7b31..f91a11b 100755 --- a/scripts/install +++ b/scripts/install @@ -32,6 +32,8 @@ public_library=$7 if [ $is_public -eq 1 ]; then public_library=1 fi +source _settings.sh + #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS @@ -86,8 +88,8 @@ ynh_setup_source "$final_path" ynh_print_info "Installing dependencies and pip packages" ynh_install_app_dependencies $PKG_DEPENDENCIES -pip install --target $final_path/vendor -r $final_path/requirements.txt -pip install --target $final_path/vendor -r $final_path/optional-requirements.txt +pip3 install --no-cache-dir --target $final_path/vendor -r $final_path/requirements.txt +pip3 install --no-cache-dir --upgrade --target $final_path/vendor -r $final_path/optional-requirements.txt #================================================= # NGINX CONFIGURATION @@ -162,15 +164,17 @@ chown -R $app:$app /var/log/$app ynh_print_info "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 -ynh_systemd_action -l "INFO in server: Starting Gevent server" +ynh_systemd_action #sleep required on low spec like raspberryPi -sleep 2s +sleep 5s ynh_systemd_action -a stop #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\"" +#insertion of dummy value for config_ldap_serv_username and config_ldap_serv_password : required for calibreweb and simpleldap but not +#required by Yunohost ldap. +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" conf="\"UPDATE user SET $(. <(echo -E echo $(<../conf/init_calibre_db_user))) WHERE ID=1\"" @@ -241,7 +245,8 @@ yunohost service add $app --log "/var/log/$app/$app.log" if [ $is_public -eq 1 ] then # unprotected_uris allows SSO credentials to be passed anyway. - ynh_app_setting_set $app unprotected_uris "/" + #ynh_app_setting_set $app unprotected_uris "/" + ynh_permission_update --permission "main" --add visitors fi if [ $public_library -eq 0 ]; then yunohost app addaccess $app -u $admin diff --git a/scripts/restore b/scripts/restore index 4f9c05f..c1ea009 100755 --- a/scripts/restore +++ b/scripts/restore @@ -89,7 +89,8 @@ chown -R $app: $final_path # Define and install dependencies ynh_print_info "Installing dependencies and pip packages" ynh_install_app_dependencies $PKG_DEPENDENCIES -pip install --target $final_path/vendor -r $final_path/requirements.txt +#pip package not required as already in app directory +#pip install --target $final_path/vendor -r $final_path/requirements.txt #================================================= # ADVERTISE SERVICE IN ADMIN PANEL diff --git a/scripts/upgrade b/scripts/upgrade index 0c037a6..243e4ce 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -80,7 +80,8 @@ ynh_add_nginx_config #================================================= ynh_print_info "Download and install dependencies" ynh_install_app_dependencies $PKG_DEPENDENCIES -pip install --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 #================================================= # CREATE DEDICATED USER @@ -111,9 +112,9 @@ ynh_multimedia_addaccess $app 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 settings -ynh_systemd_action -l "INFO in server: Starting Gevent server" +ynh_systemd_action #sleep required on low spec like raspberryPi -sleep 2s +sleep 5s ynh_systemd_action -a stop conf="\"UPDATE settings SET $(. <(echo -E echo $(<../conf/init_calibre_db_ldap_settings))) WHERE ID=1\"" @@ -153,7 +154,8 @@ chown -R $app: $final_path if [ $is_public -eq 1 ] then # unprotected_uris allows SSO credentials to be passed anyway - ynh_app_setting_set $app unprotected_uris "/" + #ynh_app_setting_set $app unprotected_uris "/" + ynh_permission_update --permission "main" --add visitors fi #================================================= @@ -169,4 +171,4 @@ fi #================================================= systemctl reload nginx -ynh_systemd_action -a restart -l "INFO in server: Starting Gevent server" +ynh_systemd_action -a restart diff --git a/sources/patches/app-optional-requirements.patch b/sources/patches/app-optional-requirements.patch new file mode 100644 index 0000000..1088286 --- /dev/null +++ b/sources/patches/app-optional-requirements.patch @@ -0,0 +1,37 @@ +--- a/optional-requirements.txt 2020-02-23 09:08:01.000000000 +0100 ++++ b/optional-requirements.txt 2020-04-13 10:50:30.317525119 +0200 +@@ -1,34 +1,3 @@ +-# GDrive Integration +-google-api-python-client==1.7.11,<1.8.0 +-gevent>=1.2.1,<1.5.0 +-greenlet>=0.4.12,<0.5.0 +-httplib2>=0.9.2,<0.18.0 +-oauth2client>=4.0.0,<4.14.0 +-uritemplate>=3.0.0,<3.1.0 +-pyasn1-modules>=0.0.8,<0.3.0 +-pyasn1>=0.1.9,<0.5.0 +-PyDrive>=1.3.1,<1.14.0 +-PyYAML>=3.12 +-rsa==3.4.2,<4.1.0 +-six>=1.10.0,<1.14.0 +- +-# goodreads +-goodreads>=0.3.2,<0.4.0 +-python-Levenshtein>=0.12.0,<0.13.0 +- + # ldap login + python_ldap>=3.0.0,<3.3.0 + flask-simpleldap>1.3.0,<1.5.0 +- +-#oauth +-flask-dance>=0.13.0 +-sqlalchemy_utils>=0.33.5,<0.37.0 +- +-# extracting metadata +-lxml>=3.8.0,<4.6.0 +-Pillow>=4.0.0,<7.1.0 +-rarfile>=2.7 +- +-# other +-natsort>=2.2.0,<7.1.0 +-git+https://github.com/OzzieIsaacs/comicapi.git@ad8bfe5a1c31db882480433f86db2c5c57634a3f#egg=comicapi From 03c5ec75db8d0eefa66cd33a24532d933575d7b8 Mon Sep 17 00:00:00 2001 From: Krakinou Date: Mon, 13 Apr 2020 19:29:12 +0200 Subject: [PATCH 08/18] Change simpleldap username --- conf/init_calibre_db_ldap_settings | 2 +- sources/patches/app-simpleldap.patch | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 sources/patches/app-simpleldap.patch diff --git a/conf/init_calibre_db_ldap_settings b/conf/init_calibre_db_ldap_settings index b0f6871..edba7e3 100644 --- a/conf/init_calibre_db_ldap_settings +++ b/conf/init_calibre_db_ldap_settings @@ -2,7 +2,7 @@ config_login_type=1, config_ldap_provider_url=\'localhost\', config_ldap_port=389, config_ldap_schema=\'ldap\', -config_ldap_serv_username=\'nicolas\', +config_ldap_serv_username=\'cn=admin,dc=yunohost,dc=org\', config_ldap_serv_password=\'eXVub2hvc3RfZGV2\', config_ldap_dn=\'ou=users,dc=yunohost,dc=org\', config_ldap_user_object=\'uid=%s\', diff --git a/sources/patches/app-simpleldap.patch b/sources/patches/app-simpleldap.patch new file mode 100644 index 0000000..cbf869a --- /dev/null +++ b/sources/patches/app-simpleldap.patch @@ -0,0 +1,12 @@ +--- a/cps/services/simpleldap.py 2020-02-23 09:08:01.000000000 +0100 ++++ b/cps/services/simpleldap.py 2020-04-13 18:57:49.302535092 +0200 +@@ -35,8 +35,7 @@ + app.config['LDAP_HOST'] = config.config_ldap_provider_url + app.config['LDAP_PORT'] = config.config_ldap_port + app.config['LDAP_SCHEMA'] = config.config_ldap_schema +- app.config['LDAP_USERNAME'] = config.config_ldap_user_object.replace('%s', config.config_ldap_serv_username)\ +- + ',' + config.config_ldap_dn ++ app.config['LDAP_USERNAME'] = config.config_ldap_serv_username + app.config['LDAP_PASSWORD'] = base64.b64decode(config.config_ldap_serv_password) + app.config['LDAP_REQUIRE_CERT'] = bool(config.config_ldap_require_cert) + if config.config_ldap_require_cert: From a1965181f72c8c2a66f166b8ea637ea2e4e84c35 Mon Sep 17 00:00:00 2001 From: Krakinou Date: Wed, 15 Apr 2020 23:42:26 +0200 Subject: [PATCH 09/18] Update users settings --- conf/init_calibre_db_ldap_settings | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/conf/init_calibre_db_ldap_settings b/conf/init_calibre_db_ldap_settings index edba7e3..101bc15 100644 --- a/conf/init_calibre_db_ldap_settings +++ b/conf/init_calibre_db_ldap_settings @@ -4,6 +4,9 @@ config_ldap_port=389, config_ldap_schema=\'ldap\', config_ldap_serv_username=\'cn=admin,dc=yunohost,dc=org\', config_ldap_serv_password=\'eXVub2hvc3RfZGV2\', -config_ldap_dn=\'ou=users,dc=yunohost,dc=org\', -config_ldap_user_object=\'uid=%s\', -config_ldap_openldap=1 \ No newline at end of file +config_ldap_dn=\'dc=yunohost,dc=org\', +config_ldap_user_object=\'\(\&\(objectClass=posixAccount\)\(uid=%s\)\)\', +config_ldap_openldap=1, +config_ldap_group_object_filter='\(\&\(objectClass=posixGroup\)\(permission=cn=%s.main,ou=permission,dc=yunohost,dc=org\)\)', +config_ldap_group_members_field='memberUid', +config_ldap_group_name='calibreweb' \ No newline at end of file From b2731a37d14eb525799209d299d58b4d74fa881b Mon Sep 17 00:00:00 2001 From: Krakinou Date: Sat, 18 Apr 2020 12:35:56 +0200 Subject: [PATCH 10/18] Init commit 0.6.7Beta --- conf/app.src | 4 +- conf/init_calibre_db_ldap_settings | 12 ++--- manifest.json | 2 +- scripts/install | 51 +++++++++---------- sources/patches/app-admin.patch | 11 ---- .../patches/app-optional-requirements.patch | 37 -------------- sources/patches/app-simpleldap.patch | 12 ----- sources/patches/app-web.patch | 11 ---- 8 files changed, 33 insertions(+), 107 deletions(-) delete mode 100644 sources/patches/app-admin.patch delete mode 100644 sources/patches/app-optional-requirements.patch delete mode 100644 sources/patches/app-simpleldap.patch delete mode 100644 sources/patches/app-web.patch diff --git a/conf/app.src b/conf/app.src index 355f00c..862bfcc 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,3 +1,3 @@ -SOURCE_URL=https://github.com/janeczku/calibre-web/archive/7c89f0b5b97678c8b93a484ee7e5acf746240938.zip -SOURCE_SUM=7127c42c2573d85a56da41ea705944a724742e9059a6c138de9cfd78424cce88 +SOURCE_URL=https://github.com/janeczku/calibre-web/archive/06fde4fcd00fcd067a58939e1d9eabee62a86913.zip +SOURCE_SUM=81aa6e95837569e9ebdb6da73529d8cbb33dfde65fd07a384ae6cc79dcfe5afa SOURCE_FORMAT=zip diff --git a/conf/init_calibre_db_ldap_settings b/conf/init_calibre_db_ldap_settings index 101bc15..6c01f4d 100644 --- a/conf/init_calibre_db_ldap_settings +++ b/conf/init_calibre_db_ldap_settings @@ -1,12 +1,10 @@ config_login_type=1, config_ldap_provider_url=\'localhost\', config_ldap_port=389, -config_ldap_schema=\'ldap\', -config_ldap_serv_username=\'cn=admin,dc=yunohost,dc=org\', -config_ldap_serv_password=\'eXVub2hvc3RfZGV2\', +config_ldap_authentication=0, config_ldap_dn=\'dc=yunohost,dc=org\', -config_ldap_user_object=\'\(\&\(objectClass=posixAccount\)\(uid=%s\)\)\', +config_ldap_user_object=\'\(\&\(objectClass=posixAccount\)\(permission=cn=calibreweb.main,ou=permission,dc=yunohost,dc=org\)\(uid=%s\)\)\', config_ldap_openldap=1, -config_ldap_group_object_filter='\(\&\(objectClass=posixGroup\)\(permission=cn=%s.main,ou=permission,dc=yunohost,dc=org\)\)', -config_ldap_group_members_field='memberUid', -config_ldap_group_name='calibreweb' \ No newline at end of file +config_ldap_group_object_filter=\'\(\&\(objectClass=posixGroup\)\(permission=cn=%s.main,ou=permission,dc=yunohost,dc=org\)\)\', +config_ldap_group_members_field=\'memberUid\', +config_ldap_group_name=\'calibreweb\' \ No newline at end of file diff --git a/manifest.json b/manifest.json index 043e31f..f8c7a2a 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Browsing, reading and downloading eBooks using a Calibre database", "fr": "Explorer, lire et télécharger des eBooks à partir d'une base de données Calibre" }, - "version": "0.96.6~ynh4", + "version": "0.96.7beta~ynh4", "url": "https://github.com/janeczku/calibre-web", "license": "free", "maintainer": { diff --git a/scripts/install b/scripts/install index f91a11b..1cd1332 100755 --- a/scripts/install +++ b/scripts/install @@ -172,8 +172,6 @@ ynh_systemd_action -a stop #set database settings as per conf file -#insertion of dummy value for config_ldap_serv_username and config_ldap_serv_password : required for calibreweb and simpleldap but not -#required by Yunohost ldap. 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" @@ -188,31 +186,32 @@ eval sqlite3 $final_path/app.db "$conf" #ynh_print_ON #Creation des autres utilisateurs -if [ $public_library -eq 1 ]; then - table_schema=$(get_db "user") +#Disabled => Will be handled by LDAP +#if [ $public_library -eq 1 ]; then +# table_schema=$(get_db "user") - for i in $(ynh_user_list); do - if [ $i = $admin ]; then continue; fi - mail=$(ynh_user_get_info $i 'mail') - ###################################### - #Build new entry for user - ###################################### - insert_user=$table_schema - insert_user="${insert_user/id/null}" #so that a new entry is created - insert_user="${insert_user/nickname/\'$i\'}" - insert_user="${insert_user/role/0}" #standard role - # pass_hash=$(python /etc/yunohost/apps/$app/conf/generate_password_hash.py "$pass_clear" $final_path/vendor) - # insert_user="${insert_user/password/\'$pass_hash\'}" #we get the same pass even if it's not thanks to LDAP, ones never knows... - insert_user="${insert_user/email/\'$mail\'}" - - ####################################### - # Insert New entry in database - ####################################### - - sqlite3 $final_path/app.db "INSERT INTO user ($table_schema) SELECT $insert_user FROM user WHERE ID = 1;" - - done -fi +# for i in $(ynh_user_list); do +# if [ $i = $admin ]; then continue; fi +# mail=$(ynh_user_get_info $i 'mail') +# ###################################### +# #Build new entry for user +# ###################################### +# insert_user=$table_schema +# insert_user="${insert_user/id/null}" #so that a new entry is created +# insert_user="${insert_user/nickname/\'$i\'}" +# insert_user="${insert_user/role/0}" #standard role +# # pass_hash=$(python /etc/yunohost/apps/$app/conf/generate_password_hash.py "$pass_clear" $final_path/vendor) +# # insert_user="${insert_user/password/\'$pass_hash\'}" #we get the same pass even if it's not thanks to LDAP, ones never knows... +# insert_user="${insert_user/email/\'$mail\'}" +# +# ####################################### +# # Insert New entry in database +# ####################################### +# +# sqlite3 $final_path/app.db "INSERT INTO user ($table_schema) SELECT $insert_user FROM user WHERE ID = 1;" +# +# done +#fi #================================================= # SECURE FILES AND DIRECTORIES diff --git a/sources/patches/app-admin.patch b/sources/patches/app-admin.patch deleted file mode 100644 index 8486e78..0000000 --- a/sources/patches/app-admin.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- a/cps/admin.py 2020-02-23 09:08:01.000000000 +0100 -+++ b/cps/admin.py 2020-04-12 12:51:28.100811662 +0200 -@@ -43,7 +43,7 @@ - from .web import admin_required, render_title_template, before_request, unconfigured, login_required_if_no_ano - - feature_support = { -- 'ldap': False, # bool(services.ldap), -+ 'ldap': bool(services.ldap), - 'goodreads': bool(services.goodreads_support) - } - \ No newline at end of file diff --git a/sources/patches/app-optional-requirements.patch b/sources/patches/app-optional-requirements.patch deleted file mode 100644 index 1088286..0000000 --- a/sources/patches/app-optional-requirements.patch +++ /dev/null @@ -1,37 +0,0 @@ ---- a/optional-requirements.txt 2020-02-23 09:08:01.000000000 +0100 -+++ b/optional-requirements.txt 2020-04-13 10:50:30.317525119 +0200 -@@ -1,34 +1,3 @@ --# GDrive Integration --google-api-python-client==1.7.11,<1.8.0 --gevent>=1.2.1,<1.5.0 --greenlet>=0.4.12,<0.5.0 --httplib2>=0.9.2,<0.18.0 --oauth2client>=4.0.0,<4.14.0 --uritemplate>=3.0.0,<3.1.0 --pyasn1-modules>=0.0.8,<0.3.0 --pyasn1>=0.1.9,<0.5.0 --PyDrive>=1.3.1,<1.14.0 --PyYAML>=3.12 --rsa==3.4.2,<4.1.0 --six>=1.10.0,<1.14.0 -- --# goodreads --goodreads>=0.3.2,<0.4.0 --python-Levenshtein>=0.12.0,<0.13.0 -- - # ldap login - python_ldap>=3.0.0,<3.3.0 - flask-simpleldap>1.3.0,<1.5.0 -- --#oauth --flask-dance>=0.13.0 --sqlalchemy_utils>=0.33.5,<0.37.0 -- --# extracting metadata --lxml>=3.8.0,<4.6.0 --Pillow>=4.0.0,<7.1.0 --rarfile>=2.7 -- --# other --natsort>=2.2.0,<7.1.0 --git+https://github.com/OzzieIsaacs/comicapi.git@ad8bfe5a1c31db882480433f86db2c5c57634a3f#egg=comicapi diff --git a/sources/patches/app-simpleldap.patch b/sources/patches/app-simpleldap.patch deleted file mode 100644 index cbf869a..0000000 --- a/sources/patches/app-simpleldap.patch +++ /dev/null @@ -1,12 +0,0 @@ ---- a/cps/services/simpleldap.py 2020-02-23 09:08:01.000000000 +0100 -+++ b/cps/services/simpleldap.py 2020-04-13 18:57:49.302535092 +0200 -@@ -35,8 +35,7 @@ - app.config['LDAP_HOST'] = config.config_ldap_provider_url - app.config['LDAP_PORT'] = config.config_ldap_port - app.config['LDAP_SCHEMA'] = config.config_ldap_schema -- app.config['LDAP_USERNAME'] = config.config_ldap_user_object.replace('%s', config.config_ldap_serv_username)\ -- + ',' + config.config_ldap_dn -+ app.config['LDAP_USERNAME'] = config.config_ldap_serv_username - app.config['LDAP_PASSWORD'] = base64.b64decode(config.config_ldap_serv_password) - app.config['LDAP_REQUIRE_CERT'] = bool(config.config_ldap_require_cert) - if config.config_ldap_require_cert: diff --git a/sources/patches/app-web.patch b/sources/patches/app-web.patch deleted file mode 100644 index fe45177..0000000 --- a/sources/patches/app-web.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- a/cps/web.py 2020-02-23 09:08:01.000000000 +0100 -+++ b/cps/web.py 2020-04-12 12:52:23.940774100 +0200 -@@ -53,7 +53,7 @@ - from .redirect import redirect_back - - feature_support = { -- 'ldap': False, # bool(services.ldap), -+ 'ldap': bool(services.ldap), - 'goodreads': bool(services.goodreads_support) - } - \ No newline at end of file From 8410a5658d55e34c584667af4b3c5436e63af99d Mon Sep 17 00:00:00 2001 From: Krakinou Date: Sat, 18 Apr 2020 18:46:22 +0200 Subject: [PATCH 11/18] Import LDAP user --- .project | 6 +++ conf/generate_password_hash.py | 10 ---- hooks/post_user_create | 49 ------------------- scripts/_common.sh | 2 - scripts/install | 35 ------------- sources/patches/app-admin.html.patch | 11 +++++ sources/patches/app-main.js.patch | 12 +++++ .../patches/app-optionnal-requirements.patch | 40 +++++++++++++++ sources/patches/app-web.patch | 10 ++++ 9 files changed, 79 insertions(+), 96 deletions(-) delete mode 100644 conf/generate_password_hash.py delete mode 100644 hooks/post_user_create create mode 100644 sources/patches/app-admin.html.patch create mode 100644 sources/patches/app-main.js.patch create mode 100644 sources/patches/app-optionnal-requirements.patch create mode 100644 sources/patches/app-web.patch diff --git a/.project b/.project index 18e8b1c..0675d93 100644 --- a/.project +++ b/.project @@ -5,7 +5,13 @@ + + org.python.pydev.PyDevBuilder + + + + org.python.pydev.pythonNature diff --git a/conf/generate_password_hash.py b/conf/generate_password_hash.py deleted file mode 100644 index 4778e8c..0000000 --- a/conf/generate_password_hash.py +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# Permet de générer le hash pour le password -#Plus utilisé depuis la MAJ 0.92~ynh3 avec LDAP -import sys -path=sys.argv[2] -sys.path.append(path) -from werkzeug.security import generate_password_hash -password=sys.argv[1] -print generate_password_hash(password) diff --git a/hooks/post_user_create b/hooks/post_user_create deleted file mode 100644 index e3a7820..0000000 --- a/hooks/post_user_create +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash - -# Source YunoHost helpers -source /usr/share/yunohost/helpers - -#pour récupérer l'app_id, on prend le nom du fichier puis on retire les 3 premiers caratères -app=`basename "$0"` -app=${app:3} -source /etc/yunohost/apps/$app/scripts/_common.sh - - -username=$1 -mail=$2 -pass_clear=$3 -final_path=$(ynh_app_setting_get $app final_path) - -public_library=$(ynh_app_setting_get "$app" public_library) -#User are duplicated in the database only if library is public -if [ $public_library -eq 1 ]; then - ###################################### - #1 get admin user and id from database - ###################################### - #we take the admin user as we're sure there is at least this one - - admin=$(ynh_app_setting_get $app admin) - admin_id=$(sqlite3 $final_path/app.db "SELECT id FROM user WHERE nickname='$admin'") - - ###################################### - #get user table structure - ###################################### - table_schema=$(get_db "user") - - ###################################### - #Build new entry for user - ###################################### - insert_user=$table_schema - insert_user="${insert_user/id/null}" #so that a new entry is created - insert_user="${insert_user/nickname/\'$username\'}" - insert_user="${insert_user/role/0}" #standard role - pass_hash=$(python /etc/yunohost/apps/$app/conf/generate_password_hash.py "$pass_clear" $final_path/vendor) - insert_user="${insert_user/password/\'$pass_hash\'}" #we get the same pass even if it's not thanks to LDAP, ones never knows... - insert_user="${insert_user/email/\'$mail\'}" - - ####################################### - # Insert New entry in database - ####################################### - - sqlite3 $final_path/app.db "INSERT INTO user ($table_schema) SELECT $insert_user FROM user WHERE ID = $admin_id;" -fi \ No newline at end of file diff --git a/scripts/_common.sh b/scripts/_common.sh index 349ee53..9946035 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -16,8 +16,6 @@ get_db() { # TO BE DELETED WHEN RELEASED #================================================= - - #================================================= #YNH_MULTIMEDIA #================================================= diff --git a/scripts/install b/scripts/install index 1cd1332..88f1f77 100755 --- a/scripts/install +++ b/scripts/install @@ -178,41 +178,6 @@ eval sqlite3 $final_path/app.db "$conf" conf="\"UPDATE user SET $(. <(echo -E echo $(<../conf/init_calibre_db_user))) WHERE ID=1\"" eval sqlite3 $final_path/app.db "$conf" -#mise à jour du mot de passe (je ne sais pas pourquoi, je n'arrive pas à l'intégrer dans le fichier de conf, pb de " et ') -#ynh_print_OFF -#had to set it on two lines or package_linter cries like a baby... -#pass=$(python ../conf/generate_password_hash.py "$pass" $final_path/vendor) -#sqlite3 $final_path/app.db "UPDATE user SET password='$pass' WHERE ID=1" -#ynh_print_ON - -#Creation des autres utilisateurs -#Disabled => Will be handled by LDAP -#if [ $public_library -eq 1 ]; then -# table_schema=$(get_db "user") - -# for i in $(ynh_user_list); do -# if [ $i = $admin ]; then continue; fi -# mail=$(ynh_user_get_info $i 'mail') -# ###################################### -# #Build new entry for user -# ###################################### -# insert_user=$table_schema -# insert_user="${insert_user/id/null}" #so that a new entry is created -# insert_user="${insert_user/nickname/\'$i\'}" -# insert_user="${insert_user/role/0}" #standard role -# # pass_hash=$(python /etc/yunohost/apps/$app/conf/generate_password_hash.py "$pass_clear" $final_path/vendor) -# # insert_user="${insert_user/password/\'$pass_hash\'}" #we get the same pass even if it's not thanks to LDAP, ones never knows... -# insert_user="${insert_user/email/\'$mail\'}" -# -# ####################################### -# # Insert New entry in database -# ####################################### -# -# sqlite3 $final_path/app.db "INSERT INTO user ($table_schema) SELECT $insert_user FROM user WHERE ID = 1;" -# -# done -#fi - #================================================= # SECURE FILES AND DIRECTORIES #================================================= diff --git a/sources/patches/app-admin.html.patch b/sources/patches/app-admin.html.patch new file mode 100644 index 0000000..fffa7d0 --- /dev/null +++ b/sources/patches/app-admin.html.patch @@ -0,0 +1,11 @@ +--- /home/nicolas/Bureau/calibre-web-06fde4fcd00fcd067a58939e1d9eabee62a86913/cps/templates/admin.html 2020-04-18 11:48:34.000000000 +0200 ++++ ./admin.html 2020-04-18 18:21:39.272422475 +0200 +@@ -149,8 +149,6 @@ + + + +-
{{_('Check for Update')}}
+- + + + diff --git a/sources/patches/app-main.js.patch b/sources/patches/app-main.js.patch new file mode 100644 index 0000000..909cd60 --- /dev/null +++ b/sources/patches/app-main.js.patch @@ -0,0 +1,12 @@ +--- a/cps/static/js/main.js 2020-04-18 11:48:34.000000000 +0200 ++++ b/cps/static/js/main.js 2020-04-18 17:39:49.405631791 +0200 +@@ -308,7 +308,8 @@ + $.ajax({ + method:"get", + dataType: "json", +- url: path + "/../../import_ldap_users", ++ url: window.location.pathname + "/../../import_ldap_users", ++// url: path + "/../../import_ldap_users", + success: function success(data) { + $("#spinner2").hide(); + ResultText = data.text; diff --git a/sources/patches/app-optionnal-requirements.patch b/sources/patches/app-optionnal-requirements.patch new file mode 100644 index 0000000..02f49d2 --- /dev/null +++ b/sources/patches/app-optionnal-requirements.patch @@ -0,0 +1,40 @@ +--- a/optional-requirements.txt 2020-04-15 22:03:21.000000000 +0200 ++++ b/optional-requirements.txt 2020-04-16 20:44:43.371235411 +0200 +@@ -1,17 +1,3 @@ +-# GDrive Integration +-google-api-python-client==1.7.11,<1.8.0 +-gevent>=1.2.1,<1.6.0 +-greenlet>=0.4.12,<0.5.0 +-httplib2>=0.9.2,<0.18.0 +-oauth2client>=4.0.0,<4.14.0 +-uritemplate>=3.0.0,<3.1.0 +-pyasn1-modules>=0.0.8,<0.3.0 +-pyasn1>=0.1.9,<0.5.0 +-PyDrive>=1.3.1,<1.4.0 +-PyYAML>=3.12 +-rsa==3.4.2,<4.1.0 +-six>=1.10.0,<1.15.0 +- + # goodreads + goodreads>=0.3.2,<0.4.0 + python-Levenshtein>=0.12.0,<0.13.0 +@@ -20,19 +6,11 @@ + python_ldap>=3.0.0,<3.3.0 + flask-simpleldap>=1.4.0,<1.5.0 + +-#oauth +-flask-dance>=1.4.0,<3.1.0 +-sqlalchemy_utils>=0.33.5,<0.37.0 +- + # extracting metadata + lxml>=3.8.0,<4.6.0 + Pillow>=4.0.0,<7.2.0 + rarfile>=2.7 + +-# other +-natsort>=2.2.0,<7.1.0 +-git+https://github.com/OzzieIsaacs/comicapi.git@ad8bfe5a1c31db882480433f86db2c5c57634a3f#egg=comicapi +- + #Kobo integration + jsonschema>=3.2.0,<3.3.0 + diff --git a/sources/patches/app-web.patch b/sources/patches/app-web.patch new file mode 100644 index 0000000..0f1202c --- /dev/null +++ b/sources/patches/app-web.patch @@ -0,0 +1,10 @@ +--- /home/nicolas/Bureau/calibre-web-06fde4fcd00fcd067a58939e1d9eabee62a86913/cps/web.py 2020-04-18 11:48:34.000000000 +0200 ++++ ./web.py 2020-04-18 18:13:44.221590991 +0200 +@@ -1216,6 +1216,7 @@ + user = ub.session.query(ub.User).filter(func.lower(ub.User.nickname) == form['username'].strip().lower()) \ + .first() + if config.config_login_type == constants.LOGIN_LDAP and services.ldap and user and form['password'] != "": ++ import_ldap_user() + login_result, error = services.ldap.bind_user(form['username'], form['password']) + if login_result: + login_user(user, remember=True) From 125e62ab0c04e73d3d36076de621c7a31b13f083 Mon Sep 17 00:00:00 2001 From: Krakinou Date: Sun, 19 Apr 2020 14:28:25 +0200 Subject: [PATCH 12/18] First SSO and progression --- .pydevproject | 5 ++++ scripts/install | 21 +++++++++------ scripts/remove | 12 ++++----- sources/patches/app-admin.html.patch | 4 +-- sources/patches/app-web.patch | 40 +++++++++++++++++++++------- 5 files changed, 56 insertions(+), 26 deletions(-) create mode 100644 .pydevproject diff --git a/.pydevproject b/.pydevproject new file mode 100644 index 0000000..d001f0a --- /dev/null +++ b/.pydevproject @@ -0,0 +1,5 @@ + + +Default +python interpreter + diff --git a/scripts/install b/scripts/install index 88f1f77..7402d81 100755 --- a/scripts/install +++ b/scripts/install @@ -38,6 +38,7 @@ source _settings.sh #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= +ynh_script_progression -t --message="Validating installation parameters..." final_path=/var/www/$app test ! -e "$final_path" || ynh_die "This path already contains a folder" @@ -53,6 +54,7 @@ ynh_webpath_register $app $domain $path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= +ynh_script_progression -t --message="Storing installation settings..." ynh_app_setting_set $app domain $domain ynh_app_setting_set $app path $path_url @@ -69,32 +71,36 @@ ynh_app_setting_set $app is_public $is_public # Find a free port port=$(ynh_find_port 8083) # Open this port -ynh_print_info "Opening port $port" +ynh_script_progression -t --message="Opening port $port..." --weight=5 yunohost firewall allow --no-upnp TCP $port 2>&1 ynh_app_setting_set $app port $port #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= - +ynh_script_progression -t --message="Downloading sources to $final_path..." --weight=10 ynh_app_setting_set $app final_path $final_path -ynh_print_info "Downloading sources to $final_path" # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source "$final_path" #================================================= # INSTALL DEPENDENCIES #================================================= +ynh_script_progression -t --message="Installing dependencies..." --weight=15 -ynh_print_info "Installing dependencies and pip packages" ynh_install_app_dependencies $PKG_DEPENDENCIES +ynh_script_progression -t --message="Installing dependencies..." --weight=15 pip3 install --no-cache-dir --target $final_path/vendor -r $final_path/requirements.txt +ynh_script_progression -t --message="Installing dependencies..." --weight=40 pip3 install --no-cache-dir --upgrade --target $final_path/vendor -r $final_path/optional-requirements.txt #================================================= # NGINX CONFIGURATION #================================================= #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 + + if [ $path_url = "/" ] ; then ynh_replace_string " proxy_set_header X-Script-Name" "# proxy_set_header X-Script-Name" ../conf/nginx.conf fi @@ -121,7 +127,7 @@ ynh_add_systemd_config #================================================= # CREATE FILES AND DIRECTORIES #================================================= -ynh_print_info "Creating files and directory" +ynh_script_progression -t --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 # 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. @@ -161,8 +167,7 @@ chown -R $app:$app /var/log/$app #================================================= # SET SQLITE DATABASE SETTINGS #================================================= - -ynh_print_info "Setting up database and settings" +ynh_script_progression -t --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 ynh_systemd_action @@ -221,6 +226,6 @@ fi #================================================= # RELOAD NGINX #================================================= -ynh_print_info "Reload nginx and start $app" +ynh_script_progression -t -l --message="Reload nginx and start $app..." systemctl reload nginx ynh_systemd_action diff --git a/scripts/remove b/scripts/remove index 63bfe68..568285e 100755 --- a/scripts/remove +++ b/scripts/remove @@ -37,7 +37,7 @@ fi #================================================= # Remove the dedicated systemd config -ynh_print_info "Removing systemd" +ynh_script_progression -t --message="Removing systemd..." ynh_remove_systemd_config @@ -47,7 +47,7 @@ ynh_remove_systemd_config #================================================= # Remove metapackage and its dependencies -ynh_print_info "Removing dependencies" +ynh_script_progression -t --message="Removing Dependencies..." ynh_remove_app_dependencies @@ -56,7 +56,7 @@ ynh_remove_app_dependencies #================================================= # Remove the app directory securely -ynh_print_info "Removing $final_path" +ynh_script_progression -t --message="Removing $final_path..." ynh_secure_remove "$final_path" #================================================= @@ -64,7 +64,7 @@ ynh_secure_remove "$final_path" #================================================= # Remove the dedicated nginx config -ynh_print_info "Removing nginx config" +ynh_script_progression -t --message="Removing Nginx Config..." ynh_remove_nginx_config #================================================= @@ -80,14 +80,14 @@ ynh_remove_logrotate if yunohost firewall list | grep -q "\- $port$" then - ynh_print_info "Removing open port $port" - echo "Close port $port" >&2 + ynh_script_progression -t --message="Closing port $port..." yunohost firewall disallow TCP $port 2>&1 fi #================================================= # SPECIFIC REMOVE #================================================= +ynh_script_progression -t --message="Removing log and user $app..." # Remove the log files ynh_secure_remove "/var/log/$app/" diff --git a/sources/patches/app-admin.html.patch b/sources/patches/app-admin.html.patch index fffa7d0..1f3449c 100644 --- a/sources/patches/app-admin.html.patch +++ b/sources/patches/app-admin.html.patch @@ -1,5 +1,5 @@ ---- /home/nicolas/Bureau/calibre-web-06fde4fcd00fcd067a58939e1d9eabee62a86913/cps/templates/admin.html 2020-04-18 11:48:34.000000000 +0200 -+++ ./admin.html 2020-04-18 18:21:39.272422475 +0200 +--- a/cps/templates/admin.html 2020-04-18 11:48:34.000000000 +0200 ++++ b/cps/templates/admin.html 2020-04-18 18:21:39.272422475 +0200 @@ -149,8 +149,6 @@ diff --git a/sources/patches/app-web.patch b/sources/patches/app-web.patch index 0f1202c..a4e1866 100644 --- a/sources/patches/app-web.patch +++ b/sources/patches/app-web.patch @@ -1,10 +1,30 @@ ---- /home/nicolas/Bureau/calibre-web-06fde4fcd00fcd067a58939e1d9eabee62a86913/cps/web.py 2020-04-18 11:48:34.000000000 +0200 -+++ ./web.py 2020-04-18 18:13:44.221590991 +0200 -@@ -1216,6 +1216,7 @@ - user = ub.session.query(ub.User).filter(func.lower(ub.User.nickname) == form['username'].strip().lower()) \ - .first() - if config.config_login_type == constants.LOGIN_LDAP and services.ldap and user and form['password'] != "": -+ import_ldap_user() - login_result, error = services.ldap.bind_user(form['username'], form['password']) - if login_result: - login_user(user, remember=True) +--- 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 @@ + if not config.db_configured: + log.debug(u"Redirect to initial configuration") + return redirect(url_for('admin.basic_configuration')) ++ 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) + 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() + 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") +- return redirect(url_for('web.login')) ++ auth_user = request.headers.get('X-Remote-User') ++ if auth_user: ++ return redirect(request.host_url) ++ else: ++ return redirect(url_for('web.login')) + + + @web.route('/remote/login') From ef218bf3ffe9c4d9b748f17b748b8caf0211fed1 Mon Sep 17 00:00:00 2001 From: Krakinou Date: Sun, 19 Apr 2020 18:06:43 +0200 Subject: [PATCH 13/18] Update scripts to new standard --- README.md | 4 +-- scripts/_settings.sh | 1 - scripts/backup | 61 +++++++++++++++++++++++-------------- scripts/install | 34 ++++++++++++--------- scripts/remove | 28 +++++++++-------- scripts/restore | 71 ++++++++++++++++++++++++-------------------- scripts/upgrade | 54 ++++++++++++++++++++++++++------- 7 files changed, 158 insertions(+), 95 deletions(-) diff --git a/README.md b/README.md index 41c45f4..5e6af76 100644 --- a/README.md +++ b/README.md @@ -78,8 +78,8 @@ sudo yunohost app upgrade calibreweb -u https://github.com/Yunohost-Apps/calibre ## Todo - [X] Multiinstance - [X] Better Multimedia integration : Integrate in Yunohost.multimedia -- [ ] rework LDAP integration to create user automatically -- [X] Package_check integration +- [X] rework LDAP integration to create user automatically +- [ ] Package_check integration - [X] On backup/remove/upgrade : check for database location to update settings - [ ] enable magic link - [ ] Add cronjob to reload database diff --git a/scripts/_settings.sh b/scripts/_settings.sh index 79faedc..ef9f822 100644 --- a/scripts/_settings.sh +++ b/scripts/_settings.sh @@ -2,6 +2,5 @@ PKG_DEPENDENCIES="sqlite3 python3-pip imagemagick" DOSSIER_MEDIA=/home/yunohost.multimedia -create_dir=0 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 ec08995..6637d1b 100755 --- a/scripts/backup +++ b/scripts/backup @@ -5,12 +5,8 @@ #================================================= # IMPORT GENERIC HELPERS #================================================= -if [ ! -e _common.sh ]; then - # 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 ../settings/scripts/_common.sh source /usr/share/yunohost/helpers #================================================= @@ -23,7 +19,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= - +ynh_script_progression --message="Loading installation settings..." --time --weight=1 app=$YNH_APP_INSTANCE_NAME 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%/} ynh_app_setting_set $app calibre_dir $calibre_dir + + #================================================= # 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 #================================================= + +ynh_script_progression --message="Backing up the main app directory..." --time --weight=1 #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 #================================================= -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 #================================================= - -ynh_backup "/etc/logrotate.d/$app" +ynh_script_progression --message="Backing up logrotate configuration..." --time --weight=1 +ynh_backup --src_path="/etc/logrotate.d/$app" #================================================= # BACKUP SYSTEMD #================================================= - -ynh_backup "/etc/systemd/system/$app.service" +ynh_script_progression --message="Backing up systemd configuration..." --time --weight=1 +ynh_backup --src_path="/etc/systemd/system/$app.service" #================================================= # BACKUP THE DATA DIRECTORY #================================================= +ynh_script_progression --message="Backing up data directory..." -backup_core_only=$(ynh_app_setting_get "$app" backup_core_only) -# 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" - ynh_backup "$calibre_dir" -else - ynh_print_info "Data dir will not be saved, because backup_core_only is set." >&2 -fi +ynh_backup --src_path="/home/yunohost.app/${app}/data" --is_big + + +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." --time --weight=1 + +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 \ No newline at end of file diff --git a/scripts/install b/scripts/install index 7402d81..ce58bbe 100755 --- a/scripts/install +++ b/scripts/install @@ -38,7 +38,7 @@ source _settings.sh #================================================= # 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 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 #================================================= -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 path $path_url @@ -71,14 +71,14 @@ ynh_app_setting_set $app is_public $is_public # Find a free port port=$(ynh_find_port 8083) # 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 ynh_app_setting_set $app port $port #================================================= # 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 # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source "$final_path" @@ -86,19 +86,21 @@ ynh_setup_source "$final_path" #================================================= # 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_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 -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 #================================================= # NGINX CONFIGURATION #================================================= #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 @@ -127,7 +129,7 @@ ynh_add_systemd_config #================================================= # 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 # 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. @@ -167,7 +169,7 @@ chown -R $app:$app /var/log/$app #================================================= # 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 ynh_systemd_action @@ -204,7 +206,7 @@ ynh_store_file_checksum "${final_path}/app.db" # 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 @@ -222,10 +224,14 @@ if [ $public_library -eq 0 ]; then fi - #================================================= # RELOAD NGINX #================================================= -ynh_script_progression -t -l --message="Reload nginx and start $app..." -systemctl reload nginx +ynh_script_progression --message="Reload nginx and start $app..." +ynh_systemd_action --service_name=nginx --action=reload ynh_systemd_action + +#================================================= +# END OF SCRIPT +#================================================= +ynh_script_progression --message="Installation of $app completed" --last diff --git a/scripts/remove b/scripts/remove index 568285e..0b84378 100755 --- a/scripts/remove +++ b/scripts/remove @@ -12,6 +12,7 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Loading installation settings..." --weight=2 app=$YNH_APP_INSTANCE_NAME 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 a service from the admin panel, added by `yunohost service add` -if yunohost service status | grep -q $app +# Remove the service from the list of services known by Yunohost (added from `yunohost service add`) +if ynh_exec_warn_less yunohost service status $app >/dev/null then - echo "Remove $app service" + ynh_script_progression --message="Removing $app service..." --time --weight=1 yunohost service remove $app fi @@ -37,7 +38,7 @@ fi #================================================= # 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 @@ -47,7 +48,7 @@ ynh_remove_systemd_config #================================================= # Remove metapackage and its dependencies -ynh_script_progression -t --message="Removing Dependencies..." +ynh_script_progression --message="Removing Dependencies..." ynh_remove_app_dependencies @@ -56,15 +57,15 @@ ynh_remove_app_dependencies #================================================= # Remove the app directory securely -ynh_script_progression -t --message="Removing $final_path..." -ynh_secure_remove "$final_path" +ynh_script_progression --message="Removing $final_path..." +ynh_secure_remove --file="$final_path" #================================================= # REMOVE NGINX CONFIGURATION #================================================= # 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 #================================================= @@ -72,6 +73,7 @@ ynh_remove_nginx_config #================================================= # Remove the app-specific logrotate config +ynh_script_progression --message="Removing logrotate configuration..." ynh_remove_logrotate #================================================= @@ -80,14 +82,14 @@ ynh_remove_logrotate if yunohost firewall list | grep -q "\- $port$" then - ynh_script_progression -t --message="Closing port $port..." + ynh_script_progression --message="Closing port $port..." yunohost firewall disallow TCP $port 2>&1 fi #================================================= # 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 ynh_secure_remove "/var/log/$app/" @@ -97,12 +99,12 @@ ynh_secure_remove "/var/log/$app/" #================================================= # REMOVE DEDICATED USER #================================================= - +ynh_script_progression --message="Removing the dedicated system user..." # Delete a system user -ynh_system_user_delete $app +ynh_system_user_delete --username=$app #================================================= # 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!!!" diff --git a/scripts/restore b/scripts/restore index c1ea009..ab0cdf2 100755 --- a/scripts/restore +++ b/scripts/restore @@ -6,12 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= -if [ ! -e _common.sh ]; then - # 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 ../settings/scripts/_common.sh source /usr/share/yunohost/helpers #================================================= @@ -24,7 +19,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= - +ynh_script_progression --message="Loading settings..." --time --weight=1 app=$YNH_APP_INSTANCE_NAME 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) is_public=$(ynh_app_setting_get $app is_public) port=$(ynh_app_setting_get $app port) +source ../settings/scripts/_settings.sh #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= - +ynh_script_progression --message="Validating restoration parameters..." --time --weight=1 ynh_webpath_available $domain $path_url \ || ynh_die "Path not available: ${domain}${path_url}" test ! -d $final_path \ @@ -48,14 +44,14 @@ test ! -d $final_path \ #================================================= # 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" #================================================= # 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 ynh_app_setting_set $app port $port @@ -63,15 +59,17 @@ ynh_app_setting_set $app port $port # 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) -ynh_system_user_create $app +ynh_system_user_create --username=$app #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_print_info "Restore app directory $final_path" -ynh_restore_file "$final_path" +ynh_script_progression --message="Restoring the app main directory..." --time --weight=1 + +ynh_restore_file --origin_path="$final_path" #================================================= # RESTORE USER RIGHTS @@ -87,45 +85,43 @@ chown -R $app: $final_path #================================================= # 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 #pip package not required as already in app directory #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 #================================================= +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 +#================================================= +# INTEGRATE SERVICE IN YUNOHOST +#================================================= + +yunohost service add $app --description "Browse eBook in the web" --log "/var/log/$app/$app.log" #================================================= # RESTORE THE LOGROTATE CONFIGURATION #================================================= -ynh_restore_file "/etc/logrotate.d/$app" -if [ ! -e /var/log/$app ]; then - mkdir /var/log/$app -fi +ynh_restore_file --origin_path="/etc/logrotate.d/$app" chown -R $app:$app /var/log/$app #================================================= # 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 # So only if it was backup previously. + if [ -d "$YNH_BACKUP_DIR/apps/$app/backup/$calibre_dir" ] then - ynh_restore_file "$calibre_dir" + ynh_restore_file --origin_path="$calibre_dir" --not_mandatory else if [ ! -e "$calibre_dir" ]; then 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 ] then # unprotected_uris allows SSO credentials to be passed anyway. - ynh_app_setting_set $app unprotected_uris "/" + ynh_permission_update --permission "main" --add visitors fi #================================================= @@ -157,10 +153,21 @@ fi #================================================= # RELOAD NGINX #================================================= -ynh_print_info "Reload nginx and start $app" -systemctl reload nginx -ynh_systemd_action -l "INFO in server: Starting Gevent server" +ynh_script_progression --message="Reloading nginx web server..." --time --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_systemd_action --service_name=$app --action="start" + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Restoration completed for $app" --time --last #================================================= # WARNING FOR READ ACCESS #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 243e4ce..b8ee15b 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,7 +12,7 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= - +ynh_script_progression --message="Loading installation settings..." --time --weight=1 app=$YNH_APP_INSTANCE_NAME 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) language=$(ynh_app_setting_get $app language) + #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") #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 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 #================================================= - +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --time --weight=1 # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { @@ -45,7 +51,9 @@ ynh_clean_setup () { ynh_abort_if_errors #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 @@ -62,12 +70,18 @@ path_url=$(ynh_normalize_url_path $path_url) # Download, check integrity, uncompress and patch the source from app.src 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 #================================================= - +ynh_script_progression --message="Upgrading nginx web server configuration..." --time --weight=1 if [ $path_url = "/" ] ; then ynh_replace_string " proxy_set_header X-Script-Name" "# proxy_set_header X-Script-Name" ../conf/nginx.conf fi @@ -78,16 +92,21 @@ ynh_add_nginx_config #================================================= # 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_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/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 a dedicated user (if not existing) +ynh_script_progression --message="Making sure dedicated system user exists..." --time --weight=1 ynh_system_user_create $app # Set permissions on app files (required to be able to update database) @@ -98,7 +117,7 @@ chown -R $app: $final_path #================================================= #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. ynh_multimedia_build_main_dir ynh_multimedia_addaccess $app @@ -106,7 +125,7 @@ ynh_multimedia_addaccess $app #================================================= #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. ### 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" @@ -128,6 +147,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_use_logrotate --non-append #================================================= @@ -135,6 +155,7 @@ ynh_use_logrotate --non-append #================================================= # Create a dedicated systemd config +ynh_script_progression --message="Upgrading systemd configuration..." --time --weight=1 ynh_add_systemd_config #================================================= @@ -169,6 +190,17 @@ fi #================================================= # RELOAD NGINX #================================================= +ynh_script_progression --message="Reloading nginx web server..." --time --weight=1 -systemctl reload nginx -ynh_systemd_action -a restart +ynh_systemd_action --service_name=nginx --action=reload +#================================================= +# 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 From f06e133eb1ce40cda56b6000b2deed0f4c44fb69 Mon Sep 17 00:00:00 2001 From: Krakinou Date: Sun, 26 Apr 2020 22:51:56 +0200 Subject: [PATCH 14/18] Update through 0.6.6 --- check_process | 24 +++---------- conf/app066.src | 3 ++ conf/init_calibre_db_settings | 8 ----- manifest.json | 3 +- scripts/_common.sh | 5 +++ scripts/_settings.sh | 2 +- scripts/backup | 2 +- scripts/change_url | 47 ++++++++++++++++++++----- scripts/install | 16 ++++----- scripts/remove | 24 ++++++------- scripts/upgrade | 65 ++++++++++++++++++++++++++--------- 11 files changed, 122 insertions(+), 77 deletions(-) create mode 100644 conf/app066.src diff --git a/check_process b/check_process index 531867d..b991b3d 100644 --- a/check_process +++ b/check_process @@ -15,12 +15,10 @@ setup_root=1 setup_private=1 setup_public=1 - upgrade=1 from_commit=3b9c5041e4fa73cb965368379f2b83d076c65341 - upgrade=1 from_commit=03bafd5219544c5d317eaf54182e4122ba63a4ad - upgrade_1 from_commit=9e5fa45df7cd840d8a26d25f953857a13d6bc5de + upgrade=1 + upgrade=1 from_commit=11f5b96df7d8850beff47f9904745fa53a6f7ed9 backup_restore=1 multi_instance=1 - incorrect_path=1 port_already_use=1 (8083) change_url=1 #;; Failed upgrade @@ -41,23 +39,11 @@ # setup_root=1 # upgrade=1 from_commit=3b9c5041e4fa73cb965368379f2b83d076c65341 ;;; Levels - Level 1=auto - Level 2=auto - Level 3=auto - Level 4=1 Level 5=auto - Level 6=auto - Level 7=auto - Level 8=0 - Level 9=0 - Level 10=0 ;;; Options -Email= +Email=nicolas@aubonalbanais.ovh Notification=none ;;; Upgrade options - ; commit=3b9c5041e4fa73cb965368379f2b83d076c65341 - name=First in progress release of the app 0.9~ynh1 - manifest_arg=domain=DOMAIN&path=PATH&admin=USER&password=pass&is_public=1& - ; commit=03bafd5219544c5d317eaf54182e4122ba63a4ad - name=Release 0.91~ynh2 + ; commit=11f5b96df7d8850beff47f9904745fa53a6f7ed9 + name=Version 0.96.0~ynh4 manifest_arg=domain=DOMAIN&path=PATH&admin=USER&password=pass&is_public=1& \ No newline at end of file diff --git a/conf/app066.src b/conf/app066.src new file mode 100644 index 0000000..f3f4ee7 --- /dev/null +++ b/conf/app066.src @@ -0,0 +1,3 @@ +SOURCE_URL=https://github.com/janeczku/calibre-web/archive/0.6.6.zip +SOURCE_SUM=87633c2817263ed2d12fce67ea292b1c6d042aa949aafb728789c15d495415cc +SOURCE_FORMAT=zip diff --git a/conf/init_calibre_db_settings b/conf/init_calibre_db_settings index 24690a0..bdbb5cf 100644 --- a/conf/init_calibre_db_settings +++ b/conf/init_calibre_db_settings @@ -1,13 +1,5 @@ config_calibre_dir=\'$calibre_dir\', config_port=$port, -config_certfile=\'\', -config_keyfile=\'\', -config_use_google_drive=0, -config_remote_login=0, -config_use_goodreads=0, -config_logfile=\'\', -config_converterpath=\'\', -config_calibre=\'\', config_logfile=\'$LOG_FILE\', config_access_log=1, config_access_logfile=\'$ACCESS_LOG_FILE\', diff --git a/manifest.json b/manifest.json index f8c7a2a..96d001e 100644 --- a/manifest.json +++ b/manifest.json @@ -11,7 +11,7 @@ "license": "free", "maintainer": { "name": "Krakinou", - "email": "misterl56@hotmail.com" + "email": "nicolas@aubonalbanais.ovh" }, "requirements": { "yunohost": ">= 3.7.1" @@ -66,6 +66,7 @@ { "name": "language", "optional": true, + "type": "string", "ask": { "en": "Select a default language", "fr": "Choisissez une langue par défaut" diff --git a/scripts/_common.sh b/scripts/_common.sh index 9946035..c694803 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -11,6 +11,11 @@ get_db() { 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"; +} + + #================================================= # EXPERIMENTAL HELPERS # TO BE DELETED WHEN RELEASED diff --git a/scripts/_settings.sh b/scripts/_settings.sh index ef9f822..9baa230 100644 --- a/scripts/_settings.sh +++ b/scripts/_settings.sh @@ -1,6 +1,6 @@ #!/bin/bash -PKG_DEPENDENCIES="sqlite3 python3-pip imagemagick" +PKG_DEPENDENCIES="sqlite3 python-dev libldap2-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 6637d1b..4f57ae1 100755 --- a/scripts/backup +++ b/scripts/backup @@ -81,7 +81,7 @@ ynh_backup --src_path="/etc/systemd/system/$app.service" #================================================= ynh_script_progression --message="Backing up data directory..." -ynh_backup --src_path="/home/yunohost.app/${app}/data" --is_big +ynh_backup --src_path="$calibre_dir" --is_big #================================================= diff --git a/scripts/change_url b/scripts/change_url index 369c1b6..dd12d60 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -22,11 +22,27 @@ app=$YNH_APP_INSTANCE_NAME #================================================= # LOAD SETTINGS #================================================= - +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) +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= +ynh_script_progression --message="Backing up the app before changing its url (may take a while)..." --weight=10 + +# Backup the current version of the app +ynh_backup_before_upgrade +ynh_clean_setup () { + # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. + ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" + + # restore it if the upgrade fails + ynh_restore_upgradebackup +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors #================================================= # CHECK THE SYNTAX OF THE PATHS @@ -55,9 +71,17 @@ fi #================================================= # STANDARD MODIFICATIONS +#================================================= +# STOP SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Stopping a systemd service..." --weight=1 + +ynh_systemd_action --service_name=$app --action="stop" + #================================================= # MODIFY URL IN NGINX CONF #================================================= +ynh_script_progression --message="Updating nginx web server configuration..." --weight=1 nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf @@ -87,16 +111,23 @@ then ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf" fi -#================================================= -# SPECIFIC MODIFICATIONS -#================================================= -# ... -#================================================= - #================================================= # GENERIC FINALISATION #================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." --weight=1 + +ynh_systemd_action --service_name=$app --action="start" +#================================================= # RELOAD NGINX #================================================= +ynh_script_progression --message="Reloading nginx web server..." --weight=1 -systemctl reload nginx +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Change of URL completed for $app" --last diff --git a/scripts/install b/scripts/install index ce58bbe..7c6a969 100755 --- a/scripts/install +++ b/scripts/install @@ -38,7 +38,7 @@ source _settings.sh #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= -ynh_script_progression --message="Validating installation parameters..." +ynh_script_progression --message="Validating installation parameters..." --weight=5 final_path=/var/www/$app 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 #================================================= -ynh_script_progression --message="Storing installation settings..." +ynh_script_progression --message="Storing installation settings..." --weight=5 ynh_app_setting_set $app domain $domain ynh_app_setting_set $app path $path_url @@ -90,10 +90,10 @@ ynh_setup_source "$final_path" ynh_script_progression --message="Installing package dependencies..." --weight=15 ynh_install_app_dependencies $PKG_DEPENDENCIES -ynh_script_progression --message="Installing pip requirements ..." --weight=30 +ynh_script_progression --message="Installing pip requirements..." --weight=50 pip3 install --no-cache-dir --target $final_path/vendor -r $final_path/requirements.txt -ynh_script_progression --message="Installing pip additionnal requirements..." --weight=40 +ynh_script_progression --message="Installing pip additionnal requirements..." --weight=60 pip3 install --no-cache-dir --upgrade --target $final_path/vendor -r $final_path/optional-requirements.txt #================================================= @@ -129,7 +129,7 @@ ynh_add_systemd_config #================================================= # CREATE FILES AND DIRECTORIES #================================================= -ynh_script_progression --message="Creating files and directory..." +ynh_script_progression --message="Creating files and directory..." --weight=5 #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 limited to the admin user, we will set it inside his own multimedia directory. @@ -169,7 +169,7 @@ chown -R $app:$app /var/log/$app #================================================= # SET SQLITE DATABASE SETTINGS #================================================= -ynh_script_progression --message="Setting up database and settings..." +ynh_script_progression --message="Setting up database and settings..." --weight=5 #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 @@ -227,11 +227,11 @@ fi #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reload nginx and start $app..." +ynh_script_progression --message="Reload nginx and start $app..." --weight=5 -t ynh_systemd_action --service_name=nginx --action=reload ynh_systemd_action #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of $app completed" --last +ynh_script_progression --message="Installation of $app completed" --last -t diff --git a/scripts/remove b/scripts/remove index 0b84378..68341c0 100755 --- a/scripts/remove +++ b/scripts/remove @@ -12,7 +12,7 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --weight=2 +ynh_script_progression --message="Loading installation settings..." --weight=3 app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) @@ -27,7 +27,7 @@ calibre_dir=$(ynh_app_setting_get $app calibre_dir) # Remove the service from the list of services known by Yunohost (added from `yunohost service add`) if ynh_exec_warn_less yunohost service status $app >/dev/null then - ynh_script_progression --message="Removing $app service..." --time --weight=1 + ynh_script_progression --message="Removing $app service..." --weight=1 yunohost service remove $app fi @@ -38,7 +38,7 @@ fi #================================================= # Remove the dedicated systemd config -ynh_script_progression --message="Stopping and removing the systemd service..." +ynh_script_progression --message="Stopping and removing the systemd service..." --weight=2 ynh_remove_systemd_config @@ -48,7 +48,7 @@ ynh_remove_systemd_config #================================================= # Remove metapackage and its dependencies -ynh_script_progression --message="Removing Dependencies..." +ynh_script_progression --message="Removing Dependencies..." --weight=5 ynh_remove_app_dependencies @@ -57,7 +57,7 @@ ynh_remove_app_dependencies #================================================= # Remove the app directory securely -ynh_script_progression --message="Removing $final_path..." +ynh_script_progression --message="Removing $final_path..." --weight=1 ynh_secure_remove --file="$final_path" #================================================= @@ -65,7 +65,7 @@ ynh_secure_remove --file="$final_path" #================================================= # Remove the dedicated nginx config -ynh_script_progression --message="Removing nginx web server configuration..." +ynh_script_progression --message="Removing nginx web server configuration..." --weight=1 ynh_remove_nginx_config #================================================= @@ -73,7 +73,7 @@ ynh_remove_nginx_config #================================================= # Remove the app-specific logrotate config -ynh_script_progression --message="Removing logrotate configuration..." +ynh_script_progression --message="Removing logrotate configuration..." --weight=1 ynh_remove_logrotate #================================================= @@ -82,16 +82,12 @@ ynh_remove_logrotate if yunohost firewall list | grep -q "\- $port$" then - ynh_script_progression --message="Closing port $port..." + ynh_script_progression --message="Closing port $port..." --weight=10 yunohost firewall disallow TCP $port 2>&1 fi -#================================================= -# SPECIFIC REMOVE -#================================================= -ynh_script_progression --message="Removing log and user $app..." - # Remove the log files +ynh_script_progression --message="Removing log file..." --weight=1 ynh_secure_remove "/var/log/$app/" #================================================= @@ -99,8 +95,8 @@ ynh_secure_remove "/var/log/$app/" #================================================= # REMOVE DEDICATED USER #================================================= -ynh_script_progression --message="Removing the dedicated system user..." # Delete a system user +ynh_script_progression --message="Removing the dedicated system user..." --weight=1 ynh_system_user_delete --username=$app #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index b8ee15b..6219aab 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,7 +12,7 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --time --weight=1 +ynh_script_progression --message="Loading installation settings..." --weight=2 app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) @@ -37,10 +37,24 @@ source _settings.sh #================================================= upgrade_type=$(ynh_check_app_version_changed) +current_upstream_package_version=$(ynh_app_upstream_version --manifest="/etc/yunohost/apps/$app/manifest.json") #0.96.0 +current_upstream_package_version="${current_upstream_package_version/".96"/".6"}" #0.6.0 + +new_upstream_package_version=$(ynh_app_upstream_version) #0.96.0 +new_upstream_package_version="${new_upstream_package_version/".96"/".6"}" #0.6.0 + +if [ -f $final_path/cps/constants.py ]; then + current_upstream_app_version=$(cat $final_path/cps/constants.py | grep STABLE_VERSION) + current_upstream_app_version="${current_upstream_app_version/STABLE_VERSION = \{\'version\': \'/""}" + current_upstream_app_version="${current_upstream_app_version/\'\}/""}" +else + current_upstream_app_version='0.6.0' +fi + #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --time --weight=1 +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=10 # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { @@ -51,7 +65,7 @@ ynh_clean_setup () { ynh_abort_if_errors #Stop the app in case database is updated -ynh_script_progression --message="Stopping a systemd service..." --time --weight=1 +ynh_script_progression --message="Stopping a systemd service..." --weight=2 ynh_systemd_action --service_name=$app --action="stop" @@ -68,12 +82,24 @@ path_url=$(ynh_normalize_url_path $path_url) # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -# Download, check integrity, uncompress and patch the source from app.src -ynh_print_info "Download and install new sources" +#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 +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_setup_source --dest_dir="$final_path" --source_id="app066" + pip install --no-cache-dir --upgrade --target $final_path/vendor -r $final_path/requirements.txt + chown -R $app: $final_path + #set database settings as per conf file : restart server so that app.db is regenerated + ynh_systemd_action + #sleep required on low spec like raspberryPi + sleep 5s + ynh_systemd_action -a stop + current_upstream_app_version="0.6.6" + #remove unwanted entry in settings db +fi + if [ "$upgrade_type" == "UPGRADE_APP" ] then - ynh_script_progression --message="Upgrading source files..." --time --weight=1 - + ynh_script_progression --message="Upgrading source files from $current_upstream_app_version to new_upstream_package_version..." --weight=10 # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$final_path" fi @@ -81,26 +107,29 @@ fi #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Upgrading nginx web server configuration..." --time --weight=1 + +ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=5 if [ $path_url = "/" ] ; then ynh_replace_string " proxy_set_header X-Script-Name" "# proxy_set_header X-Script-Name" ../conf/nginx.conf fi - # Create a dedicated nginx config ynh_add_nginx_config #================================================= # UPGRADE DEPENDENCIES #================================================= -ynh_script_progression --message="Installing package dependencies..." --weight=15 -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 +if [ "$upgrade_type" == "UPGRADE_APP" ] +then + ynh_script_progression --message="Installing package dependencies..." --weight=15 + ynh_install_app_dependencies $PKG_DEPENDENCIES -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 + ynh_script_progression --message="Installing pip requirements ..." --weight=30 + pip3 install --no-cache-dir --upgrade --target $final_path/vendor -r $final_path/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 +fi #================================================= # CREATE DEDICATED USER #================================================= @@ -130,13 +159,13 @@ ynh_script_progression --message="Update database..." --time --weight=1 ### 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 settings +#set database settings as per conf file : restart server so that app.db is regenerated, then add new ldap & log settings ynh_systemd_action #sleep required on low spec like raspberryPi sleep 5s ynh_systemd_action -a stop -conf="\"UPDATE settings SET $(. <(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" # Recalculate and store the checksum of the file for the next upgrade. @@ -150,6 +179,7 @@ ynh_store_file_checksum "$final_path/app.db" ynh_script_progression --message="Upgrading logrotate configuration..." --time --weight=1 ynh_use_logrotate --non-append + #================================================= # SETUP SYSTEMD #================================================= @@ -204,3 +234,4 @@ ynh_systemd_action --service_name=$app --action="start" #================================================= ynh_script_progression --message="Upgrade of $app completed" --time --last + From 2421277c81c98d80ab9e08555246e3e25d49227d Mon Sep 17 00:00:00 2001 From: Krakinou Date: Tue, 28 Apr 2020 23:40:02 +0200 Subject: [PATCH 15/18] Small script correction --- README.md | 2 +- scripts/_settings.sh | 2 +- scripts/change_url | 4 ++-- scripts/install | 6 +++--- scripts/restore | 4 ++-- scripts/upgrade | 14 ++++++++------ 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 5e6af76..555562c 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ sudo yunohost app upgrade calibreweb -u https://github.com/Yunohost-Apps/calibre - [X] Multiinstance - [X] Better Multimedia integration : Integrate in Yunohost.multimedia - [X] rework LDAP integration to create user automatically -- [ ] Package_check integration +- [X] Package_check integration - [X] On backup/remove/upgrade : check for database location to update settings - [ ] enable magic link - [ ] Add cronjob to reload database diff --git a/scripts/_settings.sh b/scripts/_settings.sh index 9baa230..9cc863e 100644 --- a/scripts/_settings.sh +++ b/scripts/_settings.sh @@ -1,6 +1,6 @@ #!/bin/bash -PKG_DEPENDENCIES="sqlite3 python-dev libldap2-dev python3-pip imagemagick" +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/change_url b/scripts/change_url index dd12d60..1afabc0 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -118,13 +118,13 @@ fi #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="start" +ynh_systemd_action --service_name=$app --action="start" -l "Starting Tornado server on :8083" -t 20 #================================================= # RELOAD NGINX #================================================= ynh_script_progression --message="Reloading nginx web server..." --weight=1 -ynh_systemd_action --service_name=nginx --action=reload +ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT diff --git a/scripts/install b/scripts/install index 7c6a969..830ae51 100755 --- a/scripts/install +++ b/scripts/install @@ -227,11 +227,11 @@ fi #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reload nginx and start $app..." --weight=5 -t +ynh_script_progression --message="Reload nginx and start $app..." --weight=5 ynh_systemd_action --service_name=nginx --action=reload -ynh_systemd_action +ynh_systemd_action -l "Starting Tornado server on :8083" -t 20 #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of $app completed" --last -t +ynh_script_progression --message="Installation of $app completed" --last diff --git a/scripts/restore b/scripts/restore index ab0cdf2..9600b95 100755 --- a/scripts/restore +++ b/scripts/restore @@ -109,7 +109,7 @@ yunohost service add $app --description "Browse eBook in the web" --log "/var/lo #================================================= ynh_restore_file --origin_path="/etc/logrotate.d/$app" -chown -R $app:$app /var/log/$app + #================================================= # RESTORE THE DATA DIRECTORY @@ -161,7 +161,7 @@ ynh_systemd_action --service_name=nginx --action=reload #================================================= ynh_script_progression --message="Starting a systemd service..." --time --weight=1 -ynh_systemd_action --service_name=$app --action="start" +ynh_systemd_action --service_name=$app --action="start" -l "Starting Tornado server on :8083" -t 20 #================================================= # END OF SCRIPT diff --git a/scripts/upgrade b/scripts/upgrade index 6219aab..d92fcef 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -13,9 +13,10 @@ source /usr/share/yunohost/helpers # 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) +port=$(ynh_app_setting_get $app port) path_url=$(ynh_app_setting_get $app path) admin=$(ynh_app_setting_get $app admin) is_public=$(ynh_app_setting_get $app is_public) @@ -23,13 +24,14 @@ 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 +#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") -#Save it in settings so that it can be used back afterward calibre_dir=${calibre_dir%/} ynh_app_setting_set $app calibre_dir $calibre_dir -port=$(ynh_app_setting_get $app port) +upload=$(sqlite3 $final_path/app.db "SELECT config_uploading FROM settings WHERE ID=1") +ynh_app_setting_set $app upload $upload + source _settings.sh #================================================= @@ -99,7 +101,7 @@ fi if [ "$upgrade_type" == "UPGRADE_APP" ] 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 # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$final_path" fi @@ -228,7 +230,7 @@ ynh_systemd_action --service_name=nginx --action=reload #================================================= ynh_script_progression --message="Starting a systemd service..." --time --weight=1 -ynh_systemd_action --service_name=$app --action="start" +ynh_systemd_action --service_name=$app --action="start" -l "Starting Tornado server on :8083" -t 20 #================================================= # END OF SCRIPT #================================================= From f585b5e8a535c993cb2bcadfde22bfaf97f25a77 Mon Sep 17 00:00:00 2001 From: Krakinou Date: Fri, 1 May 2020 14:08:08 +0200 Subject: [PATCH 16/18] New version & New LDAP & script cleaning New App version with better LDAP Script cleaning : --time and new package check control. Add sleep to deal with test too quick for service to start New LDAP integration : import on both request and login --- .project | 17 ------------ conf/app.src | 4 +-- scripts/_common.sh | 19 ++++--------- scripts/_settings.sh | 6 ----- scripts/backup | 24 +++++++++-------- scripts/change_url | 8 +++--- scripts/install | 25 +++++++++++------- scripts/remove | 4 ++- scripts/restore | 26 +++++++++--------- scripts/upgrade | 27 ++++++++++--------- sources/patches/app-web.patch | 50 +++++++++++++++++++++++++---------- 11 files changed, 107 insertions(+), 103 deletions(-) delete mode 100644 .project delete mode 100644 scripts/_settings.sh 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 From 0a5473fb1c85d7e3f63166d6007aab8c71d406b1 Mon Sep 17 00:00:00 2001 From: Krakinou Date: Sat, 2 May 2020 15:01:20 +0200 Subject: [PATCH 17/18] update systemd start and stop --- .project | 17 +++++++++++++++++ scripts/backup | 5 +++-- scripts/change_url | 4 ++-- scripts/install | 3 +-- scripts/restore | 8 ++++++-- scripts/upgrade | 18 +++++++++++------- 6 files changed, 40 insertions(+), 15 deletions(-) create mode 100644 .project diff --git a/.project b/.project new file mode 100644 index 0000000..0675d93 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + calibre_ynh + + + + + + org.python.pydev.PyDevBuilder + + + + + + org.python.pydev.pythonNature + + diff --git a/scripts/backup b/scripts/backup index bfd842f..e82f3c4 100755 --- a/scripts/backup +++ b/scripts/backup @@ -25,6 +25,7 @@ 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) +port=$(ynh_app_setting_get $app port) #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") @@ -90,8 +91,8 @@ ynh_backup --src_path="$calibre_dir" --is_big #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=5 -ynh_systemd_action --service_name=$app --action="start" -t 20 -sleep 2s +ynh_systemd_action --service_name=$app --action="start" -l "server on :$port" -t 20 + #================================================= # END OF SCRIPT diff --git a/scripts/change_url b/scripts/change_url index d813374..2702e74 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -119,8 +119,8 @@ fi #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=2 -ynh_systemd_action --service_name=$app --action="start" -t 20 -sleep 2s +ynh_systemd_action --service_name=$app --action="start" -l "server on :$port" -t 20 + #================================================= # RELOAD NGINX #================================================= diff --git a/scripts/install b/scripts/install index 735547d..dfafb9a 100755 --- a/scripts/install +++ b/scripts/install @@ -233,8 +233,7 @@ fi #================================================= ynh_script_progression --message="Reload nginx and start $app..." --weight=5 ynh_systemd_action --service_name=nginx --action=reload -ynh_systemd_action --service_name=$app --action=start -t 20 -sleep 2s +ynh_systemd_action --service_name=$app --action=start -l "server on :$port" -t 20 #================================================= # END OF SCRIPT diff --git a/scripts/restore b/scripts/restore index 46b2922..8cb9130 100755 --- a/scripts/restore +++ b/scripts/restore @@ -109,6 +109,11 @@ yunohost service add $app --description "Browse eBook in the web" --log "/var/lo ynh_restore_file --origin_path="/etc/logrotate.d/$app" +#================================================= +# RESTORE THE LOG FILE DIRECTORY +#================================================= +mkdir -p /var/log/$app +chown -R $app:$app /var/log/$app #================================================= # RESTORE THE DATA DIRECTORY @@ -160,8 +165,7 @@ ynh_systemd_action --service_name=nginx --action=reload #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=2 -ynh_systemd_action --service_name=$app --action="start" -t 20 -sleep 2s +ynh_systemd_action --service_name=$app --action="start" -l "server on :$port" -t 20 #================================================= # END OF SCRIPT diff --git a/scripts/upgrade b/scripts/upgrade index d49abd9..d2b04b3 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -93,10 +93,10 @@ if version_gt "0.6.6" $current_upstream_app_version && [ $current_upstream_packa pip install --no-cache-dir --upgrade --target $final_path/vendor -r $final_path/requirements.txt chown -R $app: $final_path #set database settings as per conf file : restart server so that app.db is regenerated - ynh_systemd_action + ynh_systemd_action --service_name=$app --action="start" -line_match="server on " --log_path=$final_path/calibre-web.log -t 20 #sleep required on low spec like raspberryPi sleep 5s - ynh_systemd_action -a stop + ynh_systemd_action --service_name=$app --action="stop" current_upstream_app_version="0.6.6" #remove unwanted entry in settings db fi @@ -164,10 +164,14 @@ ynh_script_progression --message="Update database..." --weight=1 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 -ynh_systemd_action +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 20 +else + ynh_systemd_action --service_name=$app --action="start" -line_match="server on :$port" -t 20 +fi #sleep required on low spec like raspberryPi -sleep 5s -ynh_systemd_action -a stop +sleep 2s +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" @@ -232,8 +236,8 @@ ynh_systemd_action --service_name=nginx --action=reload #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=2 -ynh_systemd_action --service_name=$app --action="start" -t 20 -sleep 2s +ynh_systemd_action --service_name=$app --action="start" -l "server on :$port" -t 20 + #================================================= # END OF SCRIPT #================================================= From af40936709e5a45c360b4b2a9e0cec12e495cb26 Mon Sep 17 00:00:00 2001 From: Krakinou Date: Sat, 2 May 2020 20:39:20 +0200 Subject: [PATCH 18/18] Typo Typo in upgrade update README with todo --- README.md | 6 +++++- manifest.json | 2 +- scripts/change_url | 1 + scripts/upgrade | 19 ++++++++++++------- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 555562c..a75f3a5 100644 --- a/README.md +++ b/README.md @@ -81,9 +81,13 @@ sudo yunohost app upgrade calibreweb -u https://github.com/Yunohost-Apps/calibre - [X] rework LDAP integration to create user automatically - [X] Package_check integration - [X] On backup/remove/upgrade : check for database location to update settings +- [ ] Update mail settings with yunohost settings - [ ] enable magic link -- [ ] Add cronjob to reload database +- [ ] Add cronjob to reload database (for nextcloud integration) - [ ] OPDS activation +- [ ] Add action to restart the server +- [ ] Add action to synchronize users +- [ ] Add action to deactivate LDAP et retrieve admin password ## LICENSE diff --git a/manifest.json b/manifest.json index 96d001e..f65a983 100644 --- a/manifest.json +++ b/manifest.json @@ -11,7 +11,7 @@ "license": "free", "maintainer": { "name": "Krakinou", - "email": "nicolas@aubonalbanais.ovh" + "email": "misterl56@hotmail.com" }, "requirements": { "yunohost": ">= 3.7.1" diff --git a/scripts/change_url b/scripts/change_url index 2702e74..f2e0d29 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -36,6 +36,7 @@ ynh_script_progression --message="Backing up the app before changing its url (ma # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { + ynh_clean_check_starting # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" diff --git a/scripts/upgrade b/scripts/upgrade index d2b04b3..7febd32 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -39,6 +39,7 @@ source _common.sh #================================================= # CHECK VERSION #================================================= + upgrade_type=$(ynh_check_app_version_changed) current_upstream_package_version=$(ynh_app_upstream_version --manifest="/etc/yunohost/apps/$app/manifest.json") #0.96.0 @@ -59,9 +60,13 @@ fi # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=10 + # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { + + ynh_clean_check_starting + # restore it if the upgrade fails ynh_restore_upgradebackup } @@ -87,15 +92,15 @@ path_url=$(ynh_normalize_url_path $path_url) #================================================= #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 -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_setup_source --dest_dir="$final_path" --source_id="app066" pip install --no-cache-dir --upgrade --target $final_path/vendor -r $final_path/requirements.txt chown -R $app: $final_path #set database settings as per conf file : restart server so that app.db is regenerated - ynh_systemd_action --service_name=$app --action="start" -line_match="server on " --log_path=$final_path/calibre-web.log -t 20 + ynh_systemd_action --service_name=$app --action="start" --line_match="server on " --log_path="$final_path/calibre-web.log" -t 20 #sleep required on low spec like raspberryPi - sleep 5s + sleep 2s ynh_systemd_action --service_name=$app --action="stop" current_upstream_app_version="0.6.6" #remove unwanted entry in settings db @@ -164,13 +169,13 @@ ynh_script_progression --message="Update database..." --weight=1 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 20 +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 20 else - ynh_systemd_action --service_name=$app --action="start" -line_match="server on :$port" -t 20 + ynh_systemd_action --service_name=$app --action="start" --line_match="server on :$port" -t 20 fi #sleep required on low spec like raspberryPi -sleep 2s +sleep 3s 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\""