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

75 lines
2.6 KiB
Bash
Raw Normal View History

#=================================================
# SET ALL CONSTANTS
#=================================================
2017-11-14 16:05:26 +01:00
app=$YNH_APP_INSTANCE_NAME
2017-11-16 21:10:21 +01:00
final_path=/opt/yunohost/$app
pgadmin_user="pgadmin"
2018-11-07 19:30:34 +01:00
python_version="3.5"
2017-11-16 21:10:21 +01:00
[[ -e "../settings/manifest.json" ]] || [[ -e "../manifest.json" ]] && \
APP_VERSION=$(ynh_app_upstream_version)
2018-01-22 16:51:41 +01:00
app_main_version=$(echo $APP_VERSION | cut -d'-' -f1)
app_sub_version=$(echo $APP_VERSION | cut -d'-' -f2)
2017-11-14 16:05:26 +01:00
#=================================================
# DEFINE ALL COMMON FONCTIONS
#=================================================
2017-11-14 16:05:26 +01:00
install_dependance() {
2019-04-08 19:06:29 +02:00
ynh_install_app_dependencies python3-pip build-essential python3-dev python3-venv postgresql uwsgi uwsgi-plugin-python3 expect libpq-dev
2017-11-14 16:05:26 +01:00
}
psql_create_admin() {
ynh_psql_execute_as_root \
"CREATE USER ${1} WITH PASSWORD '${2}';"
}
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() {
if [ -n "$(uname -m | grep arm)" ]
then
2018-11-29 19:50:43 +01:00
ynh_setup_source $final_path/ "armv7_stretch"
else
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
PS1=""
cp ../conf/virtualenv_activate $final_path/bin/activate
source $final_path/bin/activate
2018-11-07 19:30:34 +01:00
pip3 install --upgrade pip
pip3 install --upgrade https://ftp.postgresql.org/pub/pgadmin/pgadmin$app_main_version/v$app_sub_version/pip/pgadmin${APP_VERSION}-py2.py3-none-any.whl
deactivate
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
chown $pgadmin_user:root -R /var/log/pgadmin
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
ynh_replace_string __USER__ $pgadmin_user $final_path/lib/python$python_version/site-packages/pgadmin4/config_local.py
ynh_replace_string __DOMAIN__ $domain $final_path/lib/python$python_version/site-packages/pgadmin4/config_local.py
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_uwsgi() {
cp ../conf/pgadmin.ini /etc/uwsgi/apps-enabled/
2018-08-02 15:59:04 +02:00
ynh_replace_string __USER__ $pgadmin_user /etc/uwsgi/apps-enabled/pgadmin.ini
ynh_replace_string __FINALPATH__ $final_path /etc/uwsgi/apps-enabled/pgadmin.ini
ynh_replace_string __PATH__ $path_url /etc/uwsgi/apps-enabled/pgadmin.ini
2018-11-07 19:30:34 +01:00
ynh_replace_string __PYTHON_VERSION__ $python_version /etc/uwsgi/apps-enabled/pgadmin.ini
2017-11-16 21:10:21 +01:00
}
2017-11-14 16:05:26 +01:00