2014-12-09 21:00:17 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
2017-03-19 22:50:12 +01:00
|
|
|
source _common.sh
|
2017-03-19 18:28:38 +01:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2021-06-25 02:17:47 +02:00
|
|
|
#=================================================
|
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2024-03-19 00:08:28 +01:00
|
|
|
ynh_script_progression --message="Stopping $app's systemd service..."
|
2021-06-25 02:17:47 +02:00
|
|
|
|
2024-03-19 00:08:28 +01:00
|
|
|
ynh_systemd_action --service_name="$app" --action="stop" --log_path="systemd"
|
2021-06-25 02:17:47 +02:00
|
|
|
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
2018-07-13 17:33:05 +02:00
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
2021-04-10 20:50:48 +02:00
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..."
|
2017-03-19 18:28:38 +01:00
|
|
|
|
2018-09-30 11:50:17 +02:00
|
|
|
# If overwrite_nginx doesn't exist, create it
|
2024-02-14 14:27:36 +01:00
|
|
|
if [ -z "${overwrite_nginx:-}" ]; then
|
|
|
|
overwrite_nginx=1
|
|
|
|
ynh_app_setting_set --app="$app" --key="overwrite_nginx" --value="$overwrite_nginx"
|
2018-09-30 11:50:17 +02:00
|
|
|
fi
|
|
|
|
|
2017-09-05 00:20:40 +02:00
|
|
|
# Remove the apt list entry for jenkins
|
2024-02-14 14:27:36 +01:00
|
|
|
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
|
2021-02-25 23:05:04 +01:00
|
|
|
fi
|
|
|
|
|
2022-05-22 14:58:59 +02:00
|
|
|
# Remove the log files
|
|
|
|
ynh_secure_remove --file="/var/log/$app"
|
|
|
|
|
|
|
|
# No more needed since systemd
|
|
|
|
ynh_delete_file_checksum --file="/etc/default/jenkins"
|
|
|
|
|
2017-06-13 19:11:22 +02:00
|
|
|
#=================================================
|
2021-02-25 23:05:04 +01:00
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
2017-06-13 19:11:22 +02:00
|
|
|
#=================================================
|
2024-02-14 14:27:36 +01:00
|
|
|
ynh_script_progression --message="Upgrading source files..."
|
2017-06-13 19:11:22 +02:00
|
|
|
|
2024-02-14 14:27:36 +01:00
|
|
|
# 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"
|
2018-07-13 17:33:05 +02:00
|
|
|
|
2024-02-14 14:27:36 +01:00
|
|
|
chmod -R o-rwx "$install_dir"
|
|
|
|
chown -R "$app:$app" "$install_dir"
|
2022-06-24 03:31:22 +02:00
|
|
|
|
2024-02-14 14:27:36 +01:00
|
|
|
dpkg --install --force-confnew "$install_dir/jenkins.deb"
|
2022-06-24 03:31:22 +02:00
|
|
|
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
2024-02-14 14:27:36 +01:00
|
|
|
# SETUP APPLICATION
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
2024-02-14 14:27:36 +01:00
|
|
|
ynh_script_progression --message="Setting up application..."
|
2014-12-09 21:00:17 +01:00
|
|
|
|
2024-02-14 14:27:36 +01:00
|
|
|
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
|
2019-05-28 00:28:01 +02:00
|
|
|
|
2024-03-19 00:08:28 +01:00
|
|
|
ynh_systemd_action --service_name="$app" --action="restart" --log_path="systemd"
|
2017-09-05 00:20:40 +02:00
|
|
|
|
2020-07-15 17:04:36 +02:00
|
|
|
#=================================================
|
|
|
|
# UPGRADE PLUGINS
|
|
|
|
#=================================================
|
2021-04-10 20:50:48 +02:00
|
|
|
ynh_script_progression --message="Upgrading plugins..."
|
2020-07-15 17:04:36 +02:00
|
|
|
|
2024-02-14 14:27:36 +01:00
|
|
|
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 '^(.*?) ')
|
2020-07-15 17:04:36 +02:00
|
|
|
|
2024-02-14 14:27:36 +01:00
|
|
|
for plugin in "${UPDATE_LIST[@]}"; do
|
|
|
|
"${jenkins_plugin_manager[@]}" --plugins "$plugin" || true
|
2020-07-21 10:42:14 +02:00
|
|
|
done
|
2020-07-15 18:51:16 +02:00
|
|
|
|
2020-12-03 18:46:01 +01:00
|
|
|
#=================================================
|
2024-02-14 14:27:36 +01:00
|
|
|
# REAPPLY SYSTEM CONFIGURATIONS
|
2020-12-03 18:46:01 +01:00
|
|
|
#=================================================
|
2024-02-14 14:27:36 +01:00
|
|
|
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
|
2020-12-03 18:46:01 +01:00
|
|
|
|
2024-02-14 14:27:36 +01:00
|
|
|
yunohost service add "$app" --description="Jenkins Continuous Integration Server"
|
2021-02-25 23:05:04 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2024-03-19 00:08:28 +01:00
|
|
|
ynh_script_progression --message="Starting $app's systemd service..."
|
2021-02-25 23:05:04 +01:00
|
|
|
|
2024-03-19 00:08:28 +01:00
|
|
|
ynh_systemd_action --service_name="$app" --action="restart" --log_path="systemd"
|
2019-01-21 13:08:17 +01:00
|
|
|
|
2019-01-30 15:56:18 +01:00
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2021-04-10 20:50:48 +02:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed"
|