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-03-19 10:02:46 +01:00

110 lines
4 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source ynh_send_readme_to_admin__2
source /usr/share/yunohost/helpers
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..."
ynh_systemd_action --service_name="$app" --action="stop" --line_match="Stopped" --log_path="systemd"
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..."
# If overwrite_nginx doesn't exist, create it
if [ -z "${overwrite_nginx:-}" ]; then
overwrite_nginx=1
ynh_app_setting_set --app="$app" --key="overwrite_nginx" --value="$overwrite_nginx"
fi
# 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" --line_match="Started" --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
# Overwrite the nginx configuration only if it's allowed
if [ "$overwrite_nginx" -eq 1 ]; then
ynh_add_nginx_config
fi
yunohost service add "$app" --description="Jenkins Continuous Integration Server"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
ynh_systemd_action --service_name="$app" --action="restart" --line_match="Started" --log_path="systemd"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed"