From d40dc9fd9940087562ace93f425546a5eae65109 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 27 Jul 2022 04:18:35 +0200 Subject: [PATCH] Upgrade to 0.2021.36~ynh2 --- check_process | 17 ++-- doc/.gitkeep | 0 doc/DESCRIPTION.md | 1 + doc/DESCRIPTION_fr.md | 1 + doc/DISCLAIMER.md | 0 doc/DISCLAIMER_fr.md | 0 doc/screenshots/.gitkeep | 0 hooks/post_user_create | 7 +- hooks/post_user_delete | 7 +- manifest.json | 20 +++-- scripts/_common.sh | 65 +++++++-------- scripts/backup | 10 ++- scripts/install | 35 ++++---- scripts/remove | 33 +++----- scripts/restore | 80 ++++++++++--------- scripts/upgrade | 65 ++++++++------- .../backend-01-image_similarity-main.py.patch | 20 ++--- 17 files changed, 176 insertions(+), 185 deletions(-) create mode 100644 doc/.gitkeep create mode 100644 doc/DESCRIPTION.md create mode 100644 doc/DESCRIPTION_fr.md create mode 100644 doc/DISCLAIMER.md create mode 100644 doc/DISCLAIMER_fr.md create mode 100644 doc/screenshots/.gitkeep diff --git a/check_process b/check_process index 2b1a527..e372b58 100644 --- a/check_process +++ b/check_process @@ -1,13 +1,8 @@ -# See here for more information -# https://github.com/YunoHost/package_check#syntax-check_process-file - -# Move this file from check_process.default to check_process when you have filled it. - ;; Test complet ; Manifest - domain="domain.tld" (DOMAIN) - admin="john" (USER) - is_public=1 (PUBLIC|public=1|private=0) + domain="domain.tld" + is_public=1 + admin="john" allow_multimedia_write=1 ; Checks pkg_linter=1 @@ -17,7 +12,10 @@ setup_private=1 setup_public=1 upgrade=1 + # 0.0.20210329~ynh1 upgrade=1 from_commit=3b5b527e26cb6b530bd51f14c791d1dc15757af4 + # 0.2021.36~ynh1 + upgrade=1 from_commit=86a0d1ad46c4fd341cac32103dcaa8b3df832b7e backup_restore=1 multi_instance=0 port_already_use=0 @@ -26,6 +24,3 @@ Email= Notification=none ;;; Upgrade options - ; commit=3b5b527e26cb6b530bd51f14c791d1dc15757af4 - name=Upgrade from March 29 - manifest_arg=domain=domain.tld&admin=john&is_public=1&allow_multimedia_write=1& diff --git a/doc/.gitkeep b/doc/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/doc/DESCRIPTION.md b/doc/DESCRIPTION.md new file mode 100644 index 0000000..76700ab --- /dev/null +++ b/doc/DESCRIPTION.md @@ -0,0 +1 @@ +A photo viewer and manager similar to Google Photos diff --git a/doc/DESCRIPTION_fr.md b/doc/DESCRIPTION_fr.md new file mode 100644 index 0000000..3ebfaff --- /dev/null +++ b/doc/DESCRIPTION_fr.md @@ -0,0 +1 @@ +Un gestionnaire de photos semblable à Google Photos diff --git a/doc/DISCLAIMER.md b/doc/DISCLAIMER.md new file mode 100644 index 0000000..e69de29 diff --git a/doc/DISCLAIMER_fr.md b/doc/DISCLAIMER_fr.md new file mode 100644 index 0000000..e69de29 diff --git a/doc/screenshots/.gitkeep b/doc/screenshots/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/hooks/post_user_create b/hooks/post_user_create index b5d0c38..92f7f3a 100644 --- a/hooks/post_user_create +++ b/hooks/post_user_create @@ -6,19 +6,18 @@ app="${0//.\/50-}" user=$1 mail=$2 -arch="$(dpkg --print-architecture)" arm64_test=0 final_path=$(ynh_app_setting_get --app=$app --key=final_path) backend_path="$final_path/backend" path_prefix="$backend_path/venv/bin" -if [ "$arch" = "arm64" ] || [ "$arm64_test" -eq 1 ]; then +if [ "$YNH_ARCH" = "arm64" ] || [ "$arm64_test" -eq 1 ]; then export CONDA_DIR="$backend_path/conda" path_prefix="$backend_path/cmake/bin:$CONDA_DIR/condabin:$CONDA_DIR/bin:$path_prefix" fi pushd "$backend_path" - sudo -u $app bash -c " + ynh_exec_warn_less ynh_exec_as $app bash -c " set -a export PATH=\"$path_prefix:"'$PATH'"\" source \"$final_path\"/librephotos.env @@ -33,5 +32,5 @@ try: user.save() except User.DoesNotExist: User.objects.create_user('$user', email='$mail', scan_directory='/home/yunohost.multimedia/$user/Picture') -" 2>&1 +" popd diff --git a/hooks/post_user_delete b/hooks/post_user_delete index 5a7ea72..cd51740 100644 --- a/hooks/post_user_delete +++ b/hooks/post_user_delete @@ -6,19 +6,18 @@ app="${0//.\/50-}" user=$1 purge=$2 -arch="$(dpkg --print-architecture)" arm64_test=0 final_path=$(ynh_app_setting_get --app=$app --key=final_path) backend_path="$final_path/backend" path_prefix="$backend_path/venv/bin" -if [ "$arch" = "arm64" ] || [ "$arm64_test" -eq 1 ]; then +if [ "$YNH_ARCH" = "arm64" ] || [ "$arm64_test" -eq 1 ]; then export CONDA_DIR="$backend_path/conda" path_prefix="$backend_path/cmake/bin:$CONDA_DIR/condabin:$CONDA_DIR/bin:$path_prefix" fi pushd "$backend_path" - sudo -u $app bash -c " + ynh_exec_warn_less ynh_exec_as $app bash -c " set -a export PATH=\"$path_prefix:"'$PATH'"\" source \"$final_path\"/librephotos.env @@ -34,5 +33,5 @@ try: user.delete() except User.DoesNotExist: pass -" 2>&1 +" popd diff --git a/manifest.json b/manifest.json index dac86b1..0f24364 100644 --- a/manifest.json +++ b/manifest.json @@ -6,11 +6,11 @@ "en": "A photo viewer and manager similar to Google Photos", "fr": "Un gestionnaire de photos semblable à Google Photos" }, - "version": "0.2021.36~ynh1", + "version": "0.2021.36~ynh2", "url": "https://github.com/LibrePhotos/librephotos", "upstream": { "license": "MIT", - "website": "https://librephotos.com/", + "website": "https://librephotos.com", "demo": "https://demo2.librephotos.com/ (user: demo, password: demo1234)", "admindoc": "https://docs.librephotos.com/", "userdoc": "https://github.com/LibrePhotos/librephotos", @@ -22,7 +22,7 @@ "email": "jules.berthlet@quoi.xyz" }, "requirements": { - "yunohost": ">= 4.2.4" + "yunohost": ">= 4.3.0" }, "multi_instance": false, "services": [ @@ -31,22 +31,20 @@ "postgresql" ], "arguments": { - "install" : [ + "install": [ { "name": "domain", - "type": "domain", - "example": "example.com" - }, - { - "name": "admin", - "type": "user", - "example": "johndoe" + "type": "domain" }, { "name": "is_public", "type": "boolean", "default": true }, + { + "name": "admin", + "type": "user" + }, { "name": "allow_multimedia_write", "type": "boolean", diff --git a/scripts/_common.sh b/scripts/_common.sh index 5c65278..a0caf07 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -7,7 +7,8 @@ # dependencies used by the app pkg_dependencies="libtinfo5 unzip ca-certificates swig libpq-dev postgresql postgresql-contrib postgresql-common ffmpeg libimage-exiftool-perl curl libopenblas-dev libmagic1 libboost-all-dev libxrender-dev liblapack-dev git bzip2 cmake build-essential libsm6 libglib2.0-0 libgl1-mesa-glx gfortran gunicorn libheif-dev libssl-dev rustc liblzma-dev python3 python3-pip python3-venv imagemagick xsel nodejs npm redis-server libmagickwand-dev libldap2-dev libsasl2-dev" -arch="$(dpkg --print-architecture)" +nodejs_version="14" + arm64_test=0 if ! (apt-cache -q=0 show ufraw-batch |& grep ': No packages found' &>/dev/null); then @@ -19,7 +20,7 @@ fi #================================================= function unpack_source { - ynh_secure_remove "$final_path" + ynh_secure_remove --file="$final_path" mkdir -p "$final_path/data_models/"{places365,im2txt} ynh_setup_source --source_id="places365" --dest_dir="$final_path/data_models/places365/" ynh_setup_source --source_id="im2txt" --dest_dir="$final_path/data_models/im2txt/" @@ -35,14 +36,14 @@ function unpack_source { ynh_setup_source --source_id="backend" --dest_dir="$final_path/backend/" ynh_setup_source --source_id="frontend" --dest_dir="$final_path/frontend/" ynh_setup_source --source_id="dlib" --dest_dir="$final_path/backend/dlib/" - if [ "$arch" = "arm64" ] || [ "$arm64_test" -eq 1 ]; then + if [ "$YNH_ARCH" = "arm64" ] || [ "$arm64_test" -eq 1 ]; then export CONDA_DIR="$final_path/backend/conda" mkdir -p "$CONDA_DIR" - if [ "$arch" = "arm64" ]; then + if [ "$YNH_ARCH" = "arm64" ]; then ynh_setup_source --source_id="miniforge3" --dest_dir="$CONDA_DIR" ynh_setup_source --source_id="cmake" --dest_dir="$final_path/backend/cmake/" else - wget -O "${CONDA_DIR}/Miniforge3-4.10.1-4-Linux-aarch64.sh" https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh 2>&1 + wget -O "${CONDA_DIR}/Miniforge3-4.10.1-4-Linux-aarch64.sh" https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh ynh_setup_source --source_id="cmake_amd64" --dest_dir="$final_path/backend/cmake/" fi #ynh_setup_source --source_id="faiss" --dest_dir="$final_path/backend/faiss/" @@ -55,24 +56,24 @@ function set_up_backend { backend_path="$final_path/backend" pushd "$backend_path" chown -R $app:$app "$backend_path" - sudo -u $app python3 -m venv $backend_path/venv + ynh_exec_warn_less ynh_exec_as $app python3 -m venv $backend_path/venv path_prefix="$backend_path/venv/bin" - if [ "$arch" = "arm64" ] || [ "$arm64_test" -eq 1 ]; then + if [ "$YNH_ARCH" = "arm64" ] || [ "$arm64_test" -eq 1 ]; then path_prefix="$backend_path/cmake/bin:$CONDA_DIR/condabin:$CONDA_DIR/bin:$path_prefix" fi - local python_path="$path_prefix:$(sudo -u $app bash -c 'echo $PATH')" + local python_path="$path_prefix:$(ynh_exec_warn_less ynh_exec_as $app bash -c 'echo $PATH')" local cache_dir="$backend_path/.cache/pip" - sudo -u $app env "PATH=$python_path" pip --cache-dir "$cache_dir" install -U wheel pip setuptools 2>&1 - if [ "$arch" = "arm64" ] || [ "$arm64_test" -eq 1 ]; then - sudo -u $app env "CONDA_DIR=$CONDA_DIR" bash "${CONDA_DIR}/Miniforge3-4.10.1-4-Linux-aarch64.sh" -bu -p "${CONDA_DIR}" - sudo -u $app env "PATH=$python_path" pip --cache-dir "$cache_dir" install -U torch==1.8.1 torchvision==0.9.1 -f https://torch.maku.ml/whl/stable.html 2>&1 - sudo -u $app env "PATH=$python_path" conda install -y numpy psycopg2 cython pandas scikit-learn=0.24.1 scikit-image=0.18.1 spacy=2.3.5 gevent=20.12.1 matplotlib=3.3.2 faiss-cpu==1.7.0 + ynh_exec_warn_less ynh_exec_as $app env "PATH=$python_path" pip --cache-dir "$cache_dir" install -U wheel pip setuptools + if [ "$YNH_ARCH" = "arm64" ] || [ "$arm64_test" -eq 1 ]; then + ynh_exec_warn_less ynh_exec_as $app env "CONDA_DIR=$CONDA_DIR" bash "${CONDA_DIR}/Miniforge3-4.10.1-4-Linux-aarch64.sh" -bu -p "${CONDA_DIR}" + ynh_exec_warn_less ynh_exec_as $app env "PATH=$python_path" pip --cache-dir "$cache_dir" install -U torch==1.8.1 torchvision==0.9.1 -f https://torch.maku.ml/whl/stable.html + ynh_exec_warn_less ynh_exec_as $app env "PATH=$python_path" conda install -y numpy psycopg2 cython pandas scikit-learn=0.24.1 scikit-image=0.18.1 spacy=2.3.5 gevent=20.12.1 matplotlib=3.3.2 faiss-cpu==1.7.0 #pushd "$backend_path/faiss" - # sudo -u $app env "PATH=$python_path" cmake -B build . -DFAISS_ENABLE_GPU=OFF -DFAISS_ENABLE_PYTHON=ON -DFAISS_OPT_LEVEL=generic - # sudo -u $app env "PATH=$python_path" make -C build -j faiss - # sudo -u $app env "PATH=$python_path" make -C build -j swigfaiss + # ynh_exec_warn_less ynh_exec_as $app env "PATH=$python_path" cmake -B build . -DFAISS_ENABLE_GPU=OFF -DFAISS_ENABLE_PYTHON=ON -DFAISS_OPT_LEVEL=generic + # ynh_exec_warn_less ynh_exec_as $app env "PATH=$python_path" make -C build -j faiss + # ynh_exec_warn_less ynh_exec_as $app env "PATH=$python_path" make -C build -j swigfaiss # cd "build/faiss/python" - # sudo -u $app env "PATH=$python_path" python setup.py install + # ynh_exec_warn_less ynh_exec_as $app env "PATH=$python_path" python setup.py install #popd sed -i "/spacy==2.3.2/d" "$backend_path/requirements.txt" sed -i "/sklearn==0.0/d" "$backend_path/requirements.txt" @@ -82,15 +83,15 @@ function set_up_backend { sed -i "s/Pillow==8.1.0/Pillow>=8.1.2/" "$backend_path/requirements.txt" sed -i "/faiss-cpu==1.7.0/d" "$backend_path/requirements.txt" else - sudo -u $app env "PATH=$python_path" pip --cache-dir "$cache_dir" install -U torch==1.8.0+cpu torchvision==0.9.0+cpu -f https://download.pytorch.org/whl/torch_stable.html 2>&1 + ynh_exec_warn_less ynh_exec_as $app env "PATH=$python_path" pip --cache-dir "$cache_dir" install -U torch==1.8.0+cpu torchvision==0.9.0+cpu -f https://download.pytorch.org/whl/torch_stable.html fi pushd "$backend_path/dlib" - sudo -u $app env "PATH=$python_path" python setup.py install 2>&1 + ynh_exec_warn_less ynh_exec_as $app env "PATH=$python_path" python setup.py install popd - sudo -u $app env "PATH=$python_path" pip --cache-dir "$cache_dir" install -U --requirement "$backend_path/requirements.txt" 2>&1 - sudo -u $app env "PATH=$python_path" pip --cache-dir "$cache_dir" install -U --requirement "$backend_path/requirements-ynh.txt" 2>&1 - #if [ "$arch" = "arm64" ] || [ "$arm64_test" -eq 1 ]; then - #sudo -u $app unzip "$CONDA_DIR/lib/python3.8/site-packages/"faiss*.egg -d "$CONDA_DIR/lib/python3.8/site-packages/" + ynh_exec_warn_less ynh_exec_as $app env "PATH=$python_path" pip --cache-dir "$cache_dir" install -U --requirement "$backend_path/requirements.txt" + ynh_exec_warn_less ynh_exec_as $app env "PATH=$python_path" pip --cache-dir "$cache_dir" install -U --requirement "$backend_path/requirements-ynh.txt" + #if [ "$YNH_ARCH" = "arm64" ] || [ "$arm64_test" -eq 1 ]; then + #ynh_exec_warn_less ynh_exec_as $app unzip "$CONDA_DIR/lib/python3.8/site-packages/"faiss*.egg -d "$CONDA_DIR/lib/python3.8/site-packages/" #fi chown -R root:root "$backend_path" popd @@ -98,14 +99,14 @@ function set_up_backend { function install_dlib { pushd "$backend_path/dlib" - sudo -u $app "$backend_path/venv/bin/python" setup.py install 2>&1 + ynh_exec_warn_less ynh_exec_as $app "$backend_path/venv/bin/python" setup.py install popd } function set_node_vars { - ynh_exec_warn_less ynh_install_nodejs --nodejs_version=13 + ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version ynh_use_nodejs - node_PATH=$nodejs_path:$(sudo -u $app sh -c 'echo $PATH') + node_PATH=$nodejs_path:$(ynh_exec_warn_less ynh_exec_as $app sh -c 'echo $PATH') } @@ -114,10 +115,10 @@ function set_up_frontend { frontend_path=$final_path/frontend pushd $final_path/frontend chown -R $app:$app $frontend_path - sudo -u $app touch $frontend_path/.yarnrc - sudo -u $app env "PATH=$node_PATH" yarn --cache-folder $frontend_path/yarn-cache --use-yarnrc $frontend_path/.yarnrc install 2>&1 - sudo -u $app env "PATH=$node_PATH" yarn --cache-folder $frontend_path/yarn-cache --use-yarnrc $frontend_path/.yarnrc run build 2>&1 - sudo -u $app env "PATH=$node_PATH" yarn --cache-folder $frontend_path/yarn-cache --use-yarnrc $frontend_path/.yarnrc add serve 2>&1 + ynh_exec_warn_less ynh_exec_as $app touch $frontend_path/.yarnrc + ynh_exec_warn_less ynh_exec_as $app env "PATH=$node_PATH" yarn --cache-folder $frontend_path/yarn-cache --use-yarnrc $frontend_path/.yarnrc install --legacy-peer-deps + ynh_exec_warn_less ynh_exec_as $app env "PATH=$node_PATH" yarn --cache-folder $frontend_path/yarn-cache --use-yarnrc $frontend_path/.yarnrc run build + ynh_exec_warn_less ynh_exec_as $app env "PATH=$node_PATH" yarn --cache-folder $frontend_path/yarn-cache --use-yarnrc $frontend_path/.yarnrc add serve chown -R root:root $frontend_path popd } @@ -137,14 +138,14 @@ function upgrade_db { pushd "$final_path/backend" chown -R $app:$app "$final_path/backend" chown -R $app:$app "/var/log/$app" - sudo -u $app bash -c " + ynh_exec_warn_less ynh_exec_as $app bash -c " set -a export PATH=\"$path_prefix:"'$PATH'"\" source \"$final_path\"/librephotos.env python3 manage.py showmigrations python3 manage.py migrate python3 manage.py showmigrations - " 2>&1 + " popd set_permissions } diff --git a/scripts/backup b/scripts/backup index 15f5000..0a55cf4 100755 --- a/scripts/backup +++ b/scripts/backup @@ -15,7 +15,7 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - ynh_clean_check_starting + true } # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -43,6 +43,12 @@ ynh_print_info --message="Declaring files to be backed up..." ynh_backup --src_path="$final_path" +#================================================= +# BACKUP THE DATA DIR +#================================================= + +ynh_backup --src_path="$data_path" --is_big + #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= @@ -71,7 +77,6 @@ ynh_backup --src_path="/etc/systemd/system/$app-worker.service" #================================================= ynh_backup --src_path="/var/log/$app" -ynh_backup --src_path="$data_path" --is_big #================================================= # BACKUP THE POSTGRESQL DATABASE @@ -83,4 +88,5 @@ ynh_psql_dump_db --database="$db_name" > db.sql #================================================= # END OF SCRIPT #================================================= + ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/install b/scripts/install index 8603703..13b3cdd 100755 --- a/scripts/install +++ b/scripts/install @@ -12,6 +12,7 @@ source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= + ynh_clean_setup () { ynh_clean_check_starting } @@ -24,9 +25,10 @@ ynh_abort_if_errors domain=$YNH_APP_ARG_DOMAIN path_url="/" -admin=$YNH_APP_ARG_ADMIN is_public=$YNH_APP_ARG_IS_PUBLIC +admin=$YNH_APP_ARG_ADMIN allow_multimedia_write=$YNH_APP_ARG_ALLOW_MULTIMEDIA_WRITE + app=$YNH_APP_INSTANCE_NAME #================================================= @@ -78,6 +80,14 @@ ynh_script_progression --message="Installing dependencies..." --weight=5 ynh_install_app_dependencies $pkg_dependencies ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Configuring system user..." --weight=1 + +# Create a system user +ynh_system_user_create --username=$app --home_dir=$data_path + #================================================= # CREATE A POSTGRESQL DATABASE #================================================= @@ -102,15 +112,7 @@ unpack_source ynh_script_progression --message="Configuring NGINX web server..." --weight=1 # Create a dedicated NGINX config -ynh_add_nginx_config backend_port - -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." --weight=1 - -# Create a system user -ynh_system_user_create --username=$app --home_dir=$data_path +ynh_add_nginx_config #================================================= # SPECIFIC SETUP @@ -155,15 +157,15 @@ upgrade_db pushd "$final_path/backend" admin_mail="$(ynh_user_get_info $admin 'mail')" - sudo -u $app bash -c " + ynh_exec_warn_less ynh_exec_as $app bash -c " set -a export PATH=\"$path_prefix:"'$PATH'"\" source \"$final_path\"/librephotos.env python3 manage.py createsuperuser --noinput --username \"$admin\" --email \"$admin_mail\" - " 2>&1 + " for user in $(ynh_user_list); do mail=$(ynh_user_get_info --username="$user" --key=mail) - sudo -u $app bash -c " + ynh_exec_warn_less ynh_exec_as $app bash -c " set -a export PATH=\"$path_prefix:"'$PATH'"\" source \"$final_path\"/librephotos.env @@ -177,7 +179,7 @@ try: user.save() except User.DoesNotExist: User.objects.create_user('$user', email='$mail', scan_directory='/home/yunohost.multimedia/$user/Picture') -" 2>&1 +" done popd @@ -192,8 +194,6 @@ if [ $allow_multimedia_write -eq 1 ]; then ynh_multimedia_addaccess $app fi -#================================================= -# GENERIC FINALIZATION #================================================= # SECURE FILES AND DIRECTORIES #================================================= @@ -201,6 +201,8 @@ fi # Set permissions to app files set_permissions +#================================================= +# GENERIC FINALIZATION #================================================= # SETUP LOGROTATE #================================================= @@ -254,4 +256,5 @@ ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= + ynh_script_progression --message="Installation of $app completed" --last diff --git a/scripts/remove b/scripts/remove index e2cbdf3..df960a8 100755 --- a/scripts/remove +++ b/scripts/remove @@ -29,8 +29,6 @@ data_path=$(ynh_app_setting_get --app=$app --key=data_path) # REMOVE SERVICE INTEGRATION IN YUNOHOST #================================================= -ynh_script_progression --message="Removing $app services integration..." --weight=1 - # 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-backend >/dev/null ; then yunohost service remove $app-backend @@ -59,6 +57,14 @@ ynh_remove_systemd_config --service="$app-frontend" ynh_remove_systemd_config --service="$app-image-similarity" ynh_remove_systemd_config --service="$app-worker" +#================================================= +# REMOVE LOGROTATE CONFIGURATION +#================================================= +ynh_script_progression --message="Removing logrotate configuration..." --weight=1 + +# Remove the app-specific logrotate config +ynh_remove_logrotate + #================================================= # REMOVE THE POSTGRESQL DATABASE #================================================= @@ -67,14 +73,6 @@ ynh_script_progression --message="Removing the PostgreSQL database..." --weight= # Remove a database if it exists, along with the associated user ynh_psql_remove_db --db_user=$db_user --db_name=$db_name -#================================================= -# REMOVE DEPENDENCIES -#================================================= -ynh_script_progression --message="Removing dependencies..." --weight=30 - -# Remove metapackage and its dependencies -ynh_remove_app_dependencies - #================================================= # REMOVE APP MAIN DIR #================================================= @@ -100,18 +98,12 @@ ynh_script_progression --message="Removing NGINX web server configuration..." -- ynh_remove_nginx_config #================================================= -# REMOVE LOGROTATE CONFIGURATION +# REMOVE DEPENDENCIES #================================================= -ynh_script_progression --message="Removing logrotate configuration..." --weight=1 - -# Remove the app-specific logrotate config -ynh_remove_logrotate - -#================================================= -# REMOVE NODE -#================================================= -ynh_script_progression --message="Removing Node.js..." --weight=1 +ynh_script_progression --message="Removing dependencies..." --weight=30 +# Remove metapackage and its dependencies +ynh_remove_app_dependencies ynh_remove_nodejs #================================================= @@ -136,4 +128,5 @@ ynh_system_user_delete --username=$app #================================================= # END OF SCRIPT #================================================= + ynh_script_progression --message="Removal of $app completed" --last diff --git a/scripts/restore b/scripts/restore index 6c6e656..f081d7b 100755 --- a/scripts/restore +++ b/scripts/restore @@ -39,14 +39,11 @@ port=$(ynh_app_setting_get --app=$app --key=port) backend_port=$(ynh_app_setting_get --app=$app --key=port) similarity_port=$(ynh_app_setting_get --app=$app --key=similarity_port) - #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= ynh_script_progression --message="Validating restoration parameters..." --weight=1 -ynh_webpath_available --domain=$domain --path_url=$path_url \ - || ynh_die --message="Path not available: ${domain}${path_url}" test ! -d $final_path \ || ynh_die --message="There is already a directory: $final_path " @@ -56,10 +53,12 @@ test ! -d $data_path \ #================================================= # STANDARD RESTORATION STEPS #================================================= -# RESTORE THE NGINX CONFIGURATION +# RECREATE THE DEDICATED USER #================================================= +ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" +# Create the dedicated user (if not existing) +ynh_system_user_create --username=$app --home_dir=$data_path #================================================= # RESTORE THE APP MAIN DIR @@ -69,9 +68,9 @@ ynh_script_progression --message="Restoring the app main directory..." --weight= ynh_restore_file --origin_path="$final_path" #================================================= -# RESTORE THE APP DATA DIR +# RESTORE THE DATA DIRECTORY #================================================= -ynh_script_progression --message="Restoring the app data directory..." --weight=1 +ynh_script_progression --message="Restoring the data directory..." --weight=1 ynh_restore_file --origin_path="$data_path" --not_mandatory mkdir -p $data_path/protected_media/{thumbnails_big,square_thumbnails,square_thumbnails_small,faces} @@ -80,25 +79,14 @@ mkdir -p $data_path/matplotlib ln -s $final_path/data_models $data_path/data_models #================================================= -# RECREATE THE DEDICATED USER -#================================================= -ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 - -# Create the dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir=$data_path - -#================================================= -# RESTORE VARIOUS FILES +# RESTORE USER RIGHTS #================================================= -ynh_restore_file --origin_path="/var/log/$app" +# Restore permissions on app files +set_permissions #================================================= -# RESTORE THE LOGROTATE CONFIGURATION -#================================================= - -ynh_restore_file --origin_path="/etc/logrotate.d/$app" - +# SPECIFIC RESTORATION #================================================= # REINSTALL DEPENDENCIES #================================================= @@ -109,11 +97,18 @@ ynh_install_app_dependencies $pkg_dependencies ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" #================================================= -# RESTORE USER RIGHTS +# RESTORE NODE.JS #================================================= +ynh_script_progression --message="Restoring Node.js..." --weight=1 -# Restore permissions on app files -set_permissions +set_node_vars + +#================================================= +# RESTORE THE NGINX CONFIGURATION +#================================================= +ynh_script_progression --message="Restoring the NGINX web server configuration..." + +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # SPECIFIC RESTORATION @@ -127,11 +122,21 @@ ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql #================================================= -# RESTORE NODE.JS +# RESTORE VARIOUS FILES #================================================= -ynh_script_progression --message="Restoring Node.js..." --weight=1 -set_node_vars +ynh_restore_file --origin_path="/var/log/$app" + +#================================================= +# YUNOHOST MULTIMEDIA INTEGRATION +#================================================= +ynh_script_progression --message="Adding multimedia directories..." --weight=1 + +# Build YunoHost multimedia directories +ynh_multimedia_build_main_dir +if [ $allow_multimedia_write -eq 1 ]; then + ynh_multimedia_addaccess $app +fi #================================================= # RESTORE SYSTEMD @@ -147,6 +152,13 @@ systemctl enable $app-image-similarity.service --quiet ynh_restore_file --origin_path="/etc/systemd/system/$app-worker.service" systemctl enable $app-worker.service --quiet +#================================================= +# RESTORE THE LOGROTATE CONFIGURATION +#================================================= +ynh_script_progression --message="Restoring the logrotate configuration..." + +ynh_restore_file --origin_path="/etc/logrotate.d/$app" + #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= @@ -167,17 +179,6 @@ ynh_systemd_action --service_name=$app-frontend --action="start" --log_path="sys ynh_systemd_action --service_name=$app-image-similarity --action="start" --log_path="/var/log/$app/image_similarity.log" ynh_systemd_action --service_name=$app-worker --action="start" --log_path="/var/log/$app/$app-worker.log" -#================================================= -# YUNOHOST MULTIMEDIA INTEGRATION -#================================================= -ynh_script_progression --message="Adding multimedia directories..." --weight=1 - -# Build YunoHost multimedia directories -ynh_multimedia_build_main_dir -if [ $allow_multimedia_write -eq 1 ]; then - ynh_multimedia_addaccess $app -fi - #================================================= # GENERIC FINALIZATION #================================================= @@ -190,4 +191,5 @@ ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= + ynh_script_progression --message="Restoration completed for $app" --last diff --git a/scripts/upgrade b/scripts/upgrade index 3339bde..6c06c4e 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -18,9 +18,9 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) +language=$(ynh_app_setting_get --app=$app --key=language) admin=$(ynh_app_setting_get --app=$app --key=admin) final_path=$(ynh_app_setting_get --app=$app --key=final_path) -language=$(ynh_app_setting_get --app=$app --key=language) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) @@ -33,6 +33,7 @@ allow_multimedia_write=$(ynh_app_setting_get --app=$app --key=allow_multimedia_w #================================================= # CHECK VERSION #================================================= +ynh_script_progression --message="Checking version..." upgrade_type=$(ynh_check_app_version_changed) @@ -44,6 +45,7 @@ ynh_script_progression --message="Backing up the app before upgrading (may take # 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 } @@ -73,6 +75,14 @@ if [ "$nodejs_version" -eq 10 ]; then ynh_remove_nodejs fi +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 + +# Create a dedicated user (if not existing) +ynh_system_user_create --username=$app --home_dir=$data_path + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -82,14 +92,6 @@ then unpack_source fi -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1 - -# Create a dedicated NGINX config -ynh_add_nginx_config backend_port - #================================================= # UPGRADE DEPENDENCIES #================================================= @@ -99,12 +101,12 @@ ynh_install_app_dependencies $pkg_dependencies ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" #================================================= -# CREATE DEDICATED USER +# NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 +ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1 -# Create a dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir=$data_path +# Create a dedicated NGINX config +ynh_add_nginx_config backend_port #================================================= # SPECIFIC UPGRADE @@ -122,17 +124,6 @@ ynh_script_progression --message="Setting up frontend..." --weight=5 set_up_frontend -#================================================= -# SETUP SYSTEMD -#================================================= -ynh_script_progression --message="Upgrading systemd configurations..." --weight=1 - -# Create dedicated systemd configs -ynh_add_systemd_config --service=$app-backend --template=backend.service -ynh_add_systemd_config --service=$app-frontend --template=frontend.service -ynh_add_systemd_config --service=$app-image-similarity --template=image-similarity.service -ynh_add_systemd_config --service=$app-worker --template=worker.service - #================================================= # ADD CONFIGURATIONS #================================================= @@ -147,6 +138,13 @@ ynh_script_progression --message="Finalizing database..." --weight=1 upgrade_db +#================================================= +# SECURE FILES AND DIRECTORIES +#================================================= + +# Set permissions to app files +set_permissions + #================================================= # YUNOHOST MULTIMEDIA INTEGRATION #================================================= @@ -158,15 +156,19 @@ if [ $allow_multimedia_write -eq 1 ]; then ynh_multimedia_addaccess $app fi +#================================================= +# SETUP SYSTEMD +#================================================= +ynh_script_progression --message="Upgrading systemd configurations..." --weight=1 + +# Create dedicated systemd configs +ynh_add_systemd_config --service=$app-backend --template=backend.service +ynh_add_systemd_config --service=$app-frontend --template=frontend.service +ynh_add_systemd_config --service=$app-image-similarity --template=image-similarity.service +ynh_add_systemd_config --service=$app-worker --template=worker.service + #================================================= # GENERIC FINALIZATION -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= - -# Set permissions to app files -set_permissions - #================================================= # SETUP LOGROTATE #================================================= @@ -206,4 +208,5 @@ ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= + ynh_script_progression --message="Upgrade of $app completed" --last diff --git a/sources/patches/backend-01-image_similarity-main.py.patch b/sources/patches/backend-01-image_similarity-main.py.patch index eef02fb..9dcf7cd 100644 --- a/sources/patches/backend-01-image_similarity-main.py.patch +++ b/sources/patches/backend-01-image_similarity-main.py.patch @@ -2,21 +2,11 @@ diff --git a/image_similarity/main.py b/image_similarity/main.py index 9ca6660..9a33d98 100644 --- a/image_similarity/main.py +++ b/image_similarity/main.py -@@ -7,6 +7,8 @@ from retrieval_index import RetrievalIndex +@@ -58,6 +58,6 @@ - from utils import logger - -+import os -+ - app = Flask(__name__) - api = Api(app) - -@@ -48,7 +50,7 @@ api.add_resource(SearchIndex,'/search/') - - if __name__ == '__main__': - logger.info('starting server') -- server = WSGIServer(('0.0.0.0', 8002), app) -+ server = WSGIServer(('0.0.0.0', int(os.environ['IMAGE_SIMILARITY_SERVER_PORT'])), app) + if __name__ == "__main__": + logger.info("starting server") +- server = WSGIServer(("0.0.0.0", 8002), app) ++ server = WSGIServer(("0.0.0.0", int(os.environ['IMAGE_SIMILARITY_SERVER_PORT'])), app) server_thread = gevent.spawn(server.serve_forever) gevent.joinall([server_thread]) -