2014-12-09 21:00:17 +01:00
#!/bin/bash
2017-03-19 18:28:38 +01:00
#=================================================
2021-02-25 23:05:04 +01:00
# GENERIC START
2017-03-19 18:28:38 +01:00
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2017-03-19 22:50:12 +01:00
source _common.sh
2021-02-25 23:05:04 +01:00
source ynh_send_readme_to_admin__2
2017-03-19 18:28:38 +01:00
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
2024-02-14 13:31:37 +01:00
#REMOVEME? ynh_script_progression --message="Loading installation settings..."
2016-11-30 17:49:37 +01:00
2024-02-14 13:31:37 +01:00
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
2016-11-30 17:49:37 +01:00
2024-02-14 13:31:37 +01:00
#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain)
#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path)
#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
#REMOVEME? port=$(ynh_app_setting_get --app=$app --key=port)
#REMOVEME? overwrite_nginx=$(ynh_app_setting_get --app=$app --key=overwrite_nginx)
2015-02-27 14:41:04 +01:00
2017-12-16 23:20:29 +01:00
#=================================================
# CHECK VERSION
#=================================================
2021-02-25 23:05:04 +01:00
ynh_script_progression --message="Checking version..."
2017-12-16 23:20:29 +01:00
2018-07-13 17:33:05 +02:00
upgrade_type=$(ynh_check_app_version_changed)
2017-12-16 23:20:29 +01:00
2021-06-25 02:17:47 +02:00
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
2024-02-14 13:31:37 +01:00
#REMOVEME? ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
2021-06-25 02:17:47 +02:00
# Backup the current version of the app
2024-02-14 13:31:37 +01:00
#REMOVEME? ynh_backup_before_upgrade
#REMOVEME? ynh_clean_setup () {
2021-06-25 02:17:47 +02:00
ynh_clean_check_starting
# Restore it if the upgrade fails
2024-02-14 13:31:37 +01:00
#REMOVEME? ynh_restore_upgradebackup
2021-06-25 02:17:47 +02:00
}
# Exit if an error occurs during the execution of the script
2024-02-14 13:31:37 +01:00
#REMOVEME? ynh_abort_if_errors
2021-06-25 02:17:47 +02:00
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..."
2023-08-03 02:55:11 +02:00
ynh_systemd_action --service_name=$app --action="stop" --line_match="Stopped" --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
if [ -z "$overwrite_nginx" ]; then
overwrite_nginx=1
2019-05-28 00:28:01 +02:00
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
if [ -e "/etc/apt/sources.list.d/jenkins.list" ]
then
2019-05-28 00:28:01 +02:00
ynh_secure_remove --file=/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
2021-02-25 23:05:04 +01:00
# Cleaning legacy permissions
2024-02-14 13:31:37 +01:00
#REMOVEME? if ynh_legacy_permissions_exists; then
#REMOVEME? ynh_legacy_permissions_delete_all
2021-02-25 23:05:04 +01:00
ynh_app_setting_delete --app=$app --key=is_public
fi
# Create a permission if needed
2024-02-14 13:31:37 +01:00
#REMOVEME? if ! ynh_permission_exists --permission="github-webhook"; then
#REMOVEME? ynh_permission_create --permission="github-webhook" --url="/github-webhook" --allowed="visitors" --show_tile="false" --protected="true"
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"
2022-05-24 01:06:35 +02:00
#=================================================
# CREATE DEDICATED USER
#=================================================
2024-02-14 13:31:37 +01:00
#REMOVEME? ynh_script_progression --message="Making sure dedicated system user exists..."
2022-05-24 01:06:35 +02:00
# Create a dedicated user (if not existing)
2024-02-14 13:31:37 +01:00
#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir"
2022-05-24 01:06:35 +02:00
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
#=================================================
2018-07-13 17:33:05 +02:00
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
2021-04-10 20:50:48 +02:00
ynh_script_progression --message="Upgrading source files..."
2019-01-13 18:07:28 +01:00
# Download jenkins deb file and install it.
2019-05-28 00:28:01 +02:00
ynh_setup_source --dest_dir="../conf"
2024-02-14 13:31:37 +01:00
ynh_setup_source --source_id="jenkins-plugin-manager" --dest_dir="$install_dir"
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:$app "$install_dir"
2022-05-23 23:23:48 +02:00
2019-01-21 13:08:17 +01:00
dpkg --install --force-confnew ../conf/jenkins.deb
2018-07-13 17:33:05 +02:00
#=================================================
2022-05-22 14:58:59 +02:00
# SETUP APPLICATION
2018-07-13 17:33:05 +02:00
#=================================================
2022-05-22 14:58:59 +02:00
ynh_script_progression --message="Setuping application..."
2024-02-14 13:31:37 +01:00
ynh_replace_string --match_string="Environment=\"JENKINS_PORT=8080\"" --replace_string="Environment=\"JENKINS_PORT=$port\"\nEnvironment=\"JENKINS_PREFIX=$path\"" --target_file="/lib/systemd/system/jenkins.service"
2022-05-22 14:58:59 +02:00
systemctl daemon-reload --quiet
2018-07-13 17:33:05 +02:00
2023-08-03 02:55:11 +02:00
ynh_systemd_action --service_name=$app --action="restart" --line_match="Started" --log_path="systemd"
2017-06-13 19:11:22 +02:00
fi
2022-06-24 03:31:22 +02:00
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
2024-02-14 13:31:37 +01:00
#REMOVEME? ynh_script_progression --message="Upgrading dependencies..."
2022-06-24 03:31:22 +02:00
2024-02-14 13:31:37 +01:00
#REMOVEME? ynh_install_app_dependencies $pkg_dependencies
2022-06-24 03:31:22 +02:00
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
2021-04-10 20:50:48 +02:00
ynh_script_progression --message="Upgrading NGINX web server configuration..."
2019-05-28 00:28:01 +02:00
2020-12-03 18:24:29 +01:00
# Create a dedicated NGINX config
2018-09-30 11:50:17 +02:00
ynh_add_nginx_config
fi
2017-09-05 00:20:40 +02:00
2021-02-25 23:05:04 +01:00
#=================================================
# SPECIFIC UPGRADE
2017-03-19 18:28:38 +01:00
#=================================================
# RELOAD NGINX
#=================================================
2024-02-14 13:31:37 +01:00
#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..."
2017-03-19 18:28:38 +01:00
2024-02-14 13:31:37 +01:00
#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload
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 13:31:37 +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"
2022-05-22 14:58:59 +02:00
UPDATE_LIST=$($jenkins_plugin_manager --list | grep -o '.*\..*' | grep -oP '^(.*?) ')
2020-07-15 17:04:36 +02:00
2020-07-21 10:42:14 +02:00
for plugin in ${UPDATE_LIST}
do
2022-05-22 14:58:59 +02:00
$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
#=================================================
2021-02-25 23:05:04 +01:00
# GENERIC FINALIZATION
2020-12-03 18:46:01 +01:00
#=================================================
2021-02-25 23:05:04 +01:00
# INTEGRATE SERVICE IN YUNOHOST
2020-12-03 18:46:01 +01:00
#=================================================
2021-02-25 23:05:04 +01:00
ynh_script_progression --message="Integrating service in YunoHost..."
2020-12-03 18:46:01 +01:00
2022-05-22 14:58:59 +02:00
yunohost service add $app --description="Jenkins Continuous Integration Server"
2021-02-25 23:05:04 +01:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
2023-08-03 02:55:11 +02:00
ynh_systemd_action --service_name=$app --action="restart" --line_match="Started" --log_path="systemd"
2020-12-03 18:46:01 +01:00
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"
2019-01-30 19:23:57 +01:00
echo "You can configure this app easily by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__.
You can also find some specific actions for this app by using the experimental __URL_TAG1__action feature__URL_TAG2__$admin_panel/actions__URL_TAG3__.
2021-03-04 00:33:28 +01:00
If you're facing an issue or want to improve this app, please open a new issue in this __URL_TAG1__project__URL_TAG2__https://github.com/YunoHost-Apps/jenkins_ynh__URL_TAG3__." > mail_to_send
2019-01-30 19:23:57 +01:00
2019-05-28 00:28:01 +02:00
ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type=upgrade
2019-01-30 19:23:57 +01:00
2021-02-25 23:05:04 +01:00
#=================================================
# RELOAD NGINX
#=================================================
2024-02-14 13:31:37 +01:00
#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..."
2019-01-30 19:23:57 +01:00
2024-02-14 13:31:37 +01:00
#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload
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"