From bbc3f1a0ea25dc8a878e713f6bf7323c8342c507 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Tue, 30 Jan 2024 16:22:11 +0100 Subject: [PATCH] cleanup install --- conf/setup.exp | 4 +-- scripts/_common.sh | 4 --- scripts/config_database.py | 55 -------------------------------------- scripts/install | 42 ++++++++++++----------------- 4 files changed, 19 insertions(+), 86 deletions(-) mode change 100644 => 100755 conf/setup.exp delete mode 100644 scripts/config_database.py diff --git a/conf/setup.exp b/conf/setup.exp old mode 100644 new mode 100755 index 9cec340..26efb02 --- a/conf/setup.exp +++ b/conf/setup.exp @@ -11,11 +11,11 @@ expect "Email address:" send "$user\r"; expect "Password:" -send {__ADMIN_PASSWORD__}; +send {__PASSWORD__}; send "\r"; expect "Retype password:" -send {__ADMIN_PASSWORD__}; +send {__PASSWORD__}; send "\r"; interact diff --git a/scripts/_common.sh b/scripts/_common.sh index 6d5f31c..6abb099 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -37,7 +37,3 @@ _install_pgadmin_venv() { cp "$YNH_APP_BASEDIR/conf/requirement_$(lsb_release --codename --short).txt" "$install_dir/requirements.txt" ynh_exec_as "$app" "$venvpy" -m pip install --upgrade -r "$install_dir/requirements.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/config_database.py b/scripts/config_database.py deleted file mode 100644 index e2a62ab..0000000 --- a/scripts/config_database.py +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/python - -from importlib.machinery import SourceFileLoader -import sqlite3 -import sys - -# Import crypto from pgadmin project __PYTHON_VERSION__ -python_version = str(sys.version_info[0]) + "." + str(sys.version_info[1]) -crypto = SourceFileLoader('crypto', '/var/www/pgadmin/venv/lib/python' + - python_version + '/site-packages/pgadmin4/pgadmin/utils/crypto.py').load_module() - -# Get arguments -username = sys.argv[1] -password = sys.argv[2] - -# Connect to sqlite3 -conn = sqlite3.connect('/var/lib/pgadmin/pgadmin4.db') - -# Get encrypte user password from the database -cursor = conn.execute('SELECT `password`,1 FROM `user`') -user_encrypted_password = cursor.fetchone()[0] - -# Encrypt database password -crypted_password = crypto.encrypt(password, user_encrypted_password) - -# Declare database data to put in database -data = {'id': 1, 'user_id': 1, 'servergroup_id': 1, 'name': 'Yunohost Server', 'host': 'localhost', 'port': 5432, 'maintenance_db': 'postgres', - 'username': username, 'comment': '', 'password': crypted_password, 'role': '', 'discovery_id': '', - 'db_res': '', 'bgcolor': '', 'fgcolor': '', 'service': '', - 'use_ssh_tunnel': '', 'tunnel_host': '', 'tunnel_port': 22, 'tunnel_username': '', 'tunnel_authentication': '', 'tunnel_identity_file': '', 'tunnel_password': '', - 'save_password': 1, 'shared': '', 'kerberos_conn': 0, 'cloud_status': 0, 'passexec_cmd': '', 'passexec_expiration': '', - 'connection_params': '''{"sslmode": "prefer", "connect_timeout": 10, "sslcert": "/.postgresql/postgresql.crt", "sslkey": "/.postgresql/postgresql.key"}'''} - -# Insert new data in database -cursor = conn.cursor() -cursor.execute(''' - INSERT INTO `server` ( - `id`,`user_id`,`servergroup_id`,`name`,`host`,`port`,`maintenance_db`, - `username`,`comment`,`password`,`role`,`discovery_id`, - `db_res`,`bgcolor`,`fgcolor`,`service`, - `use_ssh_tunnel`,`tunnel_host`,`tunnel_port`,`tunnel_username`,`tunnel_authentication`,`tunnel_identity_file`,`tunnel_password`, - `save_password`,`shared`,`kerberos_conn`,`cloud_status`,`passexec_cmd`,`passexec_expiration`, - `connection_params` - ) VALUES ( - :id,:user_id,:servergroup_id,:name,:host,:port,:maintenance_db, - :username,:comment,:password,:role,:discovery_id, - :db_res,:bgcolor,:fgcolor,:service, - :use_ssh_tunnel,:tunnel_host,:tunnel_port,:tunnel_username,:tunnel_authentication,:tunnel_identity_file,:tunnel_password, - :save_password,:shared,:kerberos_conn,:cloud_status,:passexec_cmd,:passexec_expiration, - :connection_params - );''', data) -conn.commit() - -# Close connection -conn.close() diff --git a/scripts/install b/scripts/install index ebd6dbd..1c898e8 100644 --- a/scripts/install +++ b/scripts/install @@ -21,43 +21,32 @@ email=$(ynh_user_get_info --username $admin --key 'mail') #================================================= 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 +_install_pgadmin_venv setup_dir -_install_pgadmin_venv - #================================================= -# SPECIFIC SETUP +# ADD A CONFIGURATION #================================================= -# ... -#================================================= - -ynh_script_progression --message="Configuring application..." +ynh_script_progression --message="Adding a configuration file..." --weight=1 # CONFIGURE PGADMIN -config_pgadmin +ynh_add_config --template="config_local.py" --destination="$install_dir/venv/lib/python$python_version/site-packages/pgadmin4/config_local.py" -# Config uwsgi -ynh_add_uwsgi_service "python_version" +ynh_script_progression --message="Configuring $app..." -ynh_script_progression --message="Configuring sqlite database..." +ynh_add_config --template="setup.exp" --destination="$install_dir/setup.exp" +"$install_dir/setup.exp" "$install_dir/venv/bin/python3" "$install_dir/venv/lib/python$python_version/site-packages/pgadmin4/setup.py" "$email" -# initialisation sqlite database for pgadmin -chmod +x ../conf/setup.exp - -ynh_replace_special_string --match_string "__ADMIN_PASSWORD__" --replace_string "$password" --target_file "../conf/setup.exp" -../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..." -#REMOVEME? ynh_psql_test_if_first_run -ynh_psql_execute_as_root \ - --sql "CREATE USER ${db_user} WITH PASSWORD '${db_pwd}' SUPERUSER CREATEDB CREATEROLE REPLICATION" +#================================================= +# Postgresql superuser +#================================================= +ynh_script_progression --message="Configuring Postgresql superuser..." +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/venv/bin/python3 config_database.py "$db_user" "$db_pwd" +ynh_add_config --template="setup_database.py" --destination "$install_dir/setup_database.py" +"$install_dir/venv/bin/python3" "$install_dir/setup_database.py" "$db_user" "$db_pwd" # Set permission after initialisation ynh_script_progression --message="Protecting directory" @@ -71,6 +60,9 @@ ynh_script_progression --message="Adding system configurations related to $app.. # Create a dedicated NGINX config ynh_add_nginx_config +# Config uwsgi +ynh_add_uwsgi_service "python_version" + ynh_use_logrotate --logfile="/var/log/pgadmin" #=================================================