mirror of
https://github.com/YunoHost-Apps/gitlab-runner_ynh.git
synced 2024-09-03 19:15:58 +02:00
115 lines
3.9 KiB
Bash
Executable file
115 lines
3.9 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
|
source ../settings/scripts/_common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# MANAGE SCRIPT FAILURE
|
|
#=================================================
|
|
|
|
ynh_clean_setup () {
|
|
true
|
|
}
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
ynh_script_progression --message="Loading installation settings..."
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
config_path=$(ynh_app_setting_get --app=$app --key=config_path)
|
|
architecture=$(ynh_app_setting_get --app=$app --key=architecture)
|
|
gitlab_url=$(ynh_app_setting_get --app=$app --key=gitlab_url)
|
|
token=$(ynh_app_setting_get --app=$app --key=token)
|
|
executor=$(ynh_app_setting_get --app=$app --key=executor)
|
|
docker_image=$(ynh_app_setting_get --app=$app --key=docker_image)
|
|
|
|
#=================================================
|
|
# CHECK IF THE APP CAN BE RESTORED
|
|
#=================================================
|
|
ynh_script_progression --message="Validating restoration parameters..."
|
|
|
|
test ! -d $config_path \
|
|
|| ynh_die --message="There is already a directory: $config_path "
|
|
|
|
#=================================================
|
|
# STANDARD RESTORATION STEPS
|
|
#=================================================
|
|
# REINSTALL DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression --message="Reinstalling dependencies..."
|
|
|
|
# Define and install dependencies
|
|
ynh_install_extra_repo --repo="https://download.docker.com/linux/debian $(lsb_release -cs) stable" --key="https://download.docker.com/linux/debian/gpg" --name="${app}-docker"
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
ynh_script_progression --message="Reinstalling GitLab Runner..."
|
|
|
|
tempdir="$(mktemp -d)"
|
|
ynh_setup_source --dest_dir=$tempdir --source_id=$YNH_ARCH
|
|
dpkg -i $tempdir/gitlab-runner.deb
|
|
ynh_secure_remove --file="$tempdir"
|
|
|
|
#=================================================
|
|
# SPECIFIC SETUP
|
|
#=================================================
|
|
# SETUP GITLAB RUNNER
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring Gitlab Runner..."
|
|
|
|
# Can be registered several time, to do this give a list of gitlab_url, token and docker_image separated by a comma.
|
|
split_char=","
|
|
|
|
nb_to_register=$(echo "${gitlab_url}" | awk -F"${split_char}" '{print NF-1}')
|
|
|
|
for i in $(seq $nb_to_register)
|
|
do
|
|
url=$(echo $gitlab_url | cut -d$split_char -f$i)
|
|
tok=$(echo $token | cut -d$split_char -f$i)
|
|
docker_img=$(echo $docker_image | cut -d$split_char -f$i)
|
|
|
|
# Register the runner
|
|
ynh_exec_warn_less $app register \
|
|
--non-interactive \
|
|
--url "$url" \
|
|
--registration-token "$tok" \
|
|
--executor "$executor" \
|
|
--docker-image "$docker_img" \
|
|
--description "Yunohost runner" \
|
|
--tag-list "$executor,$YNH_ARCH" \
|
|
--run-untagged \
|
|
--locked="false"
|
|
done
|
|
|
|
#=================================================
|
|
# STORE THE CONFIG FILE CHECKSUM
|
|
#=================================================
|
|
|
|
# Calculate and store the config file checksum into the app settings
|
|
ynh_store_file_checksum "$config_path/config.toml"
|
|
|
|
#=================================================
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
#=================================================
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
|
|
|
yunohost service add $app
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Restoration completed for $app" --last
|