2014-12-09 21:00:17 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC STARTING
|
|
|
|
#=================================================
|
|
|
|
# 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
|
2017-09-05 00:20:40 +02:00
|
|
|
# Load common variables for all scripts.
|
|
|
|
source _variables
|
2017-03-19 18:28:38 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2016-11-30 17:49:37 +01:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2016-11-30 17:55:46 +01:00
|
|
|
domain=$(ynh_app_setting_get $app domain)
|
2017-03-19 18:28:38 +01:00
|
|
|
path_url=$(ynh_app_setting_get $app path)
|
2016-11-30 17:55:46 +01:00
|
|
|
is_public=$(ynh_app_setting_get $app is_public)
|
|
|
|
port=$(ynh_app_setting_get $app port)
|
2018-09-30 11:50:17 +02:00
|
|
|
overwrite_nginx=$(ynh_app_setting_get $app overwrite_nginx)
|
2015-02-27 14:41:04 +01:00
|
|
|
|
2017-12-16 23:20:29 +01:00
|
|
|
#=================================================
|
|
|
|
# CHECK VERSION
|
|
|
|
#=================================================
|
|
|
|
|
2018-07-13 17:33:05 +02:00
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
2017-12-16 23:20:29 +01: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
|
|
|
#=================================================
|
|
|
|
|
2019-01-13 18:07:28 +01:00
|
|
|
# Fix is_public as a boolean
|
2017-03-19 18:28:38 +01:00
|
|
|
if [ "$is_public" = "Yes" ]; then
|
2019-01-13 18:07:28 +01:00
|
|
|
ynh_app_setting_set $app is_public 1
|
2017-03-19 18:28:38 +01:00
|
|
|
is_public=1
|
|
|
|
elif [ "$is_public" = "No" ]; then
|
|
|
|
ynh_app_setting_set $app is_public 0
|
|
|
|
is_public=0
|
|
|
|
fi
|
|
|
|
|
2018-09-30 11:50:17 +02:00
|
|
|
# If overwrite_nginx doesn't exist, create it
|
|
|
|
if [ -z "$overwrite_nginx" ]; then
|
|
|
|
overwrite_nginx=1
|
|
|
|
ynh_app_setting_set $app overwrite_nginx $overwrite_nginx
|
|
|
|
fi
|
|
|
|
|
2017-09-05 00:20:40 +02:00
|
|
|
# Remove the apt list entry for jenkins
|
|
|
|
if [ -e "/etc/apt/sources.list.d/jenkins.list" ]
|
|
|
|
then
|
|
|
|
ynh_secure_remove /etc/apt/sources.list.d/jenkins.list
|
2019-01-13 18:07:28 +01:00
|
|
|
# Get APT key id for jenkins
|
2017-09-05 00:20:40 +02:00
|
|
|
apt_key=$(apt-key list | grep -B1 "Kohsuke Kawaguchi" | grep pub | cut -d'/' -f2 | cut -d' ' -f1)
|
2019-01-13 18:07:28 +01:00
|
|
|
# Delete the APT key
|
|
|
|
apt-key del $apt_key
|
2017-09-05 00:20:40 +02:00
|
|
|
apt-get update
|
|
|
|
fi
|
|
|
|
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
|
|
|
|
2017-12-05 19:30:08 +01:00
|
|
|
# Backup the current version of the app
|
|
|
|
ynh_backup_before_upgrade
|
2017-03-19 18:28:38 +01:00
|
|
|
ynh_clean_setup () {
|
2017-12-16 23:20:29 +01:00
|
|
|
ynh_clean_check_starting
|
2017-12-05 19:30:08 +01:00
|
|
|
# restore it if the upgrade fails
|
|
|
|
ynh_restore_upgradebackup
|
2017-03-19 18:28:38 +01:00
|
|
|
}
|
2017-12-05 19:30:08 +01:00
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
2017-03-19 18:28:38 +01:00
|
|
|
|
2017-09-05 00:20:40 +02:00
|
|
|
#=================================================
|
2018-07-13 17:33:05 +02:00
|
|
|
# ACTIVATE MAINTENANCE MODE
|
2017-09-05 00:20:40 +02:00
|
|
|
#=================================================
|
|
|
|
|
2018-07-13 17:33:05 +02:00
|
|
|
ynh_maintenance_mode_ON
|
2017-09-05 00:20:40 +02:00
|
|
|
|
2017-06-13 19:11:22 +02:00
|
|
|
#=================================================
|
2018-07-13 17:33:05 +02:00
|
|
|
# UPGRADE JENKINS
|
2017-06-13 19:11:22 +02:00
|
|
|
#=================================================
|
|
|
|
|
2018-07-13 17:33:05 +02:00
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
|
|
then
|
2019-01-13 18:07:28 +01:00
|
|
|
# Download jenkins deb file and install it.
|
2019-01-13 17:49:15 +01:00
|
|
|
ynh_download_file --dest_dir="../conf"
|
2019-01-21 13:08:17 +01:00
|
|
|
dpkg --install --force-confnew ../conf/jenkins.deb
|
2018-07-13 17:33:05 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# FIX JENKINS SETUP
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
if [ "$path_url" != "/" ];
|
2019-01-13 18:07:28 +01:00
|
|
|
then
|
|
|
|
# Add the path, in case of sub-path installation, into jenkins' boot options
|
2018-07-13 17:33:05 +02:00
|
|
|
if ! grep --quiet "prefix=$path_url" /etc/default/jenkins
|
|
|
|
then
|
|
|
|
sed -i "$ s@--httpPort=\$HTTP_PORT@& --prefix=$path_url@g" /etc/default/jenkins
|
|
|
|
fi
|
2017-06-13 19:11:22 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-01-13 17:49:15 +01:00
|
|
|
#=================================================
|
|
|
|
# UPGRADE DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_install_app_dependencies $app_depencencies
|
|
|
|
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2014-12-09 21:00:17 +01:00
|
|
|
|
2018-09-30 11:50:17 +02:00
|
|
|
# Overwrite the nginx configuration only if it's allowed
|
|
|
|
if [ $overwrite_nginx -eq 1 ]
|
|
|
|
then
|
|
|
|
ynh_add_nginx_config
|
|
|
|
fi
|
2017-09-05 00:20:40 +02:00
|
|
|
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
if [ $is_public -eq 1 ]
|
2014-12-16 00:14:01 +01:00
|
|
|
then
|
2017-03-19 18:28:38 +01:00
|
|
|
ynh_app_setting_set $app unprotected_uris "/"
|
2014-12-16 00:14:01 +01:00
|
|
|
else
|
2017-03-19 18:28:38 +01:00
|
|
|
ynh_app_setting_delete $app unprotected_uris
|
2014-12-16 00:14:01 +01:00
|
|
|
fi
|
|
|
|
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
|
|
|
|
2019-01-21 13:08:17 +01:00
|
|
|
ynh_systemd_action --action=reload --service_name=nginx
|
2017-09-05 00:20:40 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK JENKINS STARTING
|
|
|
|
#=================================================
|
|
|
|
|
2019-01-13 18:07:28 +01:00
|
|
|
# Wait for Jenkins to be fully started
|
2019-01-21 13:08:17 +01:00
|
|
|
ynh_systemd_action --action=restart --line_match="Jenkins is fully up and running" --log_path="/var/log/$app/$app.log" --timeout="3600"
|
2018-06-29 23:41:02 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# UPGRADE JENKINS-CLI.PHAR
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
wget -nv --no-check-certificate https://$domain$path_url/jnlpJars/jenkins-cli.jar -O /var/lib/jenkins/jenkins-cli.jar
|
2018-07-13 17:33:05 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DEACTIVE MAINTENANCE MODE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_maintenance_mode_OFF
|
2019-01-21 13:08:17 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SEND A README FOR THE ADMIN
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Get main domain and buid the url of the admin panel of the app.
|
|
|
|
admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app"
|
|
|
|
|
|
|
|
message="You can configure this app easily by using the experimental config-panel feature: $admin_panel/config-panel.
|
|
|
|
You can also find some specific actions for this app by using the experimental action feature: $admin_panel/actions.
|
|
|
|
|
|
|
|
If you're facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/jenkins_ynh"
|
|
|
|
|
|
|
|
ynh_send_readme_to_admin --app_message="$message" --recipients="root" --type="upgrade"
|