2024-01-30 11:37:53 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2018-01-31 16:08:58 +01:00
|
|
|
#=================================================
|
|
|
|
# SET ALL CONSTANTS
|
|
|
|
#=================================================
|
|
|
|
|
2020-04-20 15:32:01 +02:00
|
|
|
python_version="$(python3 -V | cut -d' ' -f2 | cut -d. -f1-2)"
|
2024-02-27 23:20:13 +01:00
|
|
|
postgresql_version="$(psql -V | cut -d' ' -f3 | cut -d. -f1)"
|
2022-03-13 15:22:35 +01:00
|
|
|
|
2018-01-31 16:08:58 +01:00
|
|
|
#=================================================
|
|
|
|
# DEFINE ALL COMMON FONCTIONS
|
|
|
|
#=================================================
|
|
|
|
|
2024-02-27 23:20:13 +01:00
|
|
|
install_source() {
|
2024-05-07 12:01:54 +02:00
|
|
|
# Cleanup old venv files
|
|
|
|
ynh_secure_remove --file="$install_dir"/bin
|
|
|
|
ynh_secure_remove --file="$install_dir"/lib
|
|
|
|
ynh_secure_remove --file="$install_dir"/lib64
|
|
|
|
ynh_secure_remove --file="$install_dir"/include
|
|
|
|
ynh_secure_remove --file="$install_dir"/share
|
|
|
|
ynh_secure_remove --file="$install_dir"/pyvenv.cfg
|
|
|
|
|
2024-02-27 23:20:13 +01:00
|
|
|
# Clean venv is it was on python with an old version in case major upgrade of debian
|
2024-04-27 01:08:10 +02:00
|
|
|
if [ ! -e "$install_dir/venv/lib/python$python_version" ] || ! grep -qF "$install_dir/venv/bin/python" "$install_dir"/venv/bin/pip; then
|
|
|
|
ynh_secure_remove --file="$install_dir"/venv/bin
|
|
|
|
ynh_secure_remove --file="$install_dir"/venv/lib
|
|
|
|
ynh_secure_remove --file="$install_dir"/venv/lib64
|
|
|
|
ynh_secure_remove --file="$install_dir"/venv/include
|
|
|
|
ynh_secure_remove --file="$install_dir"/venv/share
|
|
|
|
ynh_secure_remove --file="$install_dir"/venv/pyvenv.cfg
|
2024-02-27 23:20:13 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if uname -m | grep -q arm
|
|
|
|
then
|
2024-05-07 12:01:54 +02:00
|
|
|
ynh_setup_source --dest_dir "$install_dir"/venv/ --source_id "pgadmin_prebuilt_armv7_$(lsb_release --codename --short)" --full_replace
|
|
|
|
|
|
|
|
# Fix multi-instance support
|
|
|
|
for f in "$install_dir"/venv/bin/*; do
|
|
|
|
if ! [[ $f =~ "__" ]]; then
|
2024-05-31 17:29:45 +02:00
|
|
|
ynh_replace_special_string --match_string='#!'/opt/yunohost/pgadmin/venv --replace_string='#!'"$install_dir"/venv --target_file="$f"
|
2024-05-07 12:01:54 +02:00
|
|
|
fi
|
|
|
|
done
|
2024-01-30 16:48:42 +01:00
|
|
|
else
|
2024-02-27 23:20:13 +01:00
|
|
|
# Install virtualenv if it don't exist
|
2024-04-27 01:08:10 +02:00
|
|
|
test -e "$install_dir"/venv/bin/python3 || python3 -m venv "$install_dir"/venv
|
2024-02-27 23:20:13 +01:00
|
|
|
|
|
|
|
# Install pgadmin in virtualenv
|
2024-04-27 01:08:10 +02:00
|
|
|
pip="$install_dir"/venv/bin/pip
|
2024-02-27 23:20:13 +01:00
|
|
|
$pip install --upgrade pip wheel
|
2024-04-27 01:08:10 +02:00
|
|
|
$pip install --upgrade -r "$YNH_APP_BASEDIR/conf/requirement_$(lsb_release --codename --short).txt"
|
2024-01-30 16:48:42 +01:00
|
|
|
fi
|
2024-01-30 15:32:09 +01:00
|
|
|
|
2024-02-27 23:20:13 +01:00
|
|
|
# Apply patchs if needed
|
2024-03-12 12:13:02 +01:00
|
|
|
# Note that we put patch into scripts dir because /source are not stored and can't be used on restore
|
2024-04-27 01:08:10 +02:00
|
|
|
if ! grep -F -q '# BEGIN Yunohost Patch' "$install_dir/venv/lib/python$python_version/site-packages/pgadmin4/migrations/versions/fdc58d9bd449_.py"; then
|
|
|
|
pushd "$install_dir/venv/lib/python$python_version/site-packages/pgadmin4"
|
2024-03-12 12:13:02 +01:00
|
|
|
patch -p1 < "$YNH_APP_BASEDIR"/scripts/patch/avoid_create_user_on_setup_db.patch
|
2024-02-27 23:20:13 +01:00
|
|
|
popd
|
|
|
|
fi
|
2024-04-27 01:08:10 +02:00
|
|
|
if ! grep -F -q '# BEGIN Yunohost Patch' "$install_dir/venv/lib/python$python_version/site-packages/pgadmin4/pgadmin/__init__.py"; then
|
|
|
|
pushd "$install_dir/venv/lib/python$python_version/site-packages/pgadmin4"
|
2024-03-12 12:13:02 +01:00
|
|
|
patch -p1 < "$YNH_APP_BASEDIR"/scripts/patch/fix_add_local_db.patch
|
2024-02-27 23:20:13 +01:00
|
|
|
popd
|
|
|
|
fi
|
2024-04-27 01:08:10 +02:00
|
|
|
if ! grep -F -q '# BEGIN Yunohost Patch' "$install_dir/venv/lib/python$python_version/site-packages/pgadmin4/pgadmin/authenticate/webserver.py"; then
|
|
|
|
pushd "$install_dir/venv/lib/python$python_version/site-packages/pgadmin4"
|
2024-03-12 12:13:02 +01:00
|
|
|
patch -p1 < "$YNH_APP_BASEDIR"/scripts/patch/change_default_webserver_new_user_role_to_admin.patch
|
2024-02-27 23:20:13 +01:00
|
|
|
popd
|
|
|
|
fi
|
2024-01-30 16:48:42 +01:00
|
|
|
}
|
|
|
|
|
2024-02-27 23:20:13 +01:00
|
|
|
set_permission() {
|
|
|
|
# Set permission
|
2024-04-27 01:08:10 +02:00
|
|
|
chown "$app:$app" -R "$install_dir"
|
|
|
|
chmod u+rw,o= -R "$install_dir"
|
|
|
|
chown "$app:$app" -R "$data_dir"
|
|
|
|
chmod u+rw,o= -R "$data_dir"
|
|
|
|
chown "$app:$app" -R /var/log/"$app"
|
|
|
|
chmod u=rwX,g=rX,o= -R /var/log/"$app"
|
2024-02-27 23:20:13 +01:00
|
|
|
# Criticals files
|
2024-04-27 01:08:10 +02:00
|
|
|
chown "$app":root "$data_dir"/master_pwd
|
|
|
|
chmod u=r,g=,o= "$data_dir"/master_pwd
|
|
|
|
chown "$app":root "$install_dir"/postgres-reg.ini
|
|
|
|
chmod u=r,g=,o= "$install_dir"/postgres-reg.ini
|
2024-01-30 15:32:09 +01:00
|
|
|
}
|
2024-02-27 23:20:13 +01:00
|
|
|
|