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

87 lines
3.4 KiB
Bash
Raw Normal View History

#=================================================
# SET ALL CONSTANTS
#=================================================
2020-04-20 15:32:01 +02:00
python_version="$(python3 -V | cut -d' ' -f2 | cut -d. -f1-2)"
2022-03-13 15:22:35 +01:00
# 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"
2017-11-16 21:10:21 +01:00
#=================================================
# DEFINE ALL COMMON FONCTIONS
#=================================================
2017-11-16 21:10:21 +01:00
setup_dir() {
# Create empty dir for pgadmin
mkdir -p /var/lib/pgadmin
mkdir -p /var/log/pgadmin
mkdir -p $final_path
}
2017-11-14 16:05:26 +01:00
2017-11-16 21:10:21 +01:00
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
2021-04-04 12:48:21 +02:00
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
2021-04-04 12:48:21 +02:00
chown $pgadmin_user:root -R $final_path
if [ -n "$(uname -m | grep arm)" ]
then
2020-01-26 15:50:06 +01:00
# 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
2020-06-03 14:34:16 +02:00
ynh_setup_source --dest_dir $final_path/ --source_id "armv7_$(lsb_release --codename --short)"
else
2021-04-01 21:48:42 +02:00
# Install rustup is not already installed
# We need this to be able to install cryptgraphy
export PATH="$PATH:$final_path/.cargo/bin:$final_path/.local/bin:/usr/local/sbin"
if [ -e $final_path/.rustup ]; then
2021-04-04 12:48:21 +02:00
sudo -u "$pgadmin_user" env PATH=$PATH rustup update
2021-04-01 21:48:42 +02:00
else
sudo -u "$pgadmin_user" bash -c 'curl -sSf -L https://static.rust-lang.org/rustup.sh | sh -s -- -y --default-toolchain=stable --profile=minimal'
2021-04-01 21:48:42 +02:00
fi
2017-11-16 21:10:21 +01:00
# Install virtualenv if it don't exist
2018-11-07 19:30:34 +01:00
test -e $final_path/bin/python3 || python3 -m venv $final_path
2017-11-16 21:10:21 +01:00
# Install pgadmin in virtualenv
2021-04-01 22:15:00 +02:00
u_arg='u'
set +$u_arg;
source $final_path/bin/activate
2021-04-09 21:27:54 +02:00
set -$u_arg;
2018-11-07 19:30:34 +01:00
pip3 install --upgrade pip
2020-02-22 23:17:32 +01:00
pip3 install --upgrade 'Werkzeug<1.0'
pip3 install --upgrade 'markupsafe==2.0.1'
2020-07-29 23:14:43 +02:00
pip3 install --upgrade pgadmin$app_main_version==$app_sub_version
2021-04-01 22:15:00 +02:00
set +$u_arg;
deactivate
2021-04-01 22:15:00 +02:00
set -$u_arg;
fi
2017-11-16 21:10:21 +01:00
}
2017-11-14 16:05:26 +01:00
2017-11-16 21:10:21 +01:00
set_permission() {
# Set permission
chown $pgadmin_user:root -R $final_path
chown $pgadmin_user:root -R /var/lib/pgadmin
2022-03-19 12:19:38 +01:00
mkdir -p /var/log/pgadmin
2017-11-16 21:10:21 +01:00
chown $pgadmin_user:root -R /var/log/pgadmin
2020-02-24 23:24:30 +01:00
chown $pgadmin_user:root /var/log/uwsgi/$app
2020-03-06 15:38:59 +01:00
chown $pgadmin_user:root /etc/uwsgi/apps-available/$app.ini
2018-01-29 18:48:14 +01:00
chmod u=rwX,g=rX,o= -R /var/lib/pgadmin
2017-11-16 21:10:21 +01:00
}
2017-11-14 16:05:26 +01:00
2017-11-16 21:10:21 +01:00
config_pgadmin() {
2018-11-07 19:30:34 +01:00
cp ../conf/config_local.py $final_path/lib/python$python_version/site-packages/pgadmin4/config_local.py
2019-06-06 22:39:49 +02:00
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
2017-11-16 21:10:21 +01:00
}