1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/jenkins_ynh.git synced 2024-09-03 19:26:18 +02:00

[autopatch] Automatic patch attempt for helpers 2.1

This commit is contained in:
Yunohost-Bot 2024-08-31 00:57:44 +02:00 committed by Alexandre Aubin
parent 564fd0bbfc
commit a14b2ac829
9 changed files with 84 additions and 99 deletions

2
.gitignore vendored
View file

@ -2,3 +2,5 @@
*~ *~
Notes Notes
*.kate-swp *.kate-swp
*.sw[op]
.DS_Store

View file

@ -20,7 +20,8 @@ cpe = "cpe:2.3:a:cloudbees:jenkins"
fund = "https://www.jenkins.io/donate" fund = "https://www.jenkins.io/donate"
[integration] [integration]
yunohost = ">= 11.2" yunohost = ">= 11.2.18"
helpers_version = "2.1"
architectures = "all" architectures = "all"
multi_instance = false multi_instance = false
ldap = true ldap = true

View file

@ -1,11 +1,7 @@
#!/bin/bash #!/bin/bash
#================================================= #=================================================
# COMMON VARIABLES # COMMON VARIABLES AND CUSTOM HELPERS
#=================================================
#=================================================
# PERSONAL HELPERS
#================================================= #=================================================
#================================================= #=================================================
@ -21,11 +17,3 @@ b01_to_bool() {
declare -A b01bool=([0]=false [1]=true) declare -A b01bool=([0]=false [1]=true)
echo "${b01bool[$1]}" echo "${b01bool[$1]}"
} }
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================

View file

@ -8,25 +8,22 @@
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= ynh_print_info "Declaring files to be backed up..."
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
ynh_print_info --message="Declaring files to be backed up..."
#================================================= #=================================================
# BACKUP THE APP MAIN DIR # BACKUP THE APP MAIN DIR
#================================================= #=================================================
ynh_backup --src_path="$install_dir" --not_mandatory ynh_backup "$install_dir" || true
#================================================= #=================================================
# BACKUP THE SYSTEM CONFIGURATION # 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 # 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)."

View file

@ -10,38 +10,38 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
# STOP SYSTEMD SERVICE # 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 # 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 # 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" \ ynh_replace --file="/lib/systemd/system/jenkins.service" \
--match_string="Environment=\"JENKINS_PREFIX=$old_path\"" \ --match="Environment=\"JENKINS_PREFIX=$old_path\"" \
--replace_string="Environment=\"JENKINS_PREFIX=$new_path\"" --replace="Environment=\"JENKINS_PREFIX=$new_path\""
systemctl daemon-reload --quiet systemctl daemon-reload --quiet
#================================================= #=================================================
# START SYSTEMD SERVICE # 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 # 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 # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Change of URL completed for $app" ynh_script_progression "Change of URL completed for $app"

View file

@ -16,44 +16,43 @@ jenkins_version=$(ynh_app_upstream_version)
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # 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 # Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir" ynh_setup_source --dest_dir="$install_dir"
ynh_setup_source --source_id="jenkins-plugin-manager" --dest_dir="$install_dir" ynh_setup_source --source_id="jenkins-plugin-manager" --dest_dir="$install_dir"
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 | 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 | chown -R "$app:$app" "$install_dir"
#================================================= #=================================================
# INSTALL JENKINS # INSTALL JENKINS
#================================================= #=================================================
ynh_script_progression --message="Installing Jenkins..." ynh_script_progression "Installing Jenkins..."
# Download jenkins deb file and install it. # Download jenkins deb file and install it.
dpkg --install --force-confnew "$install_dir/jenkins.deb" || true 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) 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 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 fi
#================================================= #=================================================
# SETUP APPLICATION # 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.InstallUtil.lastExecVersion"
echo "$jenkins_version" >> "$install_dir/jenkins.install.UpgradeWizard.state" 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.InstallUtil.lastExecVersion"
chown "$app:$app" "$install_dir/jenkins.install.UpgradeWizard.state" chown "$app:$app" "$install_dir/jenkins.install.UpgradeWizard.state"
ynh_replace_string --target_file="/lib/systemd/system/jenkins.service" \ ynh_replace --file="/lib/systemd/system/jenkins.service" \
--match_string="Environment=\"JENKINS_PORT=8080\"" \ --match="Environment=\"JENKINS_PORT=8080\"" \
--replace_string="Environment=\"JENKINS_PORT=$port\"\nEnvironment=\"JENKINS_PREFIX=$path\"" --replace="Environment=\"JENKINS_PORT=$port\"\nEnvironment=\"JENKINS_PREFIX=$path\""
systemctl daemon-reload --quiet 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 if [[ $dpkg_install_failed -ge 1 ]]; then
dpkg --configure -a dpkg --configure -a
@ -62,18 +61,18 @@ fi
#================================================= #=================================================
# ADD A CONFIGURATION # 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" ynh_config_add --template="config.xml" --destination="$install_dir/config.xml"
chown "$app:$app" "$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 # INSTALL PLUGINS
#================================================= #=================================================
ynh_script_progression --message="Installing plugins..." ynh_script_progression "Installing plugins..."
jenkins_plugin_manager=( 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. # Install plugins for http authentication and ldap.
@ -109,10 +108,10 @@ jenkins_plugin_manager=(
#================================================= #=================================================
# SYSTEM CONFIGURATION # 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 # Create a dedicated NGINX config
ynh_add_nginx_config ynh_config_add_nginx
# Service is provided by the deb package # Service is provided by the deb package
yunohost service add "$app" --description="Jenkins Continuous Integration Server" 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 # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." ynh_script_progression "Starting $app's systemd service..."
# Start a 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 # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Installation of $app completed" ynh_script_progression "Installation of $app completed"

View file

@ -10,38 +10,38 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
# REMOVE SYSTEM CONFIGURATIONS # 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`) # 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" yunohost service remove "$app"
fi 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 # Remove the dedicated NGINX config
ynh_remove_nginx_config ynh_config_remove_nginx
#================================================= #=================================================
# REMOVE DEPENDENCIES # REMOVE DEPENDENCIES
#================================================= #=================================================
ynh_script_progression --message="Removing Jenkins deb packages..." ynh_script_progression "Removing Jenkins deb packages..."
# Remove metapackage and its dependencies # Remove metapackage and its dependencies
ynh_package_autopurge "$app" _ynh_apt autoremove --purge "$app"
#================================================= #=================================================
# SPECIFIC REMOVE # SPECIFIC REMOVE
#================================================= #=================================================
# REMOVE VARIOUS FILES # REMOVE VARIOUS FILES
#================================================= #=================================================
ynh_script_progression --message="Removing various files..." ynh_script_progression "Removing various files..."
# Remove a directory securely # Remove a directory securely
ynh_secure_remove --file="/etc/default/jenkins" ynh_safe_rm "/etc/default/jenkins"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Removal of $app completed" ynh_script_progression "Removal of $app completed"

View file

@ -11,16 +11,15 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
# RESTORE THE APP MAIN DIR # 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 ynh_restore "$install_dir" || true
chown -R "$app:www-data" "$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:www-data" "$install_dir"
#================================================= #=================================================
# INSTALL JENKINS # INSTALL JENKINS
#================================================= #=================================================
ynh_script_progression --message="Installing Jenkins..." ynh_script_progression "Installing Jenkins..."
# Download jenkins deb file and install it. # Download jenkins deb file and install it.
ynh_setup_source --dest_dir="../conf" ynh_setup_source --dest_dir="../conf"
@ -29,34 +28,34 @@ dpkg --install --force-confnew ../conf/jenkins.deb
#================================================= #=================================================
# SETUP APPLICATION # 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" \ ynh_replace --file="/lib/systemd/system/jenkins.service" \
--match_string="Environment=\"JENKINS_PORT=8080\"" \ --match="Environment=\"JENKINS_PORT=8080\"" \
--replace_string="Environment=\"JENKINS_PORT=$port\"\nEnvironment=\"JENKINS_PREFIX=$path\"" --replace="Environment=\"JENKINS_PORT=$port\"\nEnvironment=\"JENKINS_PREFIX=$path\""
systemctl daemon-reload --quiet systemctl daemon-reload --quiet
#================================================= #=================================================
# RESTORE SYSTEM CONFIGURATIONS # 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" yunohost service add "$app" --description="Jenkins Continuous Integration Server"
#================================================= #=================================================
# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE # 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 # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Restoration completed for $app" ynh_script_progression "Restoration completed for $app"

View file

@ -10,62 +10,61 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
# STOP SYSTEMD SERVICE # 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 # ENSURE DOWNWARD COMPATIBILITY
#================================================= #=================================================
ynh_script_progression --message="Ensuring downward compatibility..." ynh_script_progression "Ensuring downward compatibility..."
# Remove the apt list entry for jenkins # Remove the apt list entry for jenkins
if [ -e "/etc/apt/sources.list.d/jenkins.list" ]; then 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 # Delete the APT key
apt-key del "$(apt-key list | grep -B1 "Kohsuke Kawaguchi" | grep pub | cut -d'/' -f2 | cut -d' ' -f1)" apt-key del "$(apt-key list | grep -B1 "Kohsuke Kawaguchi" | grep pub | cut -d'/' -f2 | cut -d' ' -f1)"
apt-get update apt-get update
fi fi
# Remove the log files # Remove the log files
ynh_secure_remove --file="/var/log/$app" ynh_safe_rm "/var/log/$app"
# No more needed since systemd # 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 # 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. # Download jenkins deb file and install it.
ynh_setup_source --dest_dir="$install_dir" ynh_setup_source --dest_dir="$install_dir"
ynh_setup_source --source_id="jenkins-plugin-manager" --dest_dir="$install_dir" ynh_setup_source --source_id="jenkins-plugin-manager" --dest_dir="$install_dir"
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 | 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 | chown -R "$app:$app" "$install_dir"
dpkg --install --force-confnew "$install_dir/jenkins.deb" dpkg --install --force-confnew "$install_dir/jenkins.deb"
#================================================= #=================================================
# SETUP APPLICATION # 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" \ ynh_replace --file="/lib/systemd/system/jenkins.service" \
--match_string="Environment=\"JENKINS_PORT=8080\"" \ --match="Environment=\"JENKINS_PORT=8080\"" \
--replace_string="Environment=\"JENKINS_PORT=$port\"\nEnvironment=\"JENKINS_PREFIX=$path\"" --replace="Environment=\"JENKINS_PORT=$port\"\nEnvironment=\"JENKINS_PREFIX=$path\""
systemctl daemon-reload --quiet 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 # UPGRADE PLUGINS
#================================================= #=================================================
ynh_script_progression --message="Upgrading plugins..." ynh_script_progression "Upgrading plugins..."
jenkins_plugin_manager=( 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 '^(.*?) ') mapfile -t UPDATE_LIST < <("${jenkins_plugin_manager[@]}" --list | grep -o '.*\..*' | grep -oP '^(.*?) ')
@ -76,21 +75,21 @@ done
#================================================= #=================================================
# REAPPLY SYSTEM CONFIGURATIONS # 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" yunohost service add "$app" --description="Jenkins Continuous Integration Server"
#================================================= #=================================================
# START SYSTEMD SERVICE # 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 # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Upgrade of $app completed" ynh_script_progression "Upgrade of $app completed"