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
#=================================================
2021-02-25 23:05:04 +01:00
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
2018-07-13 17:33:05 +02:00
source ../settings/scripts/_common.sh
2021-02-25 23:05:04 +01:00
source ../settings/scripts/ynh_send_readme_to_admin__2
2016-11-30 17:49:37 +01:00
source /usr/share/yunohost/helpers
2019-05-28 00:28:01 +02:00
2017-09-05 00:20:40 +02:00
#=================================================
# 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
2019-01-21 13:08:17 +01:00
# Stop change_port()
ynh_exec_warn_less kill -s 15 $pid_change_port
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
#=================================================
2021-04-10 20:50:48 +02:00
ynh_script_progression --message="Loading installation settings..."
2017-03-19 18:28:38 +01:00
app=$YNH_APP_INSTANCE_NAME
2019-05-28 00:28:01 +02:00
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
port=$(ynh_app_setting_get --app=$app --key=port)
2016-11-30 17:49:37 +01:00
2017-03-19 18:28:38 +01:00
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
2019-05-28 00:28:01 +02:00
ynh_script_progression --message="Validating restoration parameters..."
2016-11-30 17:49:37 +01:00
2022-01-07 01:02:47 +01:00
test ! -d $final_path \
|| ynh_die --message="There is already a directory: $final_path "
2017-03-19 18:28:38 +01:00
#=================================================
2021-02-25 23:05:04 +01:00
# STANDARD RESTORATION STEPS
2022-05-24 01:06:35 +02:00
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
ynh_script_progression --message="Recreating the dedicated system user..."
# Create the dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
2017-03-19 18:28:38 +01:00
#=================================================
2021-02-25 23:05:04 +01:00
# SPECIFIC RESTORATION
2017-03-19 18:28:38 +01:00
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
2021-04-10 20:50:48 +02:00
ynh_script_progression --message="Reinstalling dependencies..."
2016-11-30 17:49:37 +01:00
2021-02-25 23:05:04 +01:00
# Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies
2017-05-15 14:34:58 +02:00
2022-06-24 03:31:22 +02:00
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the NGINX web server configuration..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
2017-05-15 14:34:58 +02:00
#=================================================
# INSTALL JENKINS
#=================================================
2021-04-10 20:50:48 +02:00
ynh_script_progression --message="Installing Jenkins..."
2017-05-15 14:34:58 +02:00
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"
2019-01-21 13:08:17 +01:00
dpkg --install --force-confnew ../conf/jenkins.deb
2017-03-19 18:28:38 +01:00
#=================================================
2022-05-22 14:58:59 +02:00
# SETUP APPLICATION
2017-03-19 18:28:38 +01:00
#=================================================
2022-05-22 14:58:59 +02:00
ynh_script_progression --message="Setuping application..."
2016-11-30 17:49:37 +01:00
2022-05-22 14:58:59 +02:00
ynh_replace_string --match_string="Environment=\"JENKINS_PORT=8080\"" --replace_string="Environment=\"JENKINS_PORT=$port\"\nEnvironment=\"JENKINS_PREFIX=$path_url\"" --target_file="/lib/systemd/system/jenkins.service"
systemctl daemon-reload --quiet
ynh_systemd_action --service_name=$app --action="restart" --line_match="Started Jenkins Continuous Integration Server" --log_path="systemd"
2016-11-30 17:49:37 +01:00
2017-03-19 18:28:38 +01:00
#=================================================
2022-05-22 14:58:59 +02:00
# RESTORE THE APP MAIN DIR
2017-03-19 18:28:38 +01:00
#=================================================
2022-05-22 14:58:59 +02:00
ynh_script_progression --message="Restoring the app main directory..."
2016-11-30 17:49:37 +01:00
2022-05-22 14:58:59 +02:00
ynh_restore_file --origin_path="$final_path" --not_mandatory
2017-03-19 18:28:38 +01:00
#=================================================
2021-02-25 23:05:04 +01:00
# INTEGRATE SERVICE IN YUNOHOST
2017-03-19 18:28:38 +01:00
#=================================================
2021-02-25 23:05:04 +01:00
ynh_script_progression --message="Integrating service in YunoHost..."
2017-03-19 18:28:38 +01:00
2022-05-22 14:58:59 +02:00
yunohost service add $app --description="Jenkins Continuous Integration Server"
2016-11-30 17:49:37 +01:00
2017-03-19 18:28:38 +01:00
#=================================================
2021-02-25 23:05:04 +01:00
# START SYSTEMD SERVICE
2017-03-19 18:28:38 +01:00
#=================================================
2021-04-10 20:50:48 +02:00
ynh_script_progression --message="Starting a systemd service..."
2017-03-19 18:28:38 +01:00
2022-05-22 14:58:59 +02:00
ynh_systemd_action --service_name=$app --action="restart" --line_match="Started Jenkins Continuous Integration Server" --log_path="systemd"
2018-07-13 17:33:05 +02: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-21 13:08:17 +01:00
# 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"
2017-12-16 23:20:29 +01:00
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__.
2019-01-21 13:08:17 +01:00
2019-01-30 19:23:57 +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-21 13:08:17 +01:00
2019-05-28 00:28:01 +02:00
ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type=restore
2019-01-30 15:56:18 +01:00
2021-02-25 23:05:04 +01:00
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload
2019-01-30 15:56:18 +01:00
#=================================================
# END OF SCRIPT
#=================================================
2021-04-10 20:50:48 +02:00
ynh_script_progression --message="Restoration completed for $app"