#!/bin/bash if (( $# < 1 )) then cat << EOF Usage: ./finish_install.sh [auto|manual] [cluster] 1st argument is the CI type (scheduling strategy): - auto means job will automatically be scheduled by yunorunner from apps.json etc. - manual means job will be scheduled manually (e.g. via webhooks or yunorunner ciclic) 2nd argument is to build the first node of an lxc cluster - lxd cluster will be created with the current server - some.domain.tld will be the cluster hostname and SecretAdminPasswurzd! the trust password to join the cluster EOF exit 1 fi YUNORUNNER_HOME="/var/www/yunorunner" if [ $(pwd) != "$YUNORUNNER_HOME" ] then echo "This script should be ran from $YUNORUNNER_HOME" exit 1 fi ci_type=$1 lxd_cluster=$2 # User which execute the CI software. ci_user=yunorunner echo_bold () { echo -e "\e[1m$1\e[0m" } # ----------------------------------------------------------------- function tweak_yunohost() { #echo_bold "> Setting up Yunohost..." #local DIST="bullseye" #local INSTALL_SCRIPT="https://install.yunohost.org/$DIST" #curl $INSTALL_SCRIPT | bash -s -- -a #echo_bold "> Running yunohost postinstall" #yunohost tools postinstall --domain $domain --password $yuno_pwd # What is it used for :| ... #echo_bold "> Create Yunohost CI user" #local ynh_ci_user=ynhci #yunohost user create --firstname "$ynh_ci_user" --domain "$domain" --lastname "$ynh_ci_user" "$ynh_ci_user" --password $yuno_pwd # Idk why this is needed but wokay I guess >_> echo -e "\n127.0.0.1 $domain #CI_APP" >> /etc/hosts echo_bold "> Disabling unecessary services to save up RAM" for SERVICE in mysql php7.4-fpm metronome rspamd dovecot postfix redis-server postsrsd yunohost-api avahi-daemon do systemctl stop $SERVICE systemctl disable $SERVICE --quiet done } function tweak_yunorunner() { echo_bold "> Tweaking YunoRunner..." #if ! yunohost app list --output-as json --quiet | jq -e '.apps[] | select(.id == "yunorunner")' >/dev/null #then # yunohost app install --force https://github.com/YunoHost-Apps/yunorunner_ynh -a "domain=$domain&path=/$ci_path" #fi domain=$(yunohost app setting yunorunner domain) ci_path=$(yunohost app setting yunorunner path) port=$(yunohost app setting yunorunner port) # Stop YunoRunner # to be started manually by the admin after the CI_package_check install # finishes systemctl stop $ci_user # Remove the original database, in order to rebuilt it with the new config. rm -f $YUNORUNNER_HOME/db.sqlite cat >$YUNORUNNER_HOME/config.py <>$YUNORUNNER_HOME/config.py <>$YUNORUNNER_HOME/config.py </dev/null then yunohost app install --force https://github.com/YunoHost-Apps/lxd_ynh fi mkdir .lxd pushd .lxd echo_bold "> Configuring lxd..." if [ "$lxd_cluster" == "cluster" ] then local free_space=$(df --output=avail / | sed 1d) local btrfs_size=$(( $free_space * 90 / 100 / 1024 / 1024 )) local lxc_network=$((1 + $RANDOM % 254)) yunohost firewall allow TCP 8443 cat >./preseed.conf < Configuring the CI..." # Cron tasks cat >> "/etc/cron.d/yunorunner" << EOF # self-upgrade every night 0 3 * * * root "$YUNORUNNER_HOME/maintenance/self_upgrade.sh" >> "$YUNORUNNER_HOME/maintenance/self_upgrade.log" 2>&1 EOF } # ========================= # Main stuff # ========================= #install_dependencies [ -e /usr/bin/yunohost ] || { echo "YunoHost is not installed"; exit; } [ -e /etc/yunohost/apps/yunorunner ] || { echo "Yunorunner is not installed on YunoHost"; exit; } tweak_yunohost tweak_yunorunner git clone https://github.com/YunoHost/package_check "./package_check" setup_lxd add_cron_jobs # Add permission to the user for the entire yunorunner home because it'll be the one running the tests (as a non-root user) chown -R $ci_user $YUNORUNNER_HOME echo "Done!" echo " " echo "N.B. : If you want to enable Matrix notification, you should look at " echo "the instructions inside lib/chat_notify.sh to deploy matrix-commander" echo "" echo "You may also want to tweak the 'config' file to run test with a different branch / arch" echo "" echo "When you're ready to start the CI, run: systemctl restart $ci_user"