mirror of
https://github.com/YunoHost-Apps/jenkins_ynh.git
synced 2024-09-03 19:26:18 +02:00
170 lines
5.2 KiB
Bash
170 lines
5.2 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC STARTING
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
# Load common variables for all scripts.
|
|
source _variables
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
domain=$(ynh_app_setting_get $app domain)
|
|
path_url=$(ynh_app_setting_get $app path)
|
|
is_public=$(ynh_app_setting_get $app is_public)
|
|
port=$(ynh_app_setting_get $app port)
|
|
overwrite_nginx=$(ynh_app_setting_get $app overwrite_nginx)
|
|
|
|
#=================================================
|
|
# CHECK VERSION
|
|
#=================================================
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
#=================================================
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
#=================================================
|
|
|
|
# Fix is_public as a boolean
|
|
if [ "$is_public" = "Yes" ]; then
|
|
ynh_app_setting_set $app is_public 1
|
|
is_public=1
|
|
elif [ "$is_public" = "No" ]; then
|
|
ynh_app_setting_set $app is_public 0
|
|
is_public=0
|
|
fi
|
|
|
|
# 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
|
|
|
|
# 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
|
|
# Get APT key id for jenkins
|
|
apt_key=$(apt-key list | grep -B1 "Kohsuke Kawaguchi" | grep pub | cut -d'/' -f2 | cut -d' ' -f1)
|
|
# Delete the APT key
|
|
apt-key del $apt_key
|
|
apt-get update
|
|
fi
|
|
|
|
#=================================================
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
#=================================================
|
|
|
|
# Backup the current version of the app
|
|
ynh_backup_before_upgrade
|
|
ynh_clean_setup () {
|
|
ynh_clean_check_starting
|
|
# restore it if the upgrade fails
|
|
ynh_restore_upgradebackup
|
|
}
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# ACTIVATE MAINTENANCE MODE
|
|
#=================================================
|
|
|
|
ynh_maintenance_mode_ON
|
|
|
|
#=================================================
|
|
# UPGRADE JENKINS
|
|
#=================================================
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
then
|
|
# Download jenkins deb file and install it.
|
|
ynh_download_file --dest_dir="../conf"
|
|
dpkg --install --force-confnew ../conf/jenkins.deb
|
|
|
|
#=================================================
|
|
# FIX JENKINS SETUP
|
|
#=================================================
|
|
|
|
if [ "$path_url" != "/" ];
|
|
then
|
|
# Add the path, in case of sub-path installation, into jenkins' boot options
|
|
if ! grep --quiet "prefix=$path_url" /etc/default/jenkins
|
|
then
|
|
sed -i "$ s@--httpPort=\$HTTP_PORT@& --prefix=$path_url@g" /etc/default/jenkins
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
#=================================================
|
|
# UPGRADE DEPENDENCIES
|
|
#=================================================
|
|
|
|
ynh_install_app_dependencies $app_depencencies
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
|
|
# Overwrite the nginx configuration only if it's allowed
|
|
if [ $overwrite_nginx -eq 1 ]
|
|
then
|
|
ynh_add_nginx_config
|
|
fi
|
|
|
|
#=================================================
|
|
# SETUP SSOWAT
|
|
#=================================================
|
|
|
|
if [ $is_public -eq 1 ]
|
|
then
|
|
ynh_app_setting_set $app unprotected_uris "/"
|
|
else
|
|
ynh_app_setting_delete $app unprotected_uris
|
|
fi
|
|
|
|
#=================================================
|
|
# RELOAD NGINX
|
|
#=================================================
|
|
|
|
ynh_systemd_action --action=reload --service_name=nginx
|
|
|
|
#=================================================
|
|
# CHECK JENKINS STARTING
|
|
#=================================================
|
|
|
|
# Wait for Jenkins to be fully started
|
|
ynh_systemd_action --action=restart --line_match="Jenkins is fully up and running" --log_path="/var/log/$app/$app.log" --timeout="3600"
|
|
|
|
#=================================================
|
|
# UPGRADE JENKINS-CLI.PHAR
|
|
#=================================================
|
|
|
|
wget -nv --no-check-certificate https://$domain$path_url/jnlpJars/jenkins-cli.jar -O /var/lib/jenkins/jenkins-cli.jar
|
|
|
|
#=================================================
|
|
# DEACTIVE MAINTENANCE MODE
|
|
#=================================================
|
|
|
|
ynh_maintenance_mode_OFF
|
|
|
|
#=================================================
|
|
# 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"
|