diff --git a/.gitignore b/.gitignore index 783a4ae..8f144f3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *~ *.sw[op] +.DS_Store diff --git a/manifest.toml b/manifest.toml index b8aabfa..e600d39 100644 --- a/manifest.toml +++ b/manifest.toml @@ -17,7 +17,8 @@ code = "https://git.sr.ht/~int80h/gemserv" website = "https://git.sr.ht/~int80h/gemserv/" [integration] -yunohost = ">= 11.2.27" +yunohost = ">= 11.2.18" +helpers_version = "2.1" architectures = "all" multi_instance = false ldap = "not_relevant" diff --git a/scripts/_common.sh b/scripts/_common.sh index 944a65e..3d7f008 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,17 +1,5 @@ #!/bin/bash #================================================= -# COMMON VARIABLES -#================================================= - -#================================================= -# PERSONAL HELPERS -#================================================= - -#================================================= -# EXPERIMENTAL HELPERS -#================================================= - -#================================================= -# FUTURE OFFICIAL HELPERS +# COMMON VARIABLES AND CUSTOM HELPERS #================================================= diff --git a/scripts/backup b/scripts/backup index dd4c1fc..c66b80a 100755 --- a/scripts/backup +++ b/scripts/backup @@ -1,25 +1,16 @@ #!/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/_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" #================================================= # SPECIFIC BACKUP @@ -27,14 +18,14 @@ ynh_backup --src_path="$install_dir" # BACKUP LOGROTATE #================================================= -ynh_backup --src_path="/etc/logrotate.d/$app" +ynh_backup "/etc/logrotate.d/$app" -ynh_backup --src_path="/etc/systemd/system/$app.service" +ynh_backup "/etc/systemd/system/$app.service" -ynh_backup --src_path="/etc/$app/" +ynh_backup "/etc/$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/install b/scripts/install index e92be28..7d04f97 100755 --- a/scripts/install +++ b/scripts/install @@ -1,73 +1,66 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers #================================================= # CREATE DEDICATED USER #================================================= -ynh_script_progression --message="Configuring system user..." --weight=1 +ynh_script_progression "Configuring system user..." usermod -a -G ssl-cert "$app" #================================================= # INSTALL RUST/CARGO #================================================= -ynh_script_progression --message="Installing Rust and Cargo..." --weight=1 +ynh_script_progression "Installing Rust and Cargo..." # Install rustup with the toolchain needed by Gemserv pushd "$install_dir" - ynh_exec_warn_less ynh_exec_as "$app" \ + ynh_hide_warnings ynh_exec_as_app \ RUSTUP_HOME="$install_dir/.rustup" \ CARGO_HOME="$install_dir/.cargo" \ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \ - | ynh_exec_as "$app" sh -s -- -q -y + | ynh_exec_as_app sh -s -- -q -y popd #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." --weight=1 +ynh_script_progression "Setting up source files..." # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$install_dir/build" mkdir -p "$install_dir/live" -chmod 750 "$install_dir" -chmod -R o-rwx "$install_dir" -chown -R "$app:$app" "$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 750 "$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 -R o-rwx "$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 -R "$app:$app" "$install_dir" #================================================= # SPECIFIC SETUP #================================================= # BUILD APP #================================================= -ynh_script_progression --message="Building app..." --weight=1 +ynh_script_progression "Building app..." # Compile Gemserv pushd "$install_dir/build" - ynh_exec_warn_less ynh_exec_as "$app" bash -c "source $install_dir/.cargo/env; cargo build --release" + ynh_hide_warnings ynh_exec_as_app bash -c "source $install_dir/.cargo/env; cargo build --release" popd # Install Gemserv cp -af "$install_dir/build/target/release/gemserv" "$install_dir/live/gemserv" # Remove build files and rustup -ynh_secure_remove --file="$install_dir/build" -ynh_secure_remove --file="$install_dir/.cargo" -ynh_secure_remove --file="$install_dir/.rustup" +ynh_safe_rm "$install_dir/build" +ynh_safe_rm "$install_dir/.cargo" +ynh_safe_rm "$install_dir/.rustup" #================================================= # ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Adding a configuration file..." --weight=1 +ynh_script_progression "Adding $app's configuration..." mkdir -p "/etc/$app/config.d/" @@ -75,35 +68,35 @@ chmod 750 "/etc/$app" chmod -R o-rwx "/etc/$app" chown -R "$app:$app" "/etc/$app" -ynh_add_config --template="server.toml" --destination="/etc/$app/config.d/server.toml.head" +ynh_config_add --template="server.toml" --destination="/etc/$app/config.d/server.toml.head" -chmod 600 "/etc/$app/config.d/server.toml.head" -chown "$app:$app" "/etc/$app/config.d/server.toml.head" +#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 600 "/etc/$app/config.d/server.toml.head" +#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:$app" "/etc/$app/config.d/server.toml.head" #================================================= # 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 systemd config -ynh_add_systemd_config +ynh_config_add_systemd yunohost service add "$app" --description="$app daemon" --log="/var/log/$app/$app.log" --needs_exposed_ports="1965" mkdir -p "/var/log/$app" -chmod 640 "/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 640 "/var/log/$app" # Use logrotate to manage application logfile(s) -ynh_use_logrotate +ynh_config_add_logrotate #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 +ynh_script_progression "Starting $app's systemd service..." -ynh_systemd_action --service_name="$app" --action="start" --line_match="Started" --log_path="systemd" +ynh_systemctl --service="$app" --action="start" --wait_until="Started" --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 b2c2217..d2c923a 100755 --- a/scripts/remove +++ b/scripts/remove @@ -1,35 +1,29 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh 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..." # Remove the service from the list of services known by YunoHost (added from `yunohost service add`) -if ynh_exec_warn_less yunohost service status $app >/dev/null; then +if ynh_hide_warnings yunohost service status $app >/dev/null; then yunohost service remove $app fi # Remove the dedicated systemd config -ynh_remove_systemd_config +ynh_config_remove_systemd # Remove the app-specific logrotate config -ynh_remove_logrotate +ynh_config_remove_logrotate # Remove a directory securely -ynh_secure_remove --file="/etc/$app" +ynh_safe_rm "/etc/$app" #================================================= # 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 31bdc39..c2953ba 100755 --- 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/_common.sh source /usr/share/yunohost/helpers @@ -13,46 +7,43 @@ source /usr/share/yunohost/helpers #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring the app main directory..." --weight=1 +ynh_script_progression "Restoring the app main directory..." -ynh_restore_file --origin_path="$install_dir" - -chmod 750 "$install_dir" -chmod -R o-rwx "$install_dir" -chown -R "$app:$app" "$install_dir" +ynh_restore "$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 750 "$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 -R o-rwx "$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 -R "$app:$app" "$install_dir" #================================================= # RESTORE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 +ynh_script_progression "Restoring system configurations related to $app..." -ynh_restore_file --origin_path="/etc/systemd/system/$app.service" +ynh_restore "/etc/systemd/system/$app.service" systemctl enable "$app.service" --quiet yunohost service add "$app" --description="$app daemon" --log="/var/log/$app/$app.log" --needs_exposed_ports="1965" mkdir -p "/var/log/$app" -chmod 640 "/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 640 "/var/log/$app" -ynh_restore_file --origin_path="/etc/logrotate.d/$app" +ynh_restore "/etc/logrotate.d/$app" #================================================= # RESTORE VARIOUS FILES #================================================= -ynh_script_progression --message="Restoring various files..." --weight=1 +ynh_script_progression "Restoring various files..." -ynh_restore_file --origin_path="/etc/$app/" +ynh_restore "/etc/$app/" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 +ynh_script_progression "Starting $app's systemd service..." -ynh_systemd_action --service_name="$app" --action="start" --line_match="Started" --log_path="systemd" +ynh_systemctl --service="$app" --action="start" --wait_until="Started" --log_path="systemd" -#================================================= -# GENERIC FINALIZATION #================================================= # 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 673edf9..31778bb 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,95 +1,84 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - 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..." -ynh_systemd_action --service_name=$app --action="stop" --line_match="Stopped" --log_path="systemd" +ynh_systemctl --service=$app --action="stop" --wait_until="Stopped" --log_path="systemd" #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 +ynh_script_progression "Ensuring downward compatibility..." # Change to head file if [ -f "/etc/$app/config.d/server.toml" ]; then - ynh_delete_file_checksum --file="/etc/$app/config.d/server.toml" + ynh_delete_file_checksum "/etc/$app/config.d/server.toml" mv "/etc/$app/config.d/server.toml" "/etc/$app/config.d/server.toml.head" - ynh_store_file_checksum --file="/etc/$app/config.d/server.toml.head" + ynh_store_file_checksum "/etc/$app/config.d/server.toml.head" fi #================================================= # CREATE DEDICATED USER #================================================= -ynh_script_progression --message="Configuring system user..." --weight=1 +ynh_script_progression "Configuring system user..." usermod -a -G ssl-cert "$app" #================================================= # INSTALL RUST/CARGO #================================================= -ynh_script_progression --message="Installing Rust and Cargo..." --weight=1 +ynh_script_progression "Installing Rust and Cargo..." # Install rustup with the toolchain needed by Gemserv pushd "$install_dir" - ynh_exec_warn_less ynh_exec_as "$app" \ + ynh_hide_warnings ynh_exec_as_app \ RUSTUP_HOME="$install_dir/.rustup" \ CARGO_HOME="$install_dir/.cargo" \ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \ - | ynh_exec_as "$app" sh -s -- -q -y + | ynh_exec_as_app sh -s -- -q -y popd #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Upgrading source files..." --weight=1 +ynh_script_progression "Upgrading source files..." # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$install_dir/build" -ynh_secure_remove --file="$install_dir/live" +ynh_safe_rm "$install_dir/live" mkdir -p "$install_dir/live" -chmod 750 "$install_dir" -chmod -R o-rwx "$install_dir" -chown -R "$app:$app" "$install_dir" - -#================================================= -# SPECIFIC UPGRADE +#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 750 "$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 -R o-rwx "$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 -R "$app:$app" "$install_dir" #================================================= # BUILD APP #================================================= -ynh_script_progression --message="Building app..." --weight=1 +ynh_script_progression "Building app..." # Compile Gemserv pushd "$install_dir/build" - ynh_exec_warn_less ynh_exec_as "$app" bash -c "source $install_dir/.cargo/env; cargo build --release" + ynh_hide_warnings ynh_exec_as_app bash -c "source $install_dir/.cargo/env; cargo build --release" popd # Install Gemserv cp -af "$install_dir/build/target/release/gemserv" "$install_dir/live/gemserv" # Remove build files and rustup -ynh_secure_remove --file="$install_dir/build" -ynh_secure_remove --file="$install_dir/.cargo" -ynh_secure_remove --file="$install_dir/.rustup" +ynh_safe_rm "$install_dir/build" +ynh_safe_rm "$install_dir/.cargo" +ynh_safe_rm "$install_dir/.rustup" #================================================= # UPDATE A CONFIG FILE #================================================= -ynh_script_progression --message="Updating a configuration file..." --weight=1 +ynh_script_progression "Updating configuration..." mkdir -p "/etc/$app/config.d/" @@ -97,35 +86,35 @@ chmod 750 "/etc/$app" chmod -R o-rwx "/etc/$app" chown -R "$app:$app" "/etc/$app" -ynh_add_config --template="server.toml" --destination="/etc/$app/config.d/server.toml.head" +ynh_config_add --template="server.toml" --destination="/etc/$app/config.d/server.toml.head" -chmod 600 "/etc/$app/config.d/server.toml.head" -chown "$app:$app" "/etc/$app/config.d/server.toml.head" +#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 600 "/etc/$app/config.d/server.toml.head" +#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:$app" "/etc/$app/config.d/server.toml.head" #================================================= # 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 systemd config -ynh_add_systemd_config +ynh_config_add_systemd yunohost service add "$app" --description="$app daemon" --log="/var/log/$app/$app.log" --needs_exposed_ports="1965" mkdir -p "/var/log/$app" -chmod 640 "/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 640 "/var/log/$app" # Use logrotate to manage app-specific logfile(s) -ynh_use_logrotate --non-append +ynh_config_add_logrotate #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 +ynh_script_progression "Starting $app's systemd service..." -ynh_systemd_action --service_name="$app" --action="start" --line_match="Started" --log_path="systemd" +ynh_systemctl --service="$app" --action="start" --wait_until="Started" --log_path="systemd" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --last +ynh_script_progression "Upgrade of $app completed"