diff --git a/README.md b/README.md index d253d8c..079735d 100644 --- a/README.md +++ b/README.md @@ -19,18 +19,12 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in pgAdmin is a feature rich Open Source administration and development platform for PostgreSQL. -**Shipped version:** 7.7~ynh1 +**Shipped version:** 8.2~ynh2 ## Screenshots ![Screenshot of pgAdmin4](./doc/screenshots/pgadmin4-welcome-light.png) -## Disclaimers / important information - -### Multi-users support - -This app actually don't support the SSO and don't support LDAP. After the install of the app you can create a other user. So this app is multi-users but independently of the LDAP database. - ## Documentation and resources * Official app website: diff --git a/README_fr.md b/README_fr.md index 59b39a1..2da0f15 100644 --- a/README_fr.md +++ b/README_fr.md @@ -19,18 +19,12 @@ Si vous n’avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) po pgAdmin is a feature rich Open Source administration and development platform for PostgreSQL. -**Version incluse :** 7.7~ynh1 +**Version incluse :** 8.2~ynh2 ## Captures d’écran ![Capture d’écran de pgAdmin4](./doc/screenshots/pgadmin4-welcome-light.png) -## Avertissements / informations importantes - -### Multi-users support - -This app actually don't support the SSO and don't support LDAP. After the install of the app you can create a other user. So this app is multi-users but independently of the LDAP database. - ## Documentations et ressources * Site officiel de l’app : diff --git a/check_process b/check_process deleted file mode 100644 index b42cec3..0000000 --- a/check_process +++ /dev/null @@ -1,22 +0,0 @@ -;; Test complet - ; Manifest - domain="domain.tld" - path="/path" - admin="john" - password="1Strong-Password" - ; Checks - pkg_linter=1 - setup_sub_dir=1 - setup_root=1 - setup_nourl=0 - setup_private=0 - setup_public=0 - upgrade=1 - backup_restore=1 - multi_instance=0 - port_already_use=0 - change_url=1 -;;; Options -Email= -Notification=none -;;; Upgrade options diff --git a/conf/armv7_bookworm.src b/conf/armv7_bookworm.src deleted file mode 100644 index 27506b0..0000000 --- a/conf/armv7_bookworm.src +++ /dev/null @@ -1,11 +0,0 @@ -SOURCE_URL=https://github.com/Josue-T/pgadmin_python_build/releases/download/v4-7.7/pgadmin_4-7.7-bookworm-bin1_armv7l.tar.gz -SOURCE_SUM=e18206853ced73eb1922182c5a3c825d8af21d5e40fcd607311cc4e075a28e72 -# (Optional) Program to check the integrity (sha256sum, md5sum...) -# default: sha256 -SOURCE_SUM_PRG=sha256sum -# (Optional) Archive format -# default: tar.gz -SOURCE_FORMAT=tar.gz -# (Optional) Put false if sources are directly in the archive root -# default: true -SOURCE_IN_SUBDIR=true diff --git a/conf/armv7_bullseye.src b/conf/armv7_bullseye.src deleted file mode 100644 index 3095133..0000000 --- a/conf/armv7_bullseye.src +++ /dev/null @@ -1,11 +0,0 @@ -SOURCE_URL=https://github.com/Josue-T/pgadmin_python_build/releases/download/v4-7.7/pgadmin_4-7.7-bullseye-bin1_armv7l.tar.gz -SOURCE_SUM=76022eeab9c985a30dab8b24027db095f74eb491077de01db77100e320b4a2e5 -# (Optional) Program to check the integrity (sha256sum, md5sum...) -# default: sha256 -SOURCE_SUM_PRG=sha256sum -# (Optional) Archive format -# default: tar.gz -SOURCE_FORMAT=tar.gz -# (Optional) Put false if sources are directly in the archive root -# default: true -SOURCE_IN_SUBDIR=true diff --git a/conf/config_local.py b/conf/config_local.py index bad0b92..40da066 100644 --- a/conf/config_local.py +++ b/conf/config_local.py @@ -1 +1,5 @@ -DESKTOP_USER = '__USER__@__DOMAIN__' \ No newline at end of file +#!/usr/bin/env python3 + +DESKTOP_USER = '__APP__@__DOMAIN__' + +DATA_DIR = '__INSTALL_DIR__/data' diff --git a/conf/requirement_bookworm.txt b/conf/requirement_bookworm.txt deleted file mode 100644 index 40c04ed..0000000 --- a/conf/requirement_bookworm.txt +++ /dev/null @@ -1,107 +0,0 @@ -alembic==1.12.0 -Authlib==1.2.1 -azure-common==1.1.28 -azure-core==1.29.4 -azure-identity==1.13.0 -azure-mgmt-core==1.4.0 -azure-mgmt-rdbms==10.1.0 -azure-mgmt-resource==23.0.1 -azure-mgmt-subscription==3.1.1 -Babel==2.12.1 -bcrypt==4.0.1 -bidict==0.22.1 -blinker==1.6.2 -boto3==1.28.52 -botocore==1.31.52 -Brotli==1.1.0 -cachetools==5.3.1 -certifi==2023.7.22 -cffi==1.15.1 -charset-normalizer==3.2.0 -click==8.1.7 -cryptography==41.0.4 -dnspython==2.4.2 -email-validator==2.0.0.post2 -eventlet==0.33.3 -Flask==2.2.5 -flask-babel==3.1.0 -Flask-Compress==1.14 -Flask-Gravatar==0.5.0 -Flask-Login==0.6.2 -Flask-Mail==0.9.1 -Flask-Migrate==4.0.5 -Flask-Paranoid==0.3.0 -Flask-Principal==0.4.0 -Flask-Security-Too==5.1.2 -Flask-SocketIO==5.3.6 -Flask-SQLAlchemy==3.0.5 -Flask-WTF==1.1.1 -google-api-core==2.11.1 -google-api-python-client==2.100.0 -google-auth==2.23.0 -google-auth-httplib2==0.1.1 -google-auth-oauthlib==1.0.0 -googleapis-common-protos==1.60.0 -greenlet==2.0.2 -h11==0.14.0 -httpagentparser==1.9.5 -httplib2==0.22.0 -idna==3.4 -importlib-metadata==6.8.0 -isodate==0.6.1 -itsdangerous==2.1.2 -jaraco.classes==3.3.0 -jeepney==0.8.0 -Jinja2==3.1.2 -jmespath==1.0.1 -keyring==23.13.1 -ldap3==2.9.1 -Mako==1.2.4 -MarkupSafe==2.1.3 -more-itertools==10.1.0 -msal==1.24.0 -msal-extensions==1.0.0 -msrest==0.7.1 -oauthlib==3.2.2 -paramiko==3.3.1 -passlib==1.7.4 -pgadmin4==7.7 -Pillow==9.5.0 -portalocker==2.8.2 -protobuf==4.24.3 -psutil==5.9.5 -psycopg==3.1.9 -psycopg-c==3.1.9 -pyasn1==0.5.0 -pyasn1-modules==0.3.0 -pycparser==2.21 -PyJWT==2.8.0 -PyNaCl==1.5.0 -pyotp==2.9.0 -pyparsing==3.1.1 -pypng==0.20220715.0 -python-dateutil==2.8.2 -python-engineio==4.7.1 -python-socketio==5.9.0 -pytz==2023.3.post1 -qrcode==7.4.2 -requests==2.31.0 -requests-oauthlib==1.3.1 -rsa==4.9 -s3transfer==0.6.2 -SecretStorage==3.3.3 -simple-websocket==0.10.1 -six==1.16.0 -speaklater3==1.4 -SQLAlchemy==2.0.21 -sqlparse==0.4.4 -sshtunnel==0.4.0 -typing_extensions==4.8.0 -ua-parser==0.18.0 -uritemplate==4.1.1 -urllib3==1.26.16 -user-agents==2.2.0 -Werkzeug==2.2.3 -wsproto==1.2.0 -WTForms==3.0.1 -zipp==3.17.0 diff --git a/conf/requirement_bullseye.txt b/conf/requirement_bullseye.txt deleted file mode 100644 index 1c8e668..0000000 --- a/conf/requirement_bullseye.txt +++ /dev/null @@ -1,108 +0,0 @@ -alembic==1.12.0 -Authlib==1.2.1 -azure-common==1.1.28 -azure-core==1.29.4 -azure-identity==1.13.0 -azure-mgmt-core==1.4.0 -azure-mgmt-rdbms==10.1.0 -azure-mgmt-resource==23.0.1 -azure-mgmt-subscription==3.1.1 -Babel==2.12.1 -bcrypt==4.0.1 -bidict==0.22.1 -blinker==1.6.2 -boto3==1.28.52 -botocore==1.31.52 -Brotli==1.1.0 -cachetools==5.3.1 -certifi==2023.7.22 -cffi==1.15.1 -charset-normalizer==3.2.0 -click==8.1.7 -cryptography==41.0.4 -dnspython==2.4.2 -email-validator==2.0.0.post2 -eventlet==0.33.3 -Flask==2.2.5 -flask-babel==3.1.0 -Flask-Compress==1.14 -Flask-Gravatar==0.5.0 -Flask-Login==0.6.2 -Flask-Mail==0.9.1 -Flask-Migrate==4.0.5 -Flask-Paranoid==0.3.0 -Flask-Principal==0.4.0 -Flask-Security-Too==5.1.2 -Flask-SocketIO==5.3.6 -Flask-SQLAlchemy==3.0.5 -Flask-WTF==1.1.1 -google-api-core==2.11.1 -google-api-python-client==2.100.0 -google-auth==2.23.0 -google-auth-httplib2==0.1.1 -google-auth-oauthlib==1.0.0 -googleapis-common-protos==1.60.0 -greenlet==1.1.2 -h11==0.14.0 -httpagentparser==1.9.5 -httplib2==0.22.0 -idna==3.4 -importlib-metadata==6.8.0 -isodate==0.6.1 -itsdangerous==2.1.2 -jaraco.classes==3.3.0 -jeepney==0.8.0 -Jinja2==3.1.2 -jmespath==1.0.1 -keyring==23.13.1 -ldap3==2.9.1 -Mako==1.2.4 -MarkupSafe==2.1.3 -more-itertools==10.1.0 -msal==1.24.0 -msal-extensions==1.0.0 -msrest==0.7.1 -oauthlib==3.2.2 -paramiko==3.3.1 -passlib==1.7.4 -pgadmin4==7.7 -Pillow==9.5.0 -pkg_resources==0.0.0 -portalocker==2.8.2 -protobuf==4.24.3 -psutil==5.9.5 -psycopg==3.1.9 -psycopg-c==3.1.9 -pyasn1==0.5.0 -pyasn1-modules==0.3.0 -pycparser==2.21 -PyJWT==2.8.0 -PyNaCl==1.5.0 -pyotp==2.9.0 -pyparsing==3.1.1 -pypng==0.20220715.0 -python-dateutil==2.8.2 -python-engineio==4.7.1 -python-socketio==5.9.0 -pytz==2023.3.post1 -qrcode==7.4.2 -requests==2.31.0 -requests-oauthlib==1.3.1 -rsa==4.9 -s3transfer==0.6.2 -SecretStorage==3.3.3 -simple-websocket==0.10.1 -six==1.16.0 -speaklater3==1.4 -SQLAlchemy==2.0.21 -sqlparse==0.4.4 -sshtunnel==0.4.0 -typing_extensions==4.8.0 -ua-parser==0.18.0 -uritemplate==4.1.1 -urllib3==1.26.16 -user-agents==2.2.0 -Werkzeug==2.2.3 -wsproto==1.2.0 -WTForms==3.0.1 -zipp==3.17.0 diff --git a/conf/server.json b/conf/server.json new file mode 100644 index 0000000..e30fa78 --- /dev/null +++ b/conf/server.json @@ -0,0 +1,18 @@ +{ + "Servers": { + "1": { + "Name": "YunoHost Server", + "Group": "Servers", + "Host": "localhost", + "Port": 5432, + "MaintenanceDB": "postgres", + "Username": "__DB_USER__", + "Shared": false, + "KerberosAuthentication": false, + "ConnectionParameters": { + "sslmode": "prefer", + "connect_timeout": 10 + } + } + } +} diff --git a/conf/setup.exp b/conf/setup.exp old mode 100644 new mode 100755 index 9cec340..2338cae --- a/conf/setup.exp +++ b/conf/setup.exp @@ -2,20 +2,19 @@ set timeout 20 set cmd [lindex $argv 0] -set path [lindex $argv 1] -set user [lindex $argv 2] +set arguments [lrange $argv 1 end] -spawn $cmd $path +spawn $cmd {*}$arguments expect "Email address:" -send "$user\r"; +send "__EMAIL__\r"; expect "Password:" -send {__ADMIN_PASSWORD__}; +send {__PASSWORD__}; send "\r"; expect "Retype password:" -send {__ADMIN_PASSWORD__}; +send {__PASSWORD__}; send "\r"; interact diff --git a/conf/uwsgi.ini b/conf/uwsgi.ini index a202330..02be2d0 100644 --- a/conf/uwsgi.ini +++ b/conf/uwsgi.ini @@ -16,12 +16,12 @@ plugin = python3 # Manage the subpath manage-script-name = true -mount = __PATH__=pgAdmin4.py +mount = __PATH__=pgAdmin4.py # Virtualenv and python path -virtualenv = __FINALPATH__ -pythonpath = __FINALPATH__ -chdir = __FINALPATH__/lib/python__PYTHON_VERSION__/site-packages/pgadmin4 +virtualenv = __INSTALL_DIR__/venv +pythonpath = __INSTALL_DIR__/venv +chdir = __INSTALL_DIR__/venv/lib/python__PYTHON_VERSION__/site-packages/pgadmin4 # The variable holding flask application callable = app diff --git a/conf/virtualenv_activate b/conf/virtualenv_activate deleted file mode 100644 index 6aea9b1..0000000 --- a/conf/virtualenv_activate +++ /dev/null @@ -1,78 +0,0 @@ -# This file must be used with "source bin/activate" *from bash* -# you cannot run it directly - -deactivate () { - unset -f pydoc >/dev/null 2>&1 - - # reset old environment variables - # ! [ -z ${VAR+_} ] returns true if VAR is declared at all - if ! [ -z "${_OLD_VIRTUAL_PATH+_}" ] ; then - PATH="$_OLD_VIRTUAL_PATH" - export PATH - unset _OLD_VIRTUAL_PATH - fi - if ! [ -z "${_OLD_VIRTUAL_PYTHONHOME+_}" ] ; then - PYTHONHOME="$_OLD_VIRTUAL_PYTHONHOME" - export PYTHONHOME - unset _OLD_VIRTUAL_PYTHONHOME - fi - - # This should detect bash and zsh, which have a hash command that must - # be called to get it to forget past commands. Without forgetting - # past commands the $PATH changes we made may not be respected - if [ -n "${BASH-}" ] || [ -n "${ZSH_VERSION-}" ] ; then - hash -r 2>/dev/null - fi - - if ! [ -z "${_OLD_VIRTUAL_PS1+_}" ] ; then - PS1="$_OLD_VIRTUAL_PS1" - export PS1 - unset _OLD_VIRTUAL_PS1 - fi - - unset VIRTUAL_ENV - if [ ! "${1-}" = "nondestructive" ] ; then - # Self destruct! - unset -f deactivate - fi -} - -# unset irrelevant variables -deactivate nondestructive - -VIRTUAL_ENV="/opt/yunohost/pgadmin" -export VIRTUAL_ENV - -_OLD_VIRTUAL_PATH="$PATH" -PATH="$VIRTUAL_ENV/bin:$PATH" -export PATH - -# unset PYTHONHOME if set -if ! [ -z "${PYTHONHOME+_}" ] ; then - _OLD_VIRTUAL_PYTHONHOME="$PYTHONHOME" - unset PYTHONHOME -fi - -if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT-}" ] ; then - _OLD_VIRTUAL_PS1="$PS1" - if [ "x" != x ] ; then - PS1="$PS1" - else - PS1="(`basename \"$VIRTUAL_ENV\"`) $PS1" - fi - export PS1 -fi - -# Make sure to unalias pydoc if it's already there -alias pydoc 2>/dev/null >/dev/null && unalias pydoc - -pydoc () { - python -m pydoc "$@" -} - -# This should detect bash and zsh, which have a hash command that must -# be called to get it to forget past commands. Without forgetting -# past commands the $PATH changes we made may not be respected -if [ -n "${BASH-}" ] || [ -n "${ZSH_VERSION-}" ] ; then - hash -r 2>/dev/null -fi diff --git a/doc/ADMIN.md b/doc/ADMIN.md new file mode 100644 index 0000000..0b5199f --- /dev/null +++ b/doc/ADMIN.md @@ -0,0 +1,4 @@ +The Postgresql admin user credentials: + +Username: __DB_USER__ +Password: __DB_PWD__ diff --git a/doc/DISCLAIMER.md b/doc/DISCLAIMER.md deleted file mode 100644 index 9f6167c..0000000 --- a/doc/DISCLAIMER.md +++ /dev/null @@ -1,3 +0,0 @@ -### Multi-users support - -This app actually don't support the SSO and don't support LDAP. After the install of the app you can create a other user. So this app is multi-users but independently of the LDAP database. diff --git a/doc/POST_INSTALL.md b/doc/POST_INSTALL.md new file mode 100644 index 0000000..a0e8170 --- /dev/null +++ b/doc/POST_INSTALL.md @@ -0,0 +1,5 @@ +You can connect to pgAdmin with your email and the password you provided at installation time. + +You will need to provide the Postgresql admin password once, so here it is: `__DB_PWD__`. + +pgAdmin will then store it encrypted, so you won't need anymore. diff --git a/doc/POST_UPGRADE.d/7.7~ynh2.md b/doc/POST_UPGRADE.d/7.7~ynh2.md new file mode 100644 index 0000000..0b49770 --- /dev/null +++ b/doc/POST_UPGRADE.d/7.7~ynh2.md @@ -0,0 +1,5 @@ +This upgrade fixes authentication with PostgreSQL. + +You might need to re-enter in pgAdmin the Postgresql admin password: `__DB_PWD__`. + +You can log into pgAdmin with your email and the password you provided during installation. diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 08855ed..0000000 --- a/manifest.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "name": "pgAdmin4", - "id": "pgadmin", - "packaging_format": 1, - "description": { - "en": "Manage PostgreSQL databases over the web", - "fr": "Application web de gestion des bases de données PostgreSQL" - }, - "version": "7.7~ynh1", - "url": "https://www.pgadmin.org", - "upstream": { - "license": "PostgreSQL", - "website": "https://www.pgadmin.org", - "admindoc": "https://www.pgadmin.org/docs" - }, - "license": "PostgreSQL", - "maintainer": { - "name": "Josué Tille", - "email": "josue@tille.ch" - }, - "requirements": { - "yunohost": ">= 11.0.11" - }, - "multi_instance": false, - "services": [ - "nginx", - "uwsgi" - ], - "arguments": { - "install" : [ - { - "name": "domain", - "type": "domain" - }, - { - "name": "path", - "type": "path", - "example": "/pgadmin", - "default": "/pgadmin" - }, - { - "name": "admin", - "type": "user" - }, - { - "name": "password", - "type": "password" - } - ] - } -} diff --git a/manifest.toml b/manifest.toml new file mode 100644 index 0000000..1bb10cb --- /dev/null +++ b/manifest.toml @@ -0,0 +1,71 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/manifest.v2.schema.json + +packaging_format = 2 + +id = "pgadmin" +name = "pgAdmin4" +description.en = "Manage PostgreSQL databases over the web" +description.fr = "Application web de gestion des bases de données PostgreSQL" + +version = "8.2~ynh2" + +maintainers = ["Josué Tille"] + +[upstream] +license = "PostgreSQL" +website = "https://www.pgadmin.org" +admindoc = "https://www.pgadmin.org/docs" +cpe = "cpe:2.3:a:pgadmin:pgadmin" + +[integration] +yunohost = ">= 11.0.11" +architectures = "all" +multi_instance = false +ldap = false +sso = false +disk = "700M" +ram.build = "300M" +ram.runtime = "200M" + +[install] + [install.domain] + type = "domain" + + [install.path] + type = "path" + default = "/pgadmin" + + [install.init_main_permission] + type = "group" + default = "admins" + + [install.admin] + type = "user" + + [install.password] + type = "password" + +[resources] + [resources.system_user] + + [resources.install_dir] + + [resources.permissions] + main.url = "/" + + [resources.apt] + packages = [ + "python3-pip", + "build-essential", + "python3-dev", + "python3-venv", + "postgresql", + "uwsgi", + "uwsgi-plugin-python3", + "expect", + "libpq-dev", + "libkrb5-dev", + ] + + [resources.database] + type = "postgresql" diff --git a/scripts/_common.sh b/scripts/_common.sh index ea3c266..5ac19ff 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,76 +1,30 @@ +#!/usr/bin/env bash + #================================================= # SET ALL CONSTANTS #================================================= python_version="$(python3 -V | cut -d' ' -f2 | cut -d. -f1-2)" -# dependencies used by the app -pkg_dependencies="python3-pip build-essential python3-dev python3-venv postgresql uwsgi uwsgi-plugin-python3 expect libpq-dev libkrb5-dev" - #================================================= # DEFINE ALL COMMON FONCTIONS #================================================= -setup_dir() { - # Create empty dir for pgadmin - mkdir -p /var/lib/pgadmin - mkdir -p /var/log/pgadmin - mkdir -p $final_path -} - -install_source() { - # Clean venv is it was on python with an old version in case major upgrade of debian - if [ ! -e $final_path/lib/python$python_version ]; then - ynh_secure_remove --file=$final_path/bin - ynh_secure_remove --file=$final_path/lib - ynh_secure_remove --file=$final_path/lib64 - ynh_secure_remove --file=$final_path/include - ynh_secure_remove --file=$final_path/share - ynh_secure_remove --file=$final_path/pyvenv.cfg - fi - - mkdir -p $final_path - chown $pgadmin_user:root -R $final_path - - if [ -n "$(uname -m | grep arm)" ] - then - # Clean old file, sometime it could make some big issues if we don't do this !! - ynh_secure_remove --file=$final_path/bin - ynh_secure_remove --file=$final_path/lib - ynh_secure_remove --file=$final_path/include - ynh_secure_remove --file=$final_path/share - ynh_setup_source --dest_dir $final_path/ --source_id "armv7_$(lsb_release --codename --short)" +ynh_install_venv() { + if [ -f "$install_dir/venv/bin/python" ]; then + ynh_exec_as "$app" python3 -m venv "$install_dir/venv" --upgrade else -# Install virtualenv if it don't exist - test -e $final_path/bin/python3 || python3 -m venv $final_path - -# Install pgadmin in virtualenv - u_arg='u' - set +$u_arg; - source $final_path/bin/activate - set -$u_arg; - pip3 install --upgrade pip wheel - pip3 install -I --upgrade "psycopg[c]" - pip3 install --upgrade -r $YNH_APP_BASEDIR/conf/requirement_$(lsb_release --codename --short).txt - set +$u_arg; - deactivate - set -$u_arg; + ynh_exec_as "$app" python3 -m venv "$install_dir/venv" fi + ynh_use_venv + + ynh_exec_as "$app" "$venvpy" -m pip install --upgrade --no-cache-dir pip wheel +} +ynh_use_venv() { + venvpy="$install_dir/venv/bin/python3" } -set_permission() { - # Set permission - chown $pgadmin_user:root -R $final_path - chown $pgadmin_user:root -R /var/lib/pgadmin - mkdir -p /var/log/pgadmin - chown $pgadmin_user:root -R /var/log/pgadmin - chown $pgadmin_user:root /var/log/uwsgi/$app - chown $pgadmin_user:root /etc/uwsgi/apps-available/$app.ini - chmod u=rwX,g=rX,o= -R /var/lib/pgadmin -} - -config_pgadmin() { - cp ../conf/config_local.py $final_path/lib/python$python_version/site-packages/pgadmin4/config_local.py - ynh_replace_string --match_string __USER__ --replace_string $pgadmin_user --target_file $final_path/lib/python$python_version/site-packages/pgadmin4/config_local.py - ynh_replace_string --match_string __DOMAIN__ --replace_string $domain --target_file $final_path/lib/python$python_version/site-packages/pgadmin4/config_local.py +_install_pgadmin_pip() { + version=$(ynh_app_upstream_version) + ynh_exec_as "$app" "$venvpy" -m pip install --upgrade "pgadmin4==$version" } diff --git a/scripts/backup b/scripts/backup index 14d3473..1485371 100644 --- a/scripts/backup +++ b/scripts/backup @@ -11,26 +11,6 @@ source ../settings/scripts/experimental_helper.sh source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -ynh_clean_setup () { - true -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_print_info --message="Loading installation settings..." - -app=$YNH_APP_INSTANCE_NAME - -final_path=$(ynh_app_setting_get --app=$app --key=final_path) -domain=$(ynh_app_setting_get --app=$app --key=domain) - #================================================= # DECLARE DATA AND CONF FILES TO BACKUP #================================================= @@ -40,29 +20,26 @@ ynh_print_info --message="Declaring files to be backed up..." # BACKUP THE APP MAIN DIR #================================================= -ynh_backup --src_path="$final_path" +ynh_backup --src_path="$install_dir" #================================================= -# BACKUP THE NGINX CONFIGURATION +# SYSTEM CONFIGURATION #================================================= ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" -#================================================= -# SPECIFIC BACKUP -#================================================= -# BACKUP LOGROTATE -#================================================= - ynh_backup --src_path="/etc/logrotate.d/$app" +ynh_backup --src_path="/etc/uwsgi/apps-available/$app.ini" + #================================================= # BACKUP VARIOUS FILES #================================================= -ynh_backup --src_path="/etc/uwsgi/apps-available/$app.ini" +# Backup hashed password +ynh_psql_execute_as_root --sql="SELECT rolpassword FROM pg_authid WHERE rolname='$app';" | head -3 | tail -1 > hashed_password.txt -ynh_backup --src_path="/var/lib/pgadmin" +ynh_backup --src_path="/var/log/pgadmin" #================================================= # END OF SCRIPT diff --git a/scripts/change_url b/scripts/change_url index 2f5c7ba..49fd205 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -11,108 +11,31 @@ source experimental_helper.sh source _common.sh source /usr/share/yunohost/helpers -#================================================= -# RETRIEVE ARGUMENTS -#================================================= - -old_domain=$YNH_APP_OLD_DOMAIN -old_path=$YNH_APP_OLD_PATH - -new_domain=$YNH_APP_NEW_DOMAIN -new_path=$YNH_APP_NEW_PATH - -app=$YNH_APP_INSTANCE_NAME - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." - -# Needed for helper "ynh_add_nginx_config" -final_path=$(ynh_app_setting_get --app=$app --key=final_path) - -# Add settings here as needed by your application -pgadmin_user="$app" - -#================================================= -# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP -#================================================= -ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." - -# 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" - - # 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 WHICH PARTS SHOULD BE CHANGED -#================================================= - -change_domain=0 -if [ "$old_domain" != "$new_domain" ] -then - change_domain=1 -fi - -change_path=0 -if [ "$old_path" != "$new_path" ] -then - change_path=1 -fi - #================================================= # STANDARD MODIFICATIONS #================================================= +# STOP SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Stopping a systemd service..." --weight=1 + +ynh_systemd_action --service_name="uwsgi-app@$app.service" --action="stop" --log_path="/var/log/uwsgi/$app/$app.log" #================================================= # MODIFY URL IN NGINX CONF #================================================= -ynh_script_progression --message="Updating NGINX web server configuration..." +ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1 -nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf - -# Change the path in the NGINX config file -if [ $change_path -eq 1 ] -then - # Make a backup of the original NGINX config file if modified - ynh_backup_if_checksum_is_different --file="$nginx_conf_path" - # Set global variables for NGINX helper - domain="$old_domain" - path_url="$new_path" - # Create a dedicated NGINX config - ynh_add_nginx_config -fi - -# Change the domain for NGINX -if [ $change_domain -eq 1 ] -then - # Delete file checksum for the old conf file location - ynh_delete_file_checksum --file="$nginx_conf_path" - mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf - # Store file checksum for the new config file location - ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" -fi +ynh_change_url_nginx_config #================================================= # SPECIFIC MODIFICATIONS #================================================= # UPDATE CONFIGURATION #================================================= -ynh_script_progression --message="Updating configuration..." - -domain=$new_domain -path_url=$new_path +ynh_script_progression --message="Updating configuration..." --weight=1 # Update UWSGI Config -ynh_add_uwsgi_service 'pgadmin_user python_version' +ynh_add_uwsgi_service "python_version" #================================================= # GENERIC FINALISATION @@ -123,14 +46,6 @@ ynh_script_progression --message="Starting a systemd service..." --weight=3 # Start a systemd service ynh_systemd_action --service_name="uwsgi-app@$app.service" --action="restart" --line_match="WSGI app 0 \(mountpoint='[/[:alnum:]_-]*'\) ready in [[:digit:]]* seconds on interpreter" --log_path="/var/log/uwsgi/$app/$app.log" -sleep 10 - -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." - -ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT diff --git a/scripts/config_database.py b/scripts/config_database.py deleted file mode 100644 index d62f48a..0000000 --- a/scripts/config_database.py +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/python - -from importlib.machinery import SourceFileLoader -import sqlite3 -import sys - -# Import crypto from pgadmin project __PYTHON_VERSION__ -python_version = str(sys.version_info[0]) + "." + str(sys.version_info[1]) -crypto = SourceFileLoader('crypto', '/opt/yunohost/pgadmin/lib/python' + - python_version + '/site-packages/pgadmin4/pgadmin/utils/crypto.py').load_module() - -# Get arguments -username = sys.argv[1] -password = sys.argv[2] - -# Connect to sqlite3 -conn = sqlite3.connect('/var/lib/pgadmin/pgadmin4.db') - -# Get encrypte user password from the database -cursor = conn.execute('SELECT `password`,1 FROM `user`') -user_encrypted_password = cursor.fetchone()[0] - -# Encrypt database password -crypted_password = crypto.encrypt(password, user_encrypted_password) - -# Declare database data to put in database -data = {'id': 1, 'user_id': 1, 'servergroup_id': 1, 'name': 'Yunohost Server', 'host': 'localhost', 'port': 5432, 'maintenance_db': 'postgres', - 'username': username, 'comment': '', 'password': crypted_password, 'role': '', 'discovery_id': '', - 'db_res': '', 'bgcolor': '', 'fgcolor': '', 'service': '', - 'use_ssh_tunnel': '', 'tunnel_host': '', 'tunnel_port': 22, 'tunnel_username': '', 'tunnel_authentication': '', 'tunnel_identity_file': '', 'tunnel_password': '', - 'save_password': 1, 'shared': '', 'kerberos_conn': 0, 'cloud_status': 0, 'passexec_cmd': '', 'passexec_expiration': '', - 'connection_params': '''{"sslmode": "prefer", "connect_timeout": 10, "sslcert": "/.postgresql/postgresql.crt", "sslkey": "/.postgresql/postgresql.key"}'''} - -# Insert new data in database -cursor = conn.cursor() -cursor.execute(''' - INSERT INTO `server` ( - `id`,`user_id`,`servergroup_id`,`name`,`host`,`port`,`maintenance_db`, - `username`,`comment`,`password`,`role`,`discovery_id`, - `db_res`,`bgcolor`,`fgcolor`,`service`, - `use_ssh_tunnel`,`tunnel_host`,`tunnel_port`,`tunnel_username`,`tunnel_authentication`,`tunnel_identity_file`,`tunnel_password`, - `save_password`,`shared`,`kerberos_conn`,`cloud_status`,`passexec_cmd`,`passexec_expiration`, - `connection_params` - ) VALUES ( - :id,:user_id,:servergroup_id,:name,:host,:port,:maintenance_db, - :username,:comment,:password,:role,:discovery_id, - :db_res,:bgcolor,:fgcolor,:service, - :use_ssh_tunnel,:tunnel_host,:tunnel_port,:tunnel_username,:tunnel_authentication,:tunnel_identity_file,:tunnel_password, - :save_password,:shared,:kerberos_conn,:cloud_status,:passexec_cmd,:passexec_expiration, - :connection_params - );''', data) -conn.commit() - -# Close connection -conn.close() diff --git a/scripts/experimental_helper.sh b/scripts/experimental_helper.sh index 605dd74..4691926 100644 --- a/scripts/experimental_helper.sh +++ b/scripts/experimental_helper.sh @@ -43,7 +43,7 @@ EOF # # __APP__ by $app # __PATH__ by $path_url -# __FINALPATH__ by $final_path +# __FINALPATH__ by $install_dir # # And dynamic variables (from the last example) : # __PATH_2__ by $path_2 @@ -51,7 +51,7 @@ EOF # # To be able to customise the settings of the systemd unit you can override the rules with the file "conf/uwsgi-app@override.service". # This file will be automatically placed on the good place -# +# # Note that the service need to be started manually at the end of the installation. # Generally you can start the service with this command: # ynh_systemd_action --service_name "uwsgi-app@$app.service" --line_match "WSGI app 0 \(mountpoint='[/[:alnum:]_-]*'\) ready in [[:digit:]]* seconds on interpreter" --log_path "/var/log/uwsgi/$app/$app.log" @@ -73,8 +73,8 @@ ynh_add_uwsgi_service () { # To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable. # Substitute in a nginx config file only if the variable is not empty - if test -n "${final_path:-}"; then - ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$finaluwsgiini" + if test -n "${install_dir:-}"; then + ynh_replace_string --match_string="__INSTALL_DIR__" --replace_string="$install_dir" --target_file="$finaluwsgiini" fi if test -n "${path_url:-}"; then ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$finaluwsgiini" @@ -87,7 +87,7 @@ ynh_add_uwsgi_service () { for var_to_replace in $others_var do # ${var_to_replace^^} make the content of the variable on upper-cases - # ${!var_to_replace} get the content of the variable named $var_to_replace + # ${!var_to_replace} get the content of the variable named $var_to_replace ynh_replace_string --match_string="__${var_to_replace^^}__" --replace_string="${!var_to_replace}" --target_file="$finaluwsgiini" done @@ -109,7 +109,7 @@ ynh_add_uwsgi_service () { systemctl enable "uwsgi-app@$app.service" # Add as a service - yunohost service add "uwsgi-app@$app" --log "/var/log/uwsgi/$app/$app.log" + yunohost service add "uwsgi-app@$app" --log "/var/log/uwsgi/$app/$app.log" --description="UWSGI service for $app" } # Remove the dedicated uwsgi ini file @@ -136,8 +136,8 @@ ynh_restore_uwsgi_service () { mkdir -p /var/log/uwsgi/$app chown $app:root /var/log/uwsgi/$app chmod -R u=rwX,g=rX,o= /var/log/uwsgi/$app - - yunohost service add "uwsgi-app@$app" --log "/var/log/uwsgi/$app/$app.log" + + yunohost service add "uwsgi-app@$app" --log "/var/log/uwsgi/$app/$app.log" --description="UWSGI service for $app" } #================================================= diff --git a/scripts/install b/scripts/install index ba612ea..229b1f9 100644 --- a/scripts/install +++ b/scripts/install @@ -11,147 +11,64 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# MANAGE SCRIPT FAILURE +# INITIALIZE AND STORE SETTINGS #================================================= -ynh_clean_setup () { - ynh_clean_check_starting -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# RETRIEVE ARGUMENTS FROM THE MANIFEST -#================================================= - -domain=$YNH_APP_ARG_DOMAIN -path_url=$YNH_APP_ARG_PATH -admin=$YNH_APP_ARG_ADMIN -admin_pwd=$YNH_APP_ARG_PASSWORD - -db_user="pgadmin" -db_pwd=$(ynh_string_random --length 30) -app_version=$(ynh_app_upstream_version) -app_sub_version=$(echo $app_version | cut -d'-' -f2) - -app=$YNH_APP_INSTANCE_NAME - -pgadmin_user="$app" - -#================================================= -# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS -#================================================= -ynh_script_progression --message="Validating installation parameters..." - -final_path=/opt/yunohost/$app -test ! -e "$final_path" || ynh_die --message="This path already contains a folder" - -# Register (book) web path -ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url - -# Get user email and check that the user exist +# Used in expect script email=$(ynh_user_get_info --username $admin --key 'mail') -if [[ -z $email ]] -then - ynh_die --message "Can't get user email, check that the user exist or that the user have an email" -fi #================================================= -# STORE SETTINGS FROM MANIFEST +# Postgresql superuser #================================================= -ynh_script_progression --message="Storing installation settings..." +ynh_script_progression --message="Configuring Postgresql superuser..." --weight 1 -ynh_app_setting_set --app=$app --key=domain --value=$domain -ynh_app_setting_set --app=$app --key=path --value=$path_url -ynh_app_setting_set --app=$app --key=admin --value=$admin -ynh_app_setting_set --app=$app --key=admin_pwd --value="$admin_pwd" -ynh_app_setting_set --app=$app --key=db_user --value="$db_user" -ynh_app_setting_set --app=$app --key=db_pwd --value="$db_pwd" - -#================================================= -# STANDARD MODIFICATIONS -#================================================= -# INSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Installing dependencies..." --weight=7 - -ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies - -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." - -# Create a system user -ynh_system_user_create --username=$pgadmin_user --home_dir=$final_path +ynh_psql_execute_as_root --sql "ALTER USER $db_user WITH SUPERUSER CREATEDB CREATEROLE REPLICATION" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." +ynh_script_progression --message="Setting up source files..." --weight=5 +ynh_install_venv -ynh_app_setting_set --app=$app --key=final_path --value=$final_path -# Download, check integrity, uncompress and patch the source from app.src -ynh_script_progression --message="Installing sources files..." --weight=10 -setup_dir -install_source +_install_pgadmin_pip +mkdir -p "$install_dir/data" + +chown -R "$app:root" "$install_dir" + +mkdir -p /var/log/pgadmin +chown -R "$app:root" /var/log/pgadmin #================================================= -# NGINX CONFIGURATION +# ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Configuring NGINX web server..." +ynh_script_progression --message="Configuring pgAdmin..." --weight=1 + +ynh_add_config --template="config_local.py" --destination="$install_dir/venv/lib/python$python_version/site-packages/pgadmin4/config_local.py" +chown -R "$app:root" "$install_dir" + +ynh_add_config --template="setup.exp" --destination="$install_dir/setup.exp" +chmod +x "$install_dir/setup.exp" +ynh_exec_as "$app" "$install_dir/setup.exp" "$install_dir/venv/bin/python3" "$install_dir/venv/lib/python$python_version/site-packages/pgadmin4/setup.py" setup-db + +ynh_add_config --template="server.json" --destination="$install_dir/server.json" +ynh_exec_as "$app" "$install_dir/venv/bin/python3" "$install_dir/venv/lib/python$python_version/site-packages/pgadmin4/setup.py" load-servers --user "$email" "$install_dir/server.json" + +# looks like we need to run one command as pgadmin to get access to the dbs ? +ynh_psql_connect_as --user="$db_user" --password="$db_pwd" <<< '\list' >/dev/null + +#================================================= +# SYSTEM CONFIGURATION +#================================================= +ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 # Create a dedicated NGINX config ynh_add_nginx_config -#================================================= -# SPECIFIC SETUP -#================================================= -# ... -#================================================= - -ynh_script_progression --message="Configuring application..." - -# CONFIGURE PGADMIN -config_pgadmin - # Config uwsgi -ynh_add_uwsgi_service 'pgadmin_user python_version' - -ynh_script_progression --message="Configuring sqlite database..." - -# initialisation sqlite database for pgadmin -chmod +x ../conf/setup.exp -set +u; -source $final_path/bin/activate -set -u; -ynh_replace_special_string --match_string "__ADMIN_PASSWORD__" --replace_string "$admin_pwd" --target_file "../conf/setup.exp" -../conf/setup.exp "$final_path/bin/python3" "$final_path/lib/python$python_version/site-packages/pgadmin4/setup.py" "$email" - -# POPULATE THE DATABASE -ynh_script_progression --message="Configuring Postgresql database..." -ynh_psql_test_if_first_run -ynh_psql_execute_as_root \ - --sql "CREATE USER ${db_user} WITH PASSWORD '${db_pwd}' SUPERUSER CREATEDB CREATEROLE REPLICATION" - -# Add Server In PGadmin database -$final_path/bin/python3 config_database.py "$db_user" "$db_pwd" -set +u; -deactivate -set -u; - -# Set permission after initialisation -ynh_script_progression --message="Protecting directory" -set_permission - -#================================================= -# GENERIC FINALIZATION -#================================================= -# SETUP LOGROTATE -#================================================= -ynh_script_progression --message="Configuring log rotation..." +ynh_add_uwsgi_service "python_version" ynh_use_logrotate --logfile="/var/log/pgadmin" +chown -R "$app:root" /var/log/pgadmin #================================================= # START SYSTEMD SERVICE @@ -159,22 +76,6 @@ ynh_use_logrotate --logfile="/var/log/pgadmin" ynh_script_progression --message="Starting a systemd service..." --weight=3 ynh_systemd_action --service_name "uwsgi-app@$app.service" --action="restart" --line_match "WSGI app 0 \(mountpoint='[/[:alnum:]_-]*'\) ready in [[:digit:]]* seconds on interpreter" --log_path "/var/log/uwsgi/$app/$app.log" -sleep 10 - -#================================================= -# SETUP SSOWAT -#================================================= -ynh_script_progression --message="Configuring permissions..." - -# Restrict access to admin only -ynh_permission_update --permission="main" --remove="all_users" --add=$admin - -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." - -ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index 7ded04b..25c6b3a 100644 --- a/scripts/remove +++ b/scripts/remove @@ -11,19 +11,9 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." - -app=$YNH_APP_INSTANCE_NAME - -domain=$(ynh_app_setting_get --app=$app --key=domain) -db_user=$(ynh_app_setting_get --app=$app --key=db_user) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) - -#================================================= -# STANDARD REMOVE +# REMOVE SYSTEM CONFIGURATIONS #================================================= +ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 # Stop service ynh_systemd_action --service_name "uwsgi-app@$app.service" --action stop @@ -31,67 +21,24 @@ ynh_systemd_action --service_name "uwsgi-app@$app.service" --action stop # Remove uwsgi config ynh_remove_uwsgi_service -#================================================= -# REMOVE LOGROTATE CONFIGURATION -#================================================= -ynh_script_progression --message="Removing logrotate configuration..." - # Remove the app-specific logrotate config ynh_remove_logrotate -#================================================= -# REMOVE DB_USER -#================================================= -ynh_script_progression --message="Cleaning the PostgreSQL database..." - -ynh_psql_drop_user $db_user - -#================================================= -# REMOVE APP MAIN DIR -#================================================= -ynh_script_progression --message="Removing app main directory..." --weight=4 - -# Remove the app directory securely -ynh_secure_remove --file="$final_path" - -#================================================= -# REMOVE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Removing NGINX web server configuration..." - # Remove the dedicated NGINX config ynh_remove_nginx_config -#================================================= -# REMOVE DEPENDENCIES -#================================================= -ynh_script_progression --message="Removing dependencies..." --weight=10 - -# Remove metapackage and its dependencies -ynh_remove_app_dependencies || true - #================================================= # SPECIFIC REMOVE #================================================= # REMOVE VARIOUS FILES #================================================= -ynh_script_progression --message="Removing various files..." - -# Remove app data -ynh_secure_remove --file="/var/lib/$app" +ynh_script_progression --message="Removing various files..." --weight=1 # Remove the log files ynh_secure_remove --file="/var/log/$app" -#================================================= -# GENERIC FINALIZATION -#================================================= -# REMOVE DEDICATED USER -#================================================= -ynh_script_progression --message="Removing the dedicated system user..." - -# Delete a system user -ynh_system_user_delete --username=$app +# Remove the log files +ynh_secure_remove --file="/var/log/uwsgi/$app" #================================================= # END OF SCRIPT diff --git a/scripts/restore b/scripts/restore index 8891245..36b8025 100644 --- a/scripts/restore +++ b/scripts/restore @@ -12,116 +12,63 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers #================================================= -# MANAGE SCRIPT FAILURE +# RESTORE THE POSTGRESQL SUPERUSER #================================================= +ynh_script_progression --message="Restoring the Postgresql superuser..." --weight=1 -ynh_clean_setup () { - ynh_clean_check_starting -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." - -app=$YNH_APP_INSTANCE_NAME - -domain=$(ynh_app_setting_get --app=$app --key=domain) -path_url=$(ynh_app_setting_get --app=$app --key=path) -admin=$(ynh_app_setting_get --app=$app --key=admin) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) -db_user=$(ynh_app_setting_get --app=$app --key=db_user) -db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) - -app_version=$(ynh_app_upstream_version) -app_sub_version=$(echo $app_version | cut -d'-' -f2) - -pgadmin_user="$app" - -#================================================= -# STANDARD RESTORATION STEPS -#================================================= -# 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" - -#================================================= -# RECREATE THE DEDICATED USER -#================================================= -ynh_script_progression --message="Recreating the dedicated system user..." - -# Create the dedicated user (if not existing) -ynh_system_user_create --username=$pgadmin_user --home_dir=$final_path +ynh_psql_execute_as_root --sql "ALTER USER $app WITH SUPERUSER CREATEDB CREATEROLE REPLICATION" #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring the app main directory..." --weight=5 +ynh_script_progression --message="Restoring the app main directory..." --weight=1 -ynh_restore_file --origin_path="$final_path" +ynh_restore_file --origin_path="$install_dir" + +chown -R "$app:root" "$install_dir" -#================================================= -# SPECIFIC RESTORATION #================================================= # REINSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Reinstalling dependencies..." --weight=5 +ynh_script_progression --message="Updating python virtualenv..." --weight=5 -# Define and install dependencies -ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies +ynh_install_venv -# Check that the good python version is installed -# If not upgrade the source -install_source +#================================================= +# RESTORE SYSTEM CONFIGURATIONS +#================================================= +ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 -# POPULATE THE DATABASE -ynh_script_progression --message="Reconfiguring Postgresql database..." -ynh_psql_test_if_first_run -ynh_psql_execute_as_root --sql "CREATE USER ${db_user} WITH PASSWORD '${db_pwd}' SUPERUSER CREATEDB CREATEROLE REPLICATION" +ynh_restore_file --origin_path="/etc/logrotate.d/$app" + +ynh_restore_file --origin_path="/etc/uwsgi/apps-available/$app.ini" + +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # RESTORE VARIOUS FILES #================================================= -ynh_script_progression --message="Restoring various files..." +ynh_script_progression --message="Restoring various files..." --weight=1 + +ynh_restore_file --origin_path="/var/log/$app/" +chmod -R 750 /var/log/pgadmin +chown -R "$app:root" /var/log/pgadmin -ynh_restore_file --origin_path="/etc/uwsgi/apps-available/$app.ini" -ynh_restore_file --origin_path="/var/lib/pgadmin" # Restore systemd configuration -ynh_script_progression --message="Reconfiguring application..." +ynh_script_progression --message="Reconfiguring application..." --weight=1 ynh_restore_uwsgi_service -# Set the permission -ynh_script_progression --message="Protecting directory..." -set_permission - -#================================================= -# RESTORE THE LOGROTATE CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the logrotate configuration..." - -ynh_restore_file --origin_path="/etc/logrotate.d/$app" - -#================================================= -# START SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=3 - -ynh_systemd_action --service_name "uwsgi-app@$app.service" --action="restart" --line_match "WSGI app 0 \(mountpoint='[/[:alnum:]_-]*'\) ready in [[:digit:]]* seconds on interpreter" --log_path "/var/log/uwsgi/$app/$app.log" - #================================================= # GENERIC FINALIZATION #================================================= -# RELOAD NGINX +# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE #================================================= -ynh_script_progression --message="Reloading NGINX web server..." +ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1 + +ynh_systemd_action --service_name "uwsgi-app@$app.service" --action="restart" --line_match "WSGI app 0 \(mountpoint='[/[:alnum:]_-]*'\) ready in [[:digit:]]* seconds on interpreter" --log_path "/var/log/uwsgi/$app/$app.log" ynh_systemd_action --service_name=nginx --action=reload -sleep 10 #================================================= # END OF SCRIPT diff --git a/scripts/upgrade b/scripts/upgrade index 01a55da..3641d36 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -10,111 +10,76 @@ source experimental_helper.sh source _common.sh source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." - -app=$YNH_APP_INSTANCE_NAME - -domain=$(ynh_app_setting_get --app=$app --key=domain) -path_url=$(ynh_app_setting_get --app=$app --key=path) -admin=$(ynh_app_setting_get --app=$app --key=admin) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) - -app_version=$(ynh_app_upstream_version) -app_sub_version=$(echo $app_version | cut -d'-' -f2) - -pgadmin_user="$app" - -#================================================= -# CHECK VERSION -#================================================= -ynh_script_progression --message="Checking 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)..." - -# 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 -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - #================================================= # STANDARD UPGRADE STEPS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." +ynh_script_progression --message="Stopping a systemd service..." --weight=1 -test -e /etc/uwsgi/apps-available/$app.ini && \ +if [ -f "/etc/uwsgi/apps-available/$app.ini" ]; then ynh_systemd_action --service_name "uwsgi-app@$app.service" --action stop +fi #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_script_progression --message="Ensuring downward compatibility..." +ynh_script_progression --message="Ensuring downward compatibility..." --weight=2 -if ! grep -q "$final_path" /etc/passwd; then - sed --in-place -r "s@$app\:x\:([[:digit:]]+\:[[:digit:]]+)\:\:/.*/$app\:/usr/sbin/nologin@$app\:x\:\1\:\:$final_path\:/usr/sbin/nologin@g" /etc/passwd -fi - -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Upgrading NGINX web server configuration..." - -# Create a dedicated NGINX config -ynh_add_nginx_config - -#================================================= -# UPGRADE DEPENDENCIES -#================================================= -ynh_script_progression --message="Upgrading dependencies..." - -ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies - -#================================================= -# SPECIFIC UPGRADE -#================================================= -# ... -#================================================= -# Download, check integrity, uncompress and patch the source from app.src -ynh_script_progression --message="Upgrading source files..." --weight=6 -install_source - -# CONFIGURE PGADMIN -ynh_script_progression --message="Configuring application..." -config_pgadmin - -# Config uwsgi -ynh_add_uwsgi_service 'pgadmin_user python_version' +# Set the proper home directory +usermod -d "$install_dir" "$app" # Clean old uwsgi config ynh_secure_remove /etc/uwsgi/apps-enabled/pgadmin.ini -# Set permission after initialisation -ynh_script_progression --message="Protecting directory..." -set_permission +if [ -d "/var/lib/pgadmin" ]; then + if [ ! -d "$install_dir/data" ]; then + mv "/var/lib/pgadmin" "$install_dir/data" + fi + ynh_secure_remove "/var/lib/pgadmin" +fi #================================================= -# GENERIC FINALIZATION +# Postgresql superuser #================================================= -# SETUP LOGROTATE +ynh_script_progression --message="Configuring Postgresql superuser..." --weight=1 + +# Re-set the db_pwd just in case… +ynh_psql_execute_as_root --sql "ALTER USER $app WITH PASSWORD '$db_pwd' SUPERUSER CREATEDB CREATEROLE REPLICATION" + #================================================= -ynh_script_progression --message="Upgrading logrotate configuration..." +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= +ynh_script_progression --message="Upgrading source files..." --weight=6 +ynh_install_venv + +_install_pgadmin_pip + +chown -R "$app:root" "$install_dir" + +#================================================= +# UPDATE A CONFIG FILE +#================================================= +ynh_script_progression --message="Updating a configuration file..." --weight=1 + +# CONFIGURE PGADMIN +ynh_add_config --template="config_local.py" --destination="$install_dir/venv/lib/python$python_version/site-packages/pgadmin4/config_local.py" +chown -R "$app:root" "$install_dir" + +#================================================= +# REAPPLY SYSTEM CONFIGURATIONS +#================================================= +ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 + +# Create a dedicated NGINX config +ynh_add_nginx_config + +# Config uwsgi +ynh_add_uwsgi_service "python_version" # Use logrotate to manage app-specific logfile(s) ynh_use_logrotate --logfile /var/log/pgadmin --nonappend +chown -R "$app:root" /var/log/pgadmin #================================================= # START SYSTEMD SERVICE @@ -122,14 +87,6 @@ ynh_use_logrotate --logfile /var/log/pgadmin --nonappend ynh_script_progression --message="Starting a systemd service..." --weight=3 ynh_systemd_action --service_name "uwsgi-app@$app.service" --action="restart" --line_match "WSGI app 0 \(mountpoint='[/[:alnum:]_-]*'\) ready in [[:digit:]]* seconds on interpreter" --log_path "/var/log/uwsgi/$app/$app.log" -sleep 10 - -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." - -ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT diff --git a/tests.toml b/tests.toml new file mode 100644 index 0000000..fef783d --- /dev/null +++ b/tests.toml @@ -0,0 +1,8 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/tests.v1.schema.json + +test_format = 1.0 + +[default] + + test_upgrade_from.da90e7957a1a365f3c840df02c41cd14592030db.name = "Last packaging v1 version" + test_upgrade_from.067601ed5bb19dde70f74a1fa1f6230a30efe6b5.name = "7.2~ynh1"