1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/gitlab_ynh.git synced 2024-09-03 18:36:35 +02:00
gitlab_ynh/scripts/install
2017-08-01 20:42:20 +02:00

101 lines
3.5 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# Exit on command errors and treat unset variables as an error
set -eu
# This is a multi-instance app, meaning it can be installed several times independently
# The id of the app as stated in the manifest is available as $YNH_APP_ID
# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...)
# The app instance name is available as $YNH_APP_INSTANCE_NAME
# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample
# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2
# - ynhexample__{N} for the subsequent installations, with N=3,4, ...
# The app instance name is probably what you are interested the most, since this is
# guaranteed to be unique. This is a good unique identifier to define installation path,
# db names, ...
app=$YNH_APP_INSTANCE_NAME
# Retrieve arguments
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
is_public=$YNH_APP_ARG_IS_PUBLIC
admin=$YNH_APP_ARG_ADMIN
# Source YunoHost helpers
source /usr/share/yunohost/helpers
# Save app settings
ynh_app_setting_set "$app" is_public "$is_public"
mailadmin=$(ynh_user_get_info $admin mail)
portNginx=$(ynh_find_port 8080)
portUnicorn=$(ynh_find_port 9080)
rdmPass=$(ynh_string_random 30)
# Check domain/path availability
sudo yunohost app checkurl "${domain}${path_url}" -a "$app" \
|| ynh_die "Path not available: ${domain}${path_url}"
# Add gitlab repository
sudo apt-get install -yy curl openssh-server ca-certificates postfix apt-transport-https
curl -L https://packages.gitlab.com/gitlab/gitlab-ce/gpgkey | sudo apt-key add -
sudo apt-get update
sudo apt-get install -yy debian-archive-keyring
sudo cp ../conf/gitlab-ce.list /etc/apt/sources.list.d/gitlab-ce.list
sudo apt-get update
sudo apt-get install -yy gitlab-ce
# Gitlab configuration
sed -i "s@GENERATED_EXTERNAL_URL@https://$domain@" ../conf/gitlab.rb
sed -i "s@PORTNGINX@$portNginx@" ../conf/gitlab.rb
sed -i "s@PORTUNICORN@$portUnicorn@" ../conf/gitlab.rb
sudo cp -f ../conf/gitlab.rb /etc/gitlab/gitlab.rb
sudo gitlab-ctl reconfigure
echo "newuser = User.new({ \"email\"=>'$mailadmin', \"username\"=>'$admin', \"name\"=>'$admin', \"password\"=>'$rdmPass'})
newuser.admin = true
newuser.confirmed_at = Time.now
newuser.confirmation_token = nil
newuser.save" | sudo gitlab-rails console
sudo gitlab-ctl reconfigure
# Set permissions to app files
# you may need to make some file and/or directory writeable by www-data (nginx user)
# sudo chown -R root: $src_path
#=================================================
# START GITLAB IN BACKGROUND
#=================================================
WARNING echo "Démarrage de gitlab"
tempfile="$(mktemp)"
tail -f -n1 /var/log/$app/gitlab.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 systemctl start $app # Démarre gitlab. Le démarrage est fait le plus tôt possible, car il est très long...
# Modify Nginx configuration file and copy it to Nginx conf directory
nginx_conf=../conf/nginx.conf
sed -i "s@YNH_WWW_PATH@$path_url@g" $nginx_conf
sed -i "s@PORT@$portNginx@g" $nginx_conf
sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf
# If app is public, add url to SSOWat conf as skipped_uris
if [[ $is_public -eq 1 ]]; then
# unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set "$app" unprotected_uris "/"
fi
# Reload services
sudo yunohost app ssowatconf
sudo service nginx reload
sudo gitlab-ctl restart