diff --git a/.gitignore b/.gitignore index 4c3f96c..9d6d968 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,6 @@ auto_update_config.sh auto_update/Synapse_build_*.log auto_update/synapse_build_temp.log +*~ +*.sw[op] +.DS_Store diff --git a/manifest.toml b/manifest.toml index 6b9664f..f2f90bf 100644 --- a/manifest.toml +++ b/manifest.toml @@ -18,7 +18,8 @@ admindoc = "https://www.pgadmin.org/docs" cpe = "cpe:2.3:a:pgadmin:pgadmin" [integration] -yunohost = ">= 11.2" +yunohost = ">= 11.2.18" +helpers_version = "2.1" architectures = "all" multi_instance = true ldap = true diff --git a/scripts/_common.sh b/scripts/_common.sh index 47b6a19..c2a7916 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -13,21 +13,21 @@ postgresql_version="$(psql -V | cut -d' ' -f3 | cut -d. -f1)" install_source() { # 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 + ynh_safe_rm "$install_dir"/bin + ynh_safe_rm "$install_dir"/lib + ynh_safe_rm "$install_dir"/lib64 + ynh_safe_rm "$install_dir"/include + ynh_safe_rm "$install_dir"/share + ynh_safe_rm "$install_dir"/pyvenv.cfg # Clean venv is it was on python with an old version in case major upgrade of debian 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 + ynh_safe_rm "$install_dir"/venv/bin + ynh_safe_rm "$install_dir"/venv/lib + ynh_safe_rm "$install_dir"/venv/lib64 + ynh_safe_rm "$install_dir"/venv/include + ynh_safe_rm "$install_dir"/venv/share + ynh_safe_rm "$install_dir"/venv/pyvenv.cfg fi if uname -m | grep -q arm @@ -37,7 +37,7 @@ install_source() { # Fix multi-instance support for f in "$install_dir"/venv/bin/*; do if ! [[ $f =~ "__" ]]; then - ynh_replace_special_string --match_string='#!'/opt/yunohost/pgadmin/venv --replace_string='#!'"$install_dir"/venv --target_file="$f" + ynh_replace_regex --match='#!'/opt/yunohost/pgadmin/venv --replace='#!'"$install_dir"/venv --file="$f" fi done else @@ -71,16 +71,15 @@ install_source() { set_permission() { # Set permission - chown "$app:$app" -R "$install_dir" - chmod u+rw,o= -R "$install_dir" + #REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown "$app:$app" -R "$install_dir" + #REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | 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" + #REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown "$app:$app" -R /var/log/"$app" + #REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod u=rwX,g=rX,o= -R /var/log/"$app" # Criticals files - chown "$app":root "$data_dir"/master_pwd - chmod u=r,g=,o= "$data_dir"/master_pwd + #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown "$app":root "$data_dir"/master_pwd + #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | 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 } - diff --git a/scripts/backup b/scripts/backup index 39bd4a3..09069eb 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,48 +1,39 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/experimental_helper.sh source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# DECLARE DATA AND CONF FILES TO BACKUP -#================================================= -ynh_print_info --message="Declaring files to be backed up..." +ynh_print_info "Declaring files to be backed up..." #================================================= # BACKUP THE APP MAIN DIR #================================================= -ynh_backup --src_path="$install_dir" +ynh_backup "$install_dir" #================================================= # BACKUP DATA #================================================= -ynh_backup --src_path="$data_dir" --is_big=1 +ynh_backup "$data_dir" #================================================= # SYSTEM CONFIGURATION #================================================= -ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" -ynh_backup --src_path=/etc/systemd/system/$app.service +ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_backup /etc/systemd/system/$app.service #================================================= # BACKUP VARIOUS FILES #================================================= -ynh_backup --src_path="/var/log/$app" +ynh_backup "/var/log/$app" #================================================= # END OF SCRIPT #================================================= -ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." +ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/change_url b/scripts/change_url index 3940ef6..a9631cf 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -1,31 +1,23 @@ #!/bin/bash -#================================================= -# GENERIC STARTING -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - # Import common cmd source experimental_helper.sh source _common.sh source /usr/share/yunohost/helpers -#================================================= -# STANDARD MODIFICATIONS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=1 +ynh_script_progression "Stopping $app's systemd service..." -ynh_systemd_action --service_name="$app.service" --action="stop" --log_path="/var/log/$app/$app.log" +ynh_systemctl --service="$app.service" --action="stop" #================================================= # MODIFY URL IN NGINX CONF #================================================= -ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1 +ynh_script_progression "Updating NGINX web server configuration..." -ynh_change_url_nginx_config +ynh_config_change_url_nginx #================================================= # SPECIFIC MODIFICATIONS @@ -33,18 +25,16 @@ ynh_change_url_nginx_config set_permission -#================================================= -# GENERIC FINALISATION #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=3 +ynh_script_progression "Starting $app's systemd service..." # Start a systemd service -ynh_systemd_action --service_name="$app.service" --action="restart" --line_match="Listening at: unix:/run/$app/app.socket" --log_path=systemd +ynh_systemctl --service="$app.service" --action="restart" --wait_until="Listening at: unix:/run/$app/app.socket" --log_path=systemd #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Change of URL completed for $app" --last +ynh_script_progression "Change of URL completed for $app" diff --git a/scripts/install b/scripts/install index 5ab0f21..c56ef54 100644 --- a/scripts/install +++ b/scripts/install @@ -1,11 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source experimental_helper.sh source _common.sh source /usr/share/yunohost/helpers @@ -13,12 +7,11 @@ source /usr/share/yunohost/helpers #================================================= # Postgresql superuser #================================================= -ynh_script_progression --message="Configuring Postgresql superuser..." --weight=1 +ynh_script_progression "Configuring Postgresql superuser..." -ynh_psql_execute_as_root --sql="ALTER USER $db_user WITH SUPERUSER CREATEDB CREATEROLE REPLICATION" +ynh_psql_db_shell <<< "ALTER USER $db_user WITH SUPERUSER CREATEDB CREATEROLE REPLICATION" - -ynh_script_progression --message='Creating base directory...' +ynh_script_progression 'Creating base directory...' if [ -n "$(ls -A "$data_dir")" ]; then old_data_dir_path="${data_dir}_$(date '+%Y%m%d.%H%M%S')" @@ -32,17 +25,17 @@ mkdir -p /var/log/"$app" # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." --weight=5 +ynh_script_progression "Setting up source files..." install_source #================================================= # ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Configuring pgAdmin..." --weight=1 +ynh_script_progression "Configuring pgAdmin..." -ynh_add_config --template="config_local.py" --destination="$install_dir/venv/lib/python$python_version/site-packages/pgadmin4/config_local.py" -ynh_add_config --template=postgres-reg.ini --destination="$install_dir"/postgres-reg.ini +ynh_config_add --template="config_local.py" --destination="$install_dir/venv/lib/python$python_version/site-packages/pgadmin4/config_local.py" +ynh_config_add --template=postgres-reg.ini --destination="$install_dir"/postgres-reg.ini ynh_string_random --length=60 > "$data_dir"/master_pwd set_permission @@ -51,28 +44,28 @@ $install_dir/venv/bin/python3 "$install_dir/venv/lib/python$python_version/site- #================================================= # SYSTEM CONFIGURATION #================================================= -ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 +ynh_script_progression "Adding system configurations related to $app..." # Create a dedicated NGINX config -ynh_add_nginx_config +ynh_config_add_nginx # Add systemd config -ynh_add_systemd_config --service=$app --template=pgadmin.service +ynh_config_add_systemd --template=pgadmin.service yunohost service add $app --log "/var/log/$app/$app.log" --description 'PgAdmin application' -ynh_use_logrotate --logfile="/var/log/$app" +ynh_config_add_logrotate "/var/log/$app" set_permission #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=3 +ynh_script_progression "Starting $app's systemd service..." -ynh_systemd_action --service_name="$app.service" --action="restart" --line_match="Listening at: unix:/run/$app/app.socket" --log_path=systemd +ynh_systemctl --service="$app.service" --action="restart" --wait_until="Listening at: unix:/run/$app/app.socket" --log_path=systemd #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of $app completed" --last +ynh_script_progression "Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index 500aec0..fafac7b 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,11 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source experimental_helper.sh source _common.sh source /usr/share/yunohost/helpers @@ -13,21 +7,22 @@ source /usr/share/yunohost/helpers #================================================= # REMOVE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 +ynh_script_progression "Removing system configurations related to $app..." # Stop service -ynh_systemd_action --service_name="$app.service" --action=stop -ynh_remove_systemd_config --service="$app" +ynh_systemctl --service="$app.service" --action=stop +ynh_config_remove_systemd + yunohost service remove "$app" # Remove the app-specific logrotate config -ynh_remove_logrotate +ynh_config_remove_logrotate # Remove the dedicated NGINX config -ynh_remove_nginx_config +ynh_config_remove_nginx #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" --last +ynh_script_progression "Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index fa7e905..151c18b 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,11 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/experimental_helper.sh source ../settings/scripts/_common.sh @@ -14,28 +8,27 @@ source /usr/share/yunohost/helpers #================================================= # RESTORE THE POSTGRESQL SUPERUSER #================================================= -ynh_script_progression --message="Restoring the Postgresql superuser..." --weight=1 +ynh_script_progression "Restoring the Postgresql superuser..." -ynh_psql_execute_as_root --sql="ALTER USER $app WITH SUPERUSER CREATEDB CREATEROLE REPLICATION" +ynh_psql_db_shell <<< "ALTER USER $app WITH SUPERUSER CREATEDB CREATEROLE REPLICATION" #================================================= # RESTORE ALL CONFIG AND DATA #================================================= -ynh_script_progression --message="Restoring directory and configuration..." --weight=10 -ynh_restore - +ynh_script_progression "Restoring directory and configuration..." +ynh_restore_everything #================================================= # REINSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Updating python virtualenv..." --weight=5 +ynh_script_progression "Updating python virtualenv..." install_source #================================================= # RESTORE SYSTEMD #================================================= -ynh_script_progression --message="Enable systemd services" --weight=2 +ynh_script_progression "Enable systemd services" # systemctl daemon-reload systemctl enable "$app".service --quiet @@ -43,19 +36,17 @@ yunohost service add "$app" --log "/var/log/$app/$app.log" --description 'PgAdmi set_permission -#================================================= -# GENERIC FINALIZATION #================================================= # RELOAD NGINX AND THE APP SERVICE #================================================= -ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1 +ynh_script_progression "Reloading NGINX web server and $app's service..." -ynh_systemd_action --service_name="$app.service" --action="restart" --line_match="Listening at: unix:/run/$app/app.socket" --log_path=systemd +ynh_systemctl --service="$app.service" --action="restart" --wait_until="Listening at: unix:/run/$app/app.socket" --log_path=systemd -ynh_systemd_action --service_name=nginx --action=reload +ynh_systemctl --service=nginx --action=reload #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed for $app" --last +ynh_script_progression "Restoration completed for $app" diff --git a/scripts/upgrade b/scripts/upgrade index 2bb0f87..788143f 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,53 +1,45 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source experimental_helper.sh source _common.sh source /usr/share/yunohost/helpers -#================================================= -# STANDARD UPGRADE STEPS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=1 +ynh_script_progression "Stopping $app's systemd service..." if [ -f "/etc/uwsgi/apps-available/$app.ini" ]; then - ynh_systemd_action --service_name="uwsgi-app@$app.service" --action=stop + ynh_systemctl --service="uwsgi-app@$app.service" --action=stop systemctl disable "uwsgi-app@$app.service" --quiet yunohost service remove "uwsgi-app@$app" || true - ynh_secure_remove --file="/etc/uwsgi/apps-available/$app.ini" - ynh_secure_remove --file="/etc/systemd/system/uwsgi-app@$app.service.d" + ynh_safe_rm "/etc/uwsgi/apps-available/$app.ini" + ynh_safe_rm "/etc/systemd/system/uwsgi-app@$app.service.d" else - ynh_systemd_action --service_name="$app.service" --action=stop + ynh_systemctl --service="$app.service" --action=stop fi #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_script_progression --message="Ensuring downward compatibility..." --weight=2 +ynh_script_progression "Ensuring downward compatibility..." # Clean old uwsgi config -ynh_secure_remove /etc/uwsgi/apps-enabled/pgadmin.ini +ynh_safe_rm /etc/uwsgi/apps-enabled/pgadmin.ini # Migrate data path if [ -d "/var/lib/pgadmin" ]; then if [ ! -d "$install_dir/data" ]; then mv -t "$data_dir" /var/lib/pgadmin/* fi - ynh_secure_remove "/var/lib/pgadmin" + ynh_safe_rm "/var/lib/pgadmin" fi if [ -d "$install_dir/data" ]; then if [ ! -d "$install_dir/data" ]; then mv -t "$data_dir" "$install_dir"/data/* fi - ynh_secure_remove "$install_dir/data" + ynh_safe_rm "$install_dir/data" fi if [ ! -e "$data_dir"/master_pwd ]; then ynh_string_random --length=60 > "$data_dir"/master_pwd @@ -56,53 +48,53 @@ fi #================================================= # Postgresql superuser #================================================= -ynh_script_progression --message="Configuring Postgresql superuser..." --weight=1 +ynh_script_progression "Configuring Postgresql superuser..." # Re-set the db_pwd just in case… -ynh_psql_execute_as_root --sql="ALTER USER $app WITH PASSWORD '$db_pwd' SUPERUSER CREATEDB CREATEROLE REPLICATION" +ynh_psql_db_shell <<< "ALTER USER $app WITH PASSWORD '$db_pwd' SUPERUSER CREATEDB CREATEROLE REPLICATION" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Upgrading source files..." --weight=6 +ynh_script_progression "Upgrading source files..." install_source #================================================= # UPDATE A CONFIG FILE #================================================= -ynh_script_progression --message="Updating a configuration file..." --weight=1 +ynh_script_progression "Updating configuration..." # CONFIGURE PGADMIN -ynh_add_config --template="config_local.py" --destination="$install_dir/venv/lib/python$python_version/site-packages/pgadmin4/config_local.py" -ynh_add_config --template=postgres-reg.ini --destination="$install_dir"/postgres-reg.ini +ynh_config_add --template="config_local.py" --destination="$install_dir/venv/lib/python$python_version/site-packages/pgadmin4/config_local.py" +ynh_config_add --template=postgres-reg.ini --destination="$install_dir"/postgres-reg.ini #================================================= # REAPPLY SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 +ynh_script_progression "Upgrading system configurations related to $app..." # Create a dedicated NGINX config -ynh_add_nginx_config +ynh_config_add_nginx # Add systemd config -ynh_add_systemd_config --service="$app" --template=pgadmin.service +ynh_config_add_systemd --template=pgadmin.service yunohost service add "$app" --log "/var/log/$app/$app.log" --description 'PgAdmin application' # Use logrotate to manage app-specific logfile(s) -ynh_use_logrotate --logfile=/var/log/"$app" --nonappend +ynh_config_add_logrotate /var/log/"$app" set_permission #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=3 +ynh_script_progression "Starting $app's systemd service..." -ynh_systemd_action --service_name="$app.service" --action="restart" --line_match="Listening at: unix:/run/$app/app.socket" --log_path=systemd +ynh_systemctl --service="$app.service" --action="restart" --wait_until="Listening at: unix:/run/$app/app.socket" --log_path=systemd #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --last +ynh_script_progression "Upgrade of $app completed"