1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/jenkins_ynh.git synced 2024-09-03 19:26:18 +02:00
jenkins_ynh/scripts/restore
2019-01-30 19:23:57 +01:00

160 lines
5.5 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
# Load common variables for all scripts.
source ../settings/scripts/_variables
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
# Clean installation remaining that are not handle by the remove script.
ynh_clean_check_starting
# Stop change_port()
ynh_exec_warn_less kill -s 15 $pid_change_port
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Load settings" --weight=2
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
final_path=$(ynh_app_setting_get $app final_path)
port=$(ynh_app_setting_get $app port)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_webpath_available $domain $path_url \
|| ynh_die "Path not available: ${domain}${path_url}"
test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path "
#=================================================
# ACTIVATE MAINTENANCE MODE
#=================================================
ynh_script_progression --message="Activate maintenance mode" --weight=2
ynh_maintenance_mode_ON
#=================================================
# STANDARD RESTORE STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
# Reload nginx
ynh_systemd_action --action=reload --service_name=nginx
#=================================================
# SPECIFIC RESTORE
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstall dependencies" --weight=20
ynh_install_app_dependencies $app_depencencies
#=================================================
# FIX THE PORT TO USE
#=================================================
ynh_script_progression --message="Fix the port to use"
change_port() {
# Wait for the creation of the jenkins service file
timeout=600
for j in `seq 1 $timeout`
do
# Wait for an update of plugin repositories
if test -e /etc/default/jenkins; then
break;
else
sleep 0.5
fi
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 &
pid_change_port=$!
#=================================================
# INSTALL JENKINS
#=================================================
ynh_script_progression --message="Install Jenkins" --weight=25
# Download jenkins deb file and install it.
ynh_download_file --dest_dir="../conf"
dpkg --install --force-confnew ../conf/jenkins.deb
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restore the app main directory" --weight=4
ynh_restore_file "$final_path"
#=================================================
# RESTORE THE JENKINS' BOOT CONFIG
#=================================================
ynh_secure_remove "/etc/default/jenkins"
ynh_restore_file /etc/default/$app
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
yunohost service add $app --log "/var/log/$app/$app.log"
#=================================================
# CHECK JENKINS STARTING
#=================================================
ynh_script_progression --message="Restart Jenkins" --weight=20
# 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"
#=================================================
# DEACTIVE MAINTENANCE MODE
#=================================================
ynh_script_progression --message="Deactive maintenance mode" --weight=8
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"
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__.
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
ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type="restore"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed" --last