#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _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 #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= gitlab_url=$YNH_APP_ARG_GITLAB_URL token=$YNH_APP_ARG_TOKEN docker_image=$YNH_APP_ARG_DOCKER_IMAGE app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= ynh_script_progression --message="Validating installation parameters..." config_path=/etc/$app test ! -e "$config_path" || ynh_die "This path already contains a folder" # By default, the runner will use docker to run your builds. PR are welcomes to implement more executors executor="docker" # Adding a comma at the end if [ ${gitlab_url: -1} != "," ]; then gitlab_url=${gitlab_url}, fi # Adding a comma at the end if [ ${token: -1} != "," ]; then token=${token}, fi # Adding a comma at the end if [ ${docker_image: -1} != "," ]; then docker_image=${docker_image}, fi #================================================= # STORE SETTINGS FROM MANIFEST #================================================= ynh_script_progression --message="Storing installation settings..." ynh_app_setting_set --app=$app --key=gitlab_url --value=$gitlab_url ynh_app_setting_set --app=$app --key=token --value=$token ynh_app_setting_set --app=$app --key=executor --value=$executor ynh_app_setting_set --app=$app --key=docker_image --value=$docker_image ynh_app_setting_set --app=$app --key=config_path --value=$config_path #================================================= # STANDARD MODIFICATIONS #================================================= # INSTALL DEPENDENCIES #================================================= ynh_script_progression --message="Installing 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="Setting up source files..." 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" #================================================= # GENERIC FINALIZATION #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression --message="Integrating service in YunoHost..." yunohost service add $app #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Installation of $app completed" --last