1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/pgadmin_ynh.git synced 2024-09-03 19:56:38 +02:00
pgadmin_ynh/scripts/_common.sh
2024-01-30 11:37:53 +01:00

78 lines
3 KiB
Bash

#!/usr/bin/env bash
#=================================================
# SET ALL CONSTANTS
#=================================================
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
#=================================================
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
#REMOVEME? 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() {
# Set permission
chown $app:root -R $install_dir
chown $app:root -R /var/lib/pgadmin
mkdir -p /var/log/pgadmin
chown $app:root -R /var/log/pgadmin
chown $app:root /var/log/uwsgi/$app
chown $app:root /etc/uwsgi/apps-available/$app.ini
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
}