diff --git a/conf/config_local.py b/conf/config_local.py index bad0b92..1ddd489 100644 --- a/conf/config_local.py +++ b/conf/config_local.py @@ -1 +1 @@ -DESKTOP_USER = '__USER__@__DOMAIN__' \ No newline at end of file +DESKTOP_USER = '__APP__@__DOMAIN__' diff --git a/conf/uwsgi.ini b/conf/uwsgi.ini index b5c0b7b..a582f8b 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 = __INSTALL_DIR__ pythonpath = __INSTALL_DIR__ -chdir = __INSTALL_DIR__/lib/python__PYTHON_VERSION__/site-packages/pgadmin4 +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/manifest.toml b/manifest.toml index 7b5163a..4a57f2c 100644 --- a/manifest.toml +++ b/manifest.toml @@ -48,13 +48,13 @@ ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requiremen [resources] [resources.sources] - [resources.sources.armv7_bullseye] - url = "https://github.com/Josue-T/pgadmin_python_build/releases/download/v4-7.7/pgadmin_4-7.7-bullseye-bin1_armv7l.tar.gz" - sha256 = "76022eeab9c985a30dab8b24027db095f74eb491077de01db77100e320b4a2e5" + [resources.sources.armv7_bullseye] + url = "https://github.com/Josue-T/pgadmin_python_build/releases/download/v4-7.7/pgadmin_4-7.7-bullseye-bin1_armv7l.tar.gz" + sha256 = "76022eeab9c985a30dab8b24027db095f74eb491077de01db77100e320b4a2e5" - [resources.sources.armv7_bookworm] - url = "https://github.com/Josue-T/pgadmin_python_build/releases/download/v4-7.7/pgadmin_4-7.7-bookworm-bin1_armv7l.tar.gz" - sha256 = "e18206853ced73eb1922182c5a3c825d8af21d5e40fcd607311cc4e075a28e72" + [resources.sources.armv7_bookworm] + url = "https://github.com/Josue-T/pgadmin_python_build/releases/download/v4-7.7/pgadmin_4-7.7-bookworm-bin1_armv7l.tar.gz" + sha256 = "e18206853ced73eb1922182c5a3c825d8af21d5e40fcd607311cc4e075a28e72" [resources.system_user] diff --git a/scripts/_common.sh b/scripts/_common.sh index 85bd055..bb16de0 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -6,9 +6,6 @@ python_version="$(python3 -V | cut -d' ' -f2 | cut -d. -f1-2)" -# dependencies used by the app -#REMOVEME? pkg_dependencies="python3-pip build-essential python3-dev python3-venv postgresql uwsgi uwsgi-plugin-python3 expect libpq-dev libkrb5-dev" - #================================================= # DEFINE ALL COMMON FONCTIONS #================================================= @@ -17,47 +14,6 @@ setup_dir() { # Create empty dir for pgadmin mkdir -p /var/lib/pgadmin mkdir -p /var/log/pgadmin - mkdir -p $install_dir -} - -install_source() { -# # Clean venv is it was on python with an old version in case major upgrade of debian -# if [ ! -e $install_dir/lib/python$python_version ]; then -# #REMOVEME? ynh_secure_remove --file=$install_dir/bin -# #REMOVEME? ynh_secure_remove --file=$install_dir/lib -# #REMOVEME? ynh_secure_remove --file=$install_dir/lib64 -# #REMOVEME? ynh_secure_remove --file=$install_dir/include -# #REMOVEME? ynh_secure_remove --file=$install_dir/share -# #REMOVEME? ynh_secure_remove --file=$install_dir/pyvenv.cfg -# fi - - mkdir -p $install_dir - chown $app:root -R $install_dir - - if [ -n "$(uname -m | grep arm)" ] - then - # Clean old file, sometime it could make some big issues if we don't do this !! -#REMOVEME? ynh_secure_remove --file=$install_dir/bin -#REMOVEME? ynh_secure_remove --file=$install_dir/lib -#REMOVEME? ynh_secure_remove --file=$install_dir/include -#REMOVEME? ynh_secure_remove --file=$install_dir/share - ynh_setup_source --dest_dir $install_dir/ --source_id "armv7_$(lsb_release --codename --short)" - else -# Install virtualenv if it don't exist - test -e $install_dir/bin/python3 || python3 -m venv $install_dir - -# Install pgadmin in virtualenv - u_arg='u' - set +$u_arg; - source $install_dir/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; - fi } set_permission() { @@ -71,8 +27,16 @@ set_permission() { chmod u=rwX,g=rX,o= -R /var/lib/pgadmin } -config_pgadmin() { - cp ../conf/config_local.py $install_dir/lib/python$python_version/site-packages/pgadmin4/config_local.py - ynh_replace_string --match_string __USER__ --replace_string $app --target_file $install_dir/lib/python$python_version/site-packages/pgadmin4/config_local.py - ynh_replace_string --match_string __DOMAIN__ --replace_string $domain --target_file $install_dir/lib/python$python_version/site-packages/pgadmin4/config_local.py +_install_pgadmin_venv() { + ynh_exec_as "$app" python3 -m venv --upgrade "$install_dir/venv" + venvpy="$install_dir/venv/bin/python3" + + ynh_exec_as "$app" "$venvpy" -m pip install --upgrade --no-cache-dir pip wheel + ynh_exec_as "$app" "$venvpy" -m pip install --upgrade --no-cache-dir --ignore-installed "psycopg[c]" + + ynh_exec_as "$app" "$venvpy" -m pip install --upgrade -r "$YNH_APP_BASEDIR/conf/requirement_$(lsb_release --codename --short).txt" +} + +config_pgadmin() { + ynh_add_config --template="config_local.py" --destination="$install_dir/venv/lib/python$python_version/site-packages/pgadmin4/config_local.py" } diff --git a/scripts/install b/scripts/install index 20504ac..b9696fd 100644 --- a/scripts/install +++ b/scripts/install @@ -10,6 +10,10 @@ source experimental_helper.sh source _common.sh source /usr/share/yunohost/helpers +#================================================= +# INITIALIZE AND STORE SETTINGS +#================================================= + email=$(ynh_user_get_info --username $admin --key 'mail') #================================================= @@ -19,8 +23,10 @@ ynh_script_progression --message="Setting up source files..." # 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_venv #================================================= # SPECIFIC SETUP @@ -41,10 +47,10 @@ ynh_script_progression --message="Configuring sqlite database..." # initialisation sqlite database for pgadmin chmod +x ../conf/setup.exp set +u; -source $install_dir/bin/activate +source $install_dir/venv/bin/activate set -u; ynh_replace_special_string --match_string "__ADMIN_PASSWORD__" --replace_string "$password" --target_file "../conf/setup.exp" -../conf/setup.exp "$install_dir/bin/python3" "$install_dir/lib/python$python_version/site-packages/pgadmin4/setup.py" "$email" +../conf/setup.exp "$install_dir/venv/bin/python3" "$install_dir/venv/lib/python$python_version/site-packages/pgadmin4/setup.py" "$email" # POPULATE THE DATABASE ynh_script_progression --message="Configuring Postgresql database..." @@ -53,7 +59,7 @@ ynh_psql_execute_as_root \ --sql "CREATE USER ${db_user} WITH PASSWORD '${db_pwd}' SUPERUSER CREATEDB CREATEROLE REPLICATION" # Add Server In PGadmin database -$install_dir/bin/python3 config_database.py "$db_user" "$db_pwd" +$install_dir/venv/bin/python3 config_database.py "$db_user" "$db_pwd" set +u; deactivate set -u;