2016-11-30 17:49:37 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
2017-09-05 00:20:40 +02:00
|
|
|
# GENERIC START
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
2018-07-13 17:33:05 +02:00
|
|
|
source ../settings/scripts/_common.sh
|
2016-11-30 17:49:37 +01:00
|
|
|
source /usr/share/yunohost/helpers
|
2017-09-05 00:20:40 +02:00
|
|
|
# Load common variables for all scripts.
|
|
|
|
source ../settings/scripts/_variables
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_clean_setup () {
|
2019-01-13 18:07:28 +01:00
|
|
|
# Clean installation remaining that are not handle by the remove script.
|
2017-12-16 23:20:29 +01:00
|
|
|
ynh_clean_check_starting
|
2017-09-05 00:20:40 +02:00
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
2016-11-30 17:49:37 +01:00
|
|
|
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
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
|
|
|
final_path=$(ynh_app_setting_get $app final_path)
|
2017-05-15 18:29:07 +02:00
|
|
|
port=$(ynh_app_setting_get $app port)
|
2016-11-30 17:49:37 +01:00
|
|
|
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE RESTORED
|
|
|
|
#=================================================
|
2016-11-30 17:49:37 +01:00
|
|
|
|
2017-12-16 23:20:29 +01:00
|
|
|
ynh_webpath_available $domain $path_url \
|
2017-03-19 18:28:38 +01:00
|
|
|
|| ynh_die "Path not available: ${domain}${path_url}"
|
|
|
|
test ! -d $final_path \
|
|
|
|
|| ynh_die "There is already a directory: $final_path "
|
|
|
|
|
2018-07-13 17:33:05 +02:00
|
|
|
#=================================================
|
|
|
|
# ACTIVATE MAINTENANCE MODE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_maintenance_mode_ON
|
|
|
|
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
|
|
|
# STANDARD RESTORE STEPS
|
|
|
|
#=================================================
|
2019-01-13 18:07:28 +01:00
|
|
|
# RESTORE THE NGINX CONFIGURATION
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
2016-11-30 17:49:37 +01:00
|
|
|
|
2017-06-13 19:11:22 +02:00
|
|
|
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
|
2017-03-19 18:28:38 +01:00
|
|
|
|
2019-01-13 18:07:28 +01:00
|
|
|
# Reload nginx
|
2019-01-13 17:49:15 +01:00
|
|
|
ynh_systemd_action --action=reload --service_name=nginx
|
2016-11-30 17:49:37 +01:00
|
|
|
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC RESTORE
|
|
|
|
#=================================================
|
|
|
|
# REINSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
2016-11-30 17:49:37 +01:00
|
|
|
|
2017-09-05 00:20:40 +02:00
|
|
|
ynh_install_app_dependencies $app_depencencies
|
2017-05-15 14:34:58 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# FIX THE PORT TO USE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
change_port() {
|
|
|
|
# Wait for the creation of the jenkins service file
|
|
|
|
while [ ! -e /etc/default/jenkins ]
|
|
|
|
do
|
|
|
|
sleep 0.5
|
|
|
|
done
|
|
|
|
# And modify the port as soon as possible, to prevent a crach of jenkins if the default port is already used.
|
|
|
|
ynh_replace_string "^HTTP_PORT=.*" "HTTP_PORT=$port" /etc/default/jenkins
|
|
|
|
}
|
|
|
|
change_port &
|
2017-09-05 00:20:40 +02:00
|
|
|
pid_change_port=$!
|
2017-05-15 14:34:58 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INSTALL JENKINS
|
|
|
|
#=================================================
|
|
|
|
|
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"
|
|
|
|
dpkg --install ../conf/jenkins.deb
|
2017-03-19 18:28:38 +01:00
|
|
|
|
|
|
|
#=================================================
|
2019-01-13 18:07:28 +01:00
|
|
|
# RESTORE THE APP MAIN DIR
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
2016-11-30 17:49:37 +01:00
|
|
|
|
2017-06-13 19:11:22 +02:00
|
|
|
ynh_restore_file "$final_path"
|
2016-11-30 17:49:37 +01:00
|
|
|
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
2019-01-13 18:07:28 +01:00
|
|
|
# RESTORE THE JENKINS' BOOT CONFIG
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
2016-11-30 17:49:37 +01:00
|
|
|
|
2017-05-15 14:34:58 +02:00
|
|
|
ynh_secure_remove "/etc/default/jenkins"
|
2017-06-13 19:11:22 +02:00
|
|
|
ynh_restore_file /etc/default/$app
|
2017-03-19 18:28:38 +01:00
|
|
|
|
|
|
|
#=================================================
|
2019-01-13 18:07:28 +01:00
|
|
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
|
|
|
|
2017-12-16 23:20:29 +01:00
|
|
|
yunohost service add $app --log "/var/log/$app/$app.log"
|
2016-11-30 17:49:37 +01:00
|
|
|
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
2017-12-16 23:20:29 +01:00
|
|
|
# CHECK JENKINS STARTING
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
|
|
|
|
2019-01-13 18:07:28 +01:00
|
|
|
# Wait for Jenkins to be fully started
|
2019-01-13 17:49:15 +01:00
|
|
|
ynh_systemd_action --action=restart --line_match="Jenkins is fully up and running" --log_path="/var/log/$app/$app.log" --timeout="$timeout"
|
2018-07-13 17:33:05 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DEACTIVE MAINTENANCE MODE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_maintenance_mode_OFF
|
2016-11-30 17:49:37 +01:00
|
|
|
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
2017-12-16 23:20:29 +01:00
|
|
|
# SEND A README FOR THE ADMIN
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
2016-11-30 17:55:46 +01:00
|
|
|
|
2019-01-13 18:07:28 +01:00
|
|
|
message="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"
|
2017-12-16 23:20:29 +01:00
|
|
|
|
2018-07-13 17:33:05 +02:00
|
|
|
ynh_send_readme_to_admin --app_message="$message" --recipients="root"
|