mirror of
https://github.com/YunoHost-Apps/jenkins_ynh.git
synced 2024-09-03 19:26:18 +02:00
95 lines
3.1 KiB
Bash
95 lines
3.1 KiB
Bash
#!/bin/bash
|
|
|
|
# Retrieve arguments
|
|
domain=$1
|
|
path=$2
|
|
is_public=$3
|
|
port=$4
|
|
app=jenkins
|
|
|
|
sudo yunohost app checkport $port
|
|
if [[ ! $? -eq 0 ]]; then
|
|
echo "Port $port is not available. Aborting..."
|
|
exit 1
|
|
fi
|
|
|
|
# Check domain/path availability
|
|
sudo yunohost app checkurl $domain$path -a jenkins
|
|
if [[ ! $? -eq 0 ]]; then
|
|
exit 1
|
|
fi
|
|
|
|
echo "Install dependencies..."
|
|
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
|
|
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
|
|
|
|
sudo apt-get update
|
|
sudo apt-get install jenkins -y
|
|
|
|
if [[ "$path" != "/" ]];
|
|
then
|
|
# $ means 'process only the last line'
|
|
sudo sed -i '$ s@--httpPort=$HTTP_PORT"@--httpPort=$HTTP_PORT" --prefix=$PREFIX@g' /etc/default/jenkins
|
|
fi
|
|
sudo sed -i "s/HTTP_PORT=.*/HTTP_PORT=$port/g" /etc/default/jenkins
|
|
|
|
sudo sed -i "s/-Djava.awt.headless=true/& -Djenkins.install.runSetupWizard=false/g" /etc/default/jenkins
|
|
|
|
sudo service $app restart # Redémarre jenkins
|
|
tempfile="$(mktemp)"
|
|
tail -f -n1 /var/log/$app/$app.log > "$tempfile" & # Suit le démarrage dans le log
|
|
PID_TAIL=$! # Récupère le PID de la commande tail, qui est passée en arrière plan.
|
|
|
|
sudo yunohost service add jenkins -l /var/log/jenkins/jenkins.log
|
|
|
|
echo "Nginx configuration (sso disabled)..."
|
|
sed -i "s@__PATH__@$path@g" ../conf/nginx.conf
|
|
sed -i "s@__PORT__@$port@g" ../conf/nginx.conf
|
|
sed -i "s@__DOMAIN__@$domain@g" ../conf/nginx.conf
|
|
|
|
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/jenkins.conf
|
|
|
|
sudo yunohost app setting jenkins is_public -v $is_public
|
|
if [ "$is_public" = "Yes" ];
|
|
then
|
|
sudo yunohost app setting jenkins unprotected_uris -v "/"
|
|
fi
|
|
|
|
sudo service nginx reload
|
|
sudo yunohost app ssowatconf
|
|
|
|
# Surveille le démarrage du service.
|
|
config_OK=0
|
|
for i in `seq 1 60`
|
|
do # La boucle attend le démarrage de jenkins Ou 60 secondes.
|
|
if grep -q "INFOS: Jenkins is fully up and running" "$tempfile" && [ "$config_OK" -eq 0 ]; then
|
|
# Si le log annonce une première fois le démarrage de jenkins. Fait sauter la sécurité de la première connexion de l'admin. Qui bloque curl et demande une identification inexistante une fois sur deux...
|
|
sudo wget -nv --no-check-certificate https://$domain$path/jnlpJars/jenkins-cli.jar -O /var/lib/jenkins/jenkins-cli.jar
|
|
for i in `seq 1 60`
|
|
do # La boucle attend la mise à jour des dépôts de plugins. Ou 20 secondes.
|
|
if test -e /var/lib/jenkins/updates/default.json; then
|
|
break;
|
|
else
|
|
echo -n "." >&2
|
|
sleep 1
|
|
fi
|
|
done
|
|
java -jar /var/lib/jenkins/jenkins-cli.jar -s https://$domain$path install-plugin reverse-proxy-auth-plugin
|
|
|
|
sudo cp ../conf/config.xml /var/lib/jenkins/
|
|
sudo chown jenkins: /var/lib/jenkins/config.xml
|
|
|
|
sudo service $app restart # Puis redémarre à nouveau le service.
|
|
cat /dev/null > "$tempfile" # Purge le log de suivi du démarrage.
|
|
config_OK=1
|
|
i=1;
|
|
fi
|
|
if grep -q "INFOS: Jenkins is fully up and running" "$tempfile" && [ "$config_OK" -eq 1 ]; then
|
|
break # Si le log annonce une deuxième fois le démarrage d'etherpad, sort de la boucle.
|
|
fi
|
|
echo -n "." >&2
|
|
sleep 1
|
|
|
|
done
|
|
kill -s 15 $PID_TAIL > /dev/null # Arrête l'exécution de tail.
|
|
sudo rm "$tempfile"
|