From a14b2ac829bfbe4db4a10f723a6d319230689c03 Mon Sep 17 00:00:00 2001 From: Yunohost-Bot <> Date: Sat, 31 Aug 2024 00:57:44 +0200 Subject: [PATCH] [autopatch] Automatic patch attempt for helpers 2.1 --- .gitignore | 2 ++ manifest.toml | 3 ++- scripts/_common.sh | 14 +------------- scripts/backup | 11 ++++------- scripts/change_url | 22 +++++++++++----------- scripts/install | 41 ++++++++++++++++++++--------------------- scripts/remove | 18 +++++++++--------- scripts/restore | 29 ++++++++++++++--------------- scripts/upgrade | 43 +++++++++++++++++++++---------------------- 9 files changed, 84 insertions(+), 99 deletions(-) diff --git a/.gitignore b/.gitignore index 5fff14d..e0b4b10 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ *~ Notes *.kate-swp +*.sw[op] +.DS_Store diff --git a/manifest.toml b/manifest.toml index 506149a..1d21cf1 100644 --- a/manifest.toml +++ b/manifest.toml @@ -20,7 +20,8 @@ cpe = "cpe:2.3:a:cloudbees:jenkins" fund = "https://www.jenkins.io/donate" [integration] -yunohost = ">= 11.2" +yunohost = ">= 11.2.18" +helpers_version = "2.1" architectures = "all" multi_instance = false ldap = true diff --git a/scripts/_common.sh b/scripts/_common.sh index 75053b4..679635c 100755 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,11 +1,7 @@ #!/bin/bash #================================================= -# COMMON VARIABLES -#================================================= - -#================================================= -# PERSONAL HELPERS +# COMMON VARIABLES AND CUSTOM HELPERS #================================================= #================================================= @@ -21,11 +17,3 @@ b01_to_bool() { declare -A b01bool=([0]=false [1]=true) echo "${b01bool[$1]}" } - -#================================================= -# EXPERIMENTAL HELPERS -#================================================= - -#================================================= -# FUTURE OFFICIAL HELPERS -#================================================= diff --git a/scripts/backup b/scripts/backup index 3b36061..47d433b 100644 --- a/scripts/backup +++ b/scripts/backup @@ -8,25 +8,22 @@ 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" --not_mandatory +ynh_backup "$install_dir" || true #================================================= # BACKUP THE SYSTEM CONFIGURATION #================================================= -ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # 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 1232e75..1adc659 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -10,38 +10,38 @@ source /usr/share/yunohost/helpers #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." +ynh_script_progression "Stopping $app's systemd service..." -ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" +ynh_systemctl --service=$app --action="stop" --log_path="systemd" #================================================= # MODIFY URL IN NGINX CONF #================================================= -ynh_script_progression --message="Updating NGINX web server configuration..." +ynh_script_progression "Updating NGINX web server configuration..." -ynh_change_url_nginx_config +ynh_config_change_url_nginx #================================================= # MODIFY JENKINS SETUP #================================================= -ynh_script_progression --message="Updating Jenkins setup..." +ynh_script_progression "Updating Jenkins setup..." -ynh_replace_string --target_file="/lib/systemd/system/jenkins.service" \ - --match_string="Environment=\"JENKINS_PREFIX=$old_path\"" \ - --replace_string="Environment=\"JENKINS_PREFIX=$new_path\"" +ynh_replace --file="/lib/systemd/system/jenkins.service" \ + --match="Environment=\"JENKINS_PREFIX=$old_path\"" \ + --replace="Environment=\"JENKINS_PREFIX=$new_path\"" systemctl daemon-reload --quiet #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting $app's systemd service..." --weight=1 +ynh_script_progression "Starting $app's systemd service..." # Start a systemd service -ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" +ynh_systemctl --service="$app" --action="start" --log_path="systemd" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Change of URL completed for $app" +ynh_script_progression "Change of URL completed for $app" diff --git a/scripts/install b/scripts/install index 20e9ecb..04b0fc1 100644 --- a/scripts/install +++ b/scripts/install @@ -16,44 +16,43 @@ jenkins_version=$(ynh_app_upstream_version) #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." +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" ynh_setup_source --source_id="jenkins-plugin-manager" --dest_dir="$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 -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" #================================================= # INSTALL JENKINS #================================================= -ynh_script_progression --message="Installing Jenkins..." +ynh_script_progression "Installing Jenkins..." # Download jenkins deb file and install it. dpkg --install --force-confnew "$install_dir/jenkins.deb" || true dpkg_install_failed=$(dpkg-query -f '${status} ${package}\n' -W | awk '$4 ~ /^jenkins.*/ && $3 != "installed" {print $4}' | wc -l) if [[ $dpkg_install_failed -ge 1 ]]; then - ynh_print_warn --message="The service jenkins cannot be started for now." + ynh_print_warn "The service jenkins cannot be started for now." fi #================================================= # SETUP APPLICATION #================================================= -ynh_script_progression --message="Setting up application on port $port..." +ynh_script_progression "Setting up application on port $port..." echo "$jenkins_version" >> "$install_dir/jenkins.install.InstallUtil.lastExecVersion" echo "$jenkins_version" >> "$install_dir/jenkins.install.UpgradeWizard.state" chown "$app:$app" "$install_dir/jenkins.install.InstallUtil.lastExecVersion" chown "$app:$app" "$install_dir/jenkins.install.UpgradeWizard.state" -ynh_replace_string --target_file="/lib/systemd/system/jenkins.service" \ - --match_string="Environment=\"JENKINS_PORT=8080\"" \ - --replace_string="Environment=\"JENKINS_PORT=$port\"\nEnvironment=\"JENKINS_PREFIX=$path\"" +ynh_replace --file="/lib/systemd/system/jenkins.service" \ + --match="Environment=\"JENKINS_PORT=8080\"" \ + --replace="Environment=\"JENKINS_PORT=$port\"\nEnvironment=\"JENKINS_PREFIX=$path\"" systemctl daemon-reload --quiet -ynh_systemd_action --service_name="$app" --action="restart" --log_path="systemd" +ynh_systemctl --service="$app" --action="restart" --log_path="systemd" if [[ $dpkg_install_failed -ge 1 ]]; then dpkg --configure -a @@ -62,18 +61,18 @@ fi #================================================= # ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Adding a configuration file..." +ynh_script_progression "Adding $app's configuration..." -ynh_add_config --template="config.xml" --destination="$install_dir/config.xml" -chown "$app:$app" "$install_dir/config.xml" +ynh_config_add --template="config.xml" --destination="$install_dir/config.xml" +#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" "$install_dir/config.xml" #================================================= # INSTALL PLUGINS #================================================= -ynh_script_progression --message="Installing plugins..." +ynh_script_progression "Installing plugins..." jenkins_plugin_manager=( - ynh_exec_warn_less java -jar "$install_dir/jenkins-plugin-manager.jar" --war /usr/share/java/jenkins.war --plugin-download-directory="$install_dir/plugins" + ynh_hide_warnings java -jar "$install_dir/jenkins-plugin-manager.jar" --war /usr/share/java/jenkins.war --plugin-download-directory="$install_dir/plugins" ) # Install plugins for http authentication and ldap. @@ -109,10 +108,10 @@ jenkins_plugin_manager=( #================================================= # 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 # Service is provided by the deb package yunohost service add "$app" --description="Jenkins Continuous Integration Server" @@ -120,13 +119,13 @@ yunohost service add "$app" --description="Jenkins Continuous Integration Server #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression "Starting $app's systemd service..." # Start a systemd service -ynh_systemd_action --service_name="$app" --action="restart" --log_path="systemd" +ynh_systemctl --service="$app" --action="restart" --log_path="systemd" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of $app completed" +ynh_script_progression "Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index 05e04f1..af8580c 100644 --- a/scripts/remove +++ b/scripts/remove @@ -10,38 +10,38 @@ 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 -ynh_systemd_action --service_name="$app" --action="stop" --log_path="systemd" +ynh_systemctl --service="$app" --action="stop" --log_path="systemd" # Remove the dedicated NGINX config -ynh_remove_nginx_config +ynh_config_remove_nginx #================================================= # REMOVE DEPENDENCIES #================================================= -ynh_script_progression --message="Removing Jenkins deb packages..." +ynh_script_progression "Removing Jenkins deb packages..." # Remove metapackage and its dependencies -ynh_package_autopurge "$app" +_ynh_apt autoremove --purge "$app" #================================================= # SPECIFIC REMOVE #================================================= # REMOVE VARIOUS FILES #================================================= -ynh_script_progression --message="Removing various files..." +ynh_script_progression "Removing various files..." # Remove a directory securely -ynh_secure_remove --file="/etc/default/jenkins" +ynh_safe_rm "/etc/default/jenkins" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" +ynh_script_progression "Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index b50f757..70a021a 100644 --- a/scripts/restore +++ b/scripts/restore @@ -11,16 +11,15 @@ 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" --not_mandatory - -chown -R "$app:www-data" "$install_dir" +ynh_restore "$install_dir" || true +#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:www-data" "$install_dir" #================================================= # INSTALL JENKINS #================================================= -ynh_script_progression --message="Installing Jenkins..." +ynh_script_progression "Installing Jenkins..." # Download jenkins deb file and install it. ynh_setup_source --dest_dir="../conf" @@ -29,34 +28,34 @@ dpkg --install --force-confnew ../conf/jenkins.deb #================================================= # SETUP APPLICATION #================================================= -ynh_script_progression --message="Setting up $app's service..." +ynh_script_progression "Setting up $app's service..." -ynh_replace_string --target_file="/lib/systemd/system/jenkins.service" \ - --match_string="Environment=\"JENKINS_PORT=8080\"" \ - --replace_string="Environment=\"JENKINS_PORT=$port\"\nEnvironment=\"JENKINS_PREFIX=$path\"" +ynh_replace --file="/lib/systemd/system/jenkins.service" \ + --match="Environment=\"JENKINS_PORT=8080\"" \ + --replace="Environment=\"JENKINS_PORT=$port\"\nEnvironment=\"JENKINS_PREFIX=$path\"" systemctl daemon-reload --quiet #================================================= # 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/nginx/conf.d/$domain.d/$app.conf" +ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf" yunohost service add "$app" --description="Jenkins Continuous Integration Server" #================================================= # RELOAD NGINX AND PHP-FPM OR 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" --action="restart" --log_path="systemd" +ynh_systemctl --service="$app" --action="restart" --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" +ynh_script_progression "Restoration completed for $app" diff --git a/scripts/upgrade b/scripts/upgrade index a52c494..6966772 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -10,62 +10,61 @@ source /usr/share/yunohost/helpers #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping $app's systemd service..." +ynh_script_progression "Stopping $app's systemd service..." -ynh_systemd_action --service_name="$app" --action="stop" --log_path="systemd" +ynh_systemctl --service="$app" --action="stop" --log_path="systemd" #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_script_progression --message="Ensuring downward compatibility..." +ynh_script_progression "Ensuring downward compatibility..." # Remove the apt list entry for jenkins if [ -e "/etc/apt/sources.list.d/jenkins.list" ]; then - ynh_secure_remove --file=/etc/apt/sources.list.d/jenkins.list + ynh_safe_rm /etc/apt/sources.list.d/jenkins.list # Delete the APT key apt-key del "$(apt-key list | grep -B1 "Kohsuke Kawaguchi" | grep pub | cut -d'/' -f2 | cut -d' ' -f1)" apt-get update fi # Remove the log files -ynh_secure_remove --file="/var/log/$app" +ynh_safe_rm "/var/log/$app" # No more needed since systemd -ynh_delete_file_checksum --file="/etc/default/jenkins" +ynh_delete_file_checksum "/etc/default/jenkins" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Upgrading source files..." +ynh_script_progression "Upgrading source files..." # Download jenkins deb file and install it. ynh_setup_source --dest_dir="$install_dir" ynh_setup_source --source_id="jenkins-plugin-manager" --dest_dir="$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 -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" dpkg --install --force-confnew "$install_dir/jenkins.deb" #================================================= # SETUP APPLICATION #================================================= -ynh_script_progression --message="Setting up application..." +ynh_script_progression "Setting up application..." -ynh_replace_string --target_file="/lib/systemd/system/jenkins.service" \ - --match_string="Environment=\"JENKINS_PORT=8080\"" \ - --replace_string="Environment=\"JENKINS_PORT=$port\"\nEnvironment=\"JENKINS_PREFIX=$path\"" +ynh_replace --file="/lib/systemd/system/jenkins.service" \ + --match="Environment=\"JENKINS_PORT=8080\"" \ + --replace="Environment=\"JENKINS_PORT=$port\"\nEnvironment=\"JENKINS_PREFIX=$path\"" systemctl daemon-reload --quiet -ynh_systemd_action --service_name="$app" --action="restart" --log_path="systemd" +ynh_systemctl --service="$app" --action="restart" --log_path="systemd" #================================================= # UPGRADE PLUGINS #================================================= -ynh_script_progression --message="Upgrading plugins..." +ynh_script_progression "Upgrading plugins..." jenkins_plugin_manager=( - ynh_exec_warn_less java -jar "$install_dir/jenkins-plugin-manager.jar" --war /usr/share/java/jenkins.war --plugin-download-directory="$install_dir/plugins" + ynh_hide_warnings java -jar "$install_dir/jenkins-plugin-manager.jar" --war /usr/share/java/jenkins.war --plugin-download-directory="$install_dir/plugins" ) mapfile -t UPDATE_LIST < <("${jenkins_plugin_manager[@]}" --list | grep -o '.*\..*' | grep -oP '^(.*?) ') @@ -76,21 +75,21 @@ done #================================================= # REAPPLY SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 +ynh_script_progression "Upgrading system configurations related to $app..." -ynh_add_nginx_config +ynh_config_add_nginx yunohost service add "$app" --description="Jenkins Continuous Integration Server" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting $app's systemd service..." +ynh_script_progression "Starting $app's systemd service..." -ynh_systemd_action --service_name="$app" --action="restart" --log_path="systemd" +ynh_systemctl --service="$app" --action="restart" --log_path="systemd" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" +ynh_script_progression "Upgrade of $app completed"