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

96 lines
3.5 KiB
Bash

#!/bin/bash
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping $app's systemd service..."
ynh_systemd_action --service_name="$app" --action="stop" --log_path="systemd"
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="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
# 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"
# No more needed since systemd
ynh_delete_file_checksum --file="/etc/default/jenkins"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="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"
dpkg --install --force-confnew "$install_dir/jenkins.deb"
#=================================================
# SETUP APPLICATION
#=================================================
ynh_script_progression --message="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\""
systemctl daemon-reload --quiet
ynh_systemd_action --service_name="$app" --action="restart" --log_path="systemd"
#=================================================
# UPGRADE PLUGINS
#=================================================
ynh_script_progression --message="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"
)
mapfile -t UPDATE_LIST < <("${jenkins_plugin_manager[@]}" --list | grep -o '.*\..*' | grep -oP '^(.*?) ')
for plugin in "${UPDATE_LIST[@]}"; do
"${jenkins_plugin_manager[@]}" --plugins "$plugin" || true
done
#=================================================
# REAPPLY SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
ynh_add_nginx_config
yunohost service add "$app" --description="Jenkins Continuous Integration Server"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting $app's systemd service..."
ynh_systemd_action --service_name="$app" --action="restart" --log_path="systemd"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed"