2017-06-10 10:10:31 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2018-12-16 23:05:12 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
2018-12-19 00:02:20 +01:00
|
|
|
#=================================================
|
|
|
|
|
2019-03-16 02:38:12 +01:00
|
|
|
source _common.sh
|
2018-12-16 23:05:12 +01:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2019-03-16 02:38:12 +01:00
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_clean_setup () {
|
|
|
|
ynh_secure_remove "$tempdir" 2>&1
|
|
|
|
|
|
|
|
ynh_clean_check_starting
|
|
|
|
}
|
2018-12-16 23:05:12 +01:00
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
2018-12-19 00:02:20 +01:00
|
|
|
#=================================================
|
2019-03-16 02:38:12 +01:00
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
2018-12-19 00:02:20 +01:00
|
|
|
#=================================================
|
|
|
|
|
2017-06-10 10:10:31 +02:00
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
path_url=$YNH_APP_ARG_PATH
|
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
2019-01-13 16:01:54 +01:00
|
|
|
use_web_account=$YNH_APP_ARG_USE_WEB_ACCOUNT
|
2017-06-28 15:41:05 +02:00
|
|
|
admin=$YNH_APP_ARG_ADMIN
|
2017-06-10 10:10:31 +02:00
|
|
|
|
2019-03-16 02:38:12 +01:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2018-12-19 00:02:20 +01:00
|
|
|
#=================================================
|
2019-03-16 02:38:12 +01:00
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
2018-12-19 00:02:20 +01:00
|
|
|
#=================================================
|
2019-03-16 02:38:12 +01:00
|
|
|
ynh_print_info "Validating installation parameters..."
|
2018-12-19 00:02:20 +01:00
|
|
|
|
2019-03-16 02:38:12 +01:00
|
|
|
config_path=/etc/$app
|
|
|
|
final_path=/opt/$app
|
|
|
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
2018-12-19 00:02:20 +01:00
|
|
|
|
2019-03-16 02:38:12 +01:00
|
|
|
# Detect the system architecture
|
|
|
|
if [ -n "$(uname -m | grep 64)" ]; then
|
|
|
|
architecture="x86-64"
|
|
|
|
elif [ -n "$(uname -m | grep 86)" ]; then
|
|
|
|
ynh_die "Gitlab is not compatible with x86 architecture"
|
|
|
|
elif [ -n "$(uname -m | grep arm)" ]; then
|
|
|
|
architecture="arm"
|
|
|
|
else
|
|
|
|
ynh_die "Unable to detect your achitecture, please open a bug describing \
|
|
|
|
your hardware and the result of the command \"uname -m\"." 1
|
|
|
|
fi
|
2017-06-10 10:10:31 +02:00
|
|
|
|
2019-03-16 02:38:12 +01:00
|
|
|
path_url=$(ynh_normalize_url_path $path_url)
|
2018-12-19 00:02:20 +01:00
|
|
|
|
2019-03-16 02:38:12 +01:00
|
|
|
# Register (book) web path
|
|
|
|
ynh_webpath_register $app $domain $path_url
|
2017-06-10 10:10:31 +02:00
|
|
|
|
2018-12-19 00:02:20 +01:00
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
2019-03-16 02:38:12 +01:00
|
|
|
ynh_print_info "Storing installation settings..."
|
2017-06-28 15:41:05 +02:00
|
|
|
|
2018-12-16 23:05:12 +01:00
|
|
|
ynh_app_setting_set $app admin $admin
|
|
|
|
ynh_app_setting_set $app path_url $path_url
|
|
|
|
ynh_app_setting_set $app is_public $is_public
|
2019-01-13 16:01:54 +01:00
|
|
|
ynh_app_setting_set $app use_web_account $use_web_account
|
2019-03-16 02:38:12 +01:00
|
|
|
ynh_app_setting_set $app final_path $final_path
|
|
|
|
ynh_app_setting_set $app config_path $config_path
|
|
|
|
ynh_app_setting_set $app architecture $architecture
|
2018-12-19 00:02:20 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
2019-03-16 02:38:12 +01:00
|
|
|
# FIND AND OPEN A PORT
|
2018-12-19 00:02:20 +01:00
|
|
|
#=================================================
|
2019-03-16 02:38:12 +01:00
|
|
|
ynh_print_info "Configuring firewall..."
|
2019-01-26 14:30:58 +01:00
|
|
|
|
2018-12-19 00:02:20 +01:00
|
|
|
# Find free ports
|
|
|
|
port=$(ynh_find_port 8080)
|
2019-01-22 15:47:54 +01:00
|
|
|
portUnicorn=$(ynh_find_port $(($port + 1)))
|
2018-12-19 00:02:20 +01:00
|
|
|
|
2019-03-16 02:38:12 +01:00
|
|
|
# Open these port
|
2018-12-19 00:02:20 +01:00
|
|
|
yunohost firewall allow --no-upnp TCP $port 2>&1
|
|
|
|
yunohost firewall allow --no-upnp TCP $portUnicorn 2>&1
|
2018-12-16 23:05:12 +01:00
|
|
|
ynh_app_setting_set $app web_port $port
|
|
|
|
ynh_app_setting_set $app unicorn_port $portUnicorn
|
2017-06-10 10:10:31 +02:00
|
|
|
|
2018-12-16 23:05:12 +01:00
|
|
|
#=================================================
|
2019-03-16 02:38:12 +01:00
|
|
|
# INSTALL DEPENDENCIES
|
2018-12-16 23:05:12 +01:00
|
|
|
#=================================================
|
2019-03-16 02:38:12 +01:00
|
|
|
ynh_print_info "Installing dependencies..."
|
2017-06-10 10:10:31 +02:00
|
|
|
|
2019-03-16 02:38:12 +01:00
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
2017-06-10 10:35:32 +02:00
|
|
|
|
2018-12-19 00:02:20 +01:00
|
|
|
#=================================================
|
2019-03-16 02:38:12 +01:00
|
|
|
# PRECONFIGURE GITLAB
|
2018-12-19 00:02:20 +01:00
|
|
|
#=================================================
|
2019-03-16 02:38:12 +01:00
|
|
|
ynh_print_info "Preconfigure gitlab..."
|
|
|
|
|
|
|
|
mkdir -p $config_path
|
|
|
|
|
|
|
|
cp -f ../conf/gitlab.rb "$config_path/gitlab.rb"
|
2017-06-10 10:10:31 +02:00
|
|
|
|
2019-03-16 02:38:12 +01:00
|
|
|
ynh_replace_string "__GENERATED_EXTERNAL_URL__" "https://$domain${path_url%/}" "$config_path/gitlab.rb"
|
|
|
|
ynh_replace_string "__PORT__" "$port" "$config_path/gitlab.rb"
|
|
|
|
ynh_replace_string "__PORTUNICORN__" "$portUnicorn" "$config_path/gitlab.rb"
|
2017-06-28 15:41:05 +02:00
|
|
|
|
2018-12-19 00:02:20 +01:00
|
|
|
#=================================================
|
2019-03-16 02:38:12 +01:00
|
|
|
# STORE THE CONFIG FILE CHECKSUM
|
2018-12-19 00:02:20 +01:00
|
|
|
#=================================================
|
|
|
|
|
2019-03-16 02:38:12 +01:00
|
|
|
ynh_store_file_checksum "$config_path/gitlab.rb"
|
2017-06-28 15:41:05 +02:00
|
|
|
|
2018-12-19 00:02:20 +01:00
|
|
|
#=================================================
|
2019-03-16 02:38:12 +01:00
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
2018-12-19 00:02:20 +01:00
|
|
|
#=================================================
|
2019-03-16 02:38:12 +01:00
|
|
|
ynh_print_info "Setting up source files..."
|
|
|
|
|
|
|
|
update_src_version() {
|
|
|
|
source ./upgrade.d/upgrade.last.sh
|
2019-03-16 12:28:47 +01:00
|
|
|
cp ../conf/$architecture.src.default ../conf/$architecture.src
|
|
|
|
ynh_replace_string "__VERSION__" "$gitlab_version" "../conf/$architecture.src"
|
|
|
|
ynh_replace_string "__SOURCE_FILENAME__" "$gitlab_filename" "../conf/$architecture.src"
|
2019-03-16 13:17:15 +01:00
|
|
|
|
|
|
|
if [ $architecture = "x86-64" ]; then
|
|
|
|
ynh_replace_string "__SHA256_SUM__" "$gitlab_x86_64_source_sha256" "../conf/$architecture.src"
|
|
|
|
elif [ $architecture = "arm" ]; then
|
|
|
|
ynh_replace_string "__SHA256_SUM__" "$gitlab_arm_source_sha256" "../conf/$architecture.src"
|
|
|
|
fi
|
2019-03-16 02:38:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
update_src_version
|
|
|
|
|
|
|
|
tempdir="$(mktemp -d)"
|
2017-06-28 15:41:05 +02:00
|
|
|
|
2019-03-16 02:38:12 +01:00
|
|
|
ynh_setup_source $tempdir $architecture
|
|
|
|
|
|
|
|
if IS_PACKAGE_CHECK; then
|
|
|
|
dpkg -i $tempdir/$gitlab_filename || true # This command will fail in lxc env
|
2019-03-16 12:29:00 +01:00
|
|
|
ynh_replace_string "command \"cat \/etc\/sysctl.conf \/etc\/sysctl.d\/\*.conf | sysctl -e -p -\"" "command \"cat \/etc\/sysctl.conf\"" "$final_path/embedded/cookbooks/package/resources/sysctl.rb"
|
2019-03-16 02:38:12 +01:00
|
|
|
dpkg --configure gitlab-ce
|
|
|
|
else
|
|
|
|
dpkg -i $tempdir/$gitlab_filename
|
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
ynh_print_info "Configuring nginx web server..."
|
|
|
|
|
|
|
|
# Create a dedicated nginx config
|
|
|
|
ynh_add_nginx_config
|
2017-06-28 15:41:05 +02:00
|
|
|
|
2018-12-19 00:02:20 +01:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
2019-03-16 02:38:12 +01:00
|
|
|
# ADD USER AND CONFIGURE SIGN IN SYSTEM
|
2018-12-19 00:02:20 +01:00
|
|
|
#=================================================
|
2019-01-26 14:30:58 +01:00
|
|
|
ynh_print_info "Creating an administrator user..."
|
|
|
|
|
2018-12-19 00:02:20 +01:00
|
|
|
mailadmin=$(ynh_user_get_info $admin mail)
|
|
|
|
rdmPass=$(ynh_string_random 30)
|
|
|
|
|
2017-06-28 16:28:20 +02:00
|
|
|
echo "newuser = User.new({ \"email\"=>'$mailadmin', \"username\"=>'$admin', \"name\"=>'$admin', \"password\"=>'$rdmPass'})
|
2017-06-28 15:41:05 +02:00
|
|
|
newuser.admin = true
|
|
|
|
newuser.confirmed_at = Time.now
|
|
|
|
newuser.confirmation_token = nil
|
2018-12-24 16:25:32 +01:00
|
|
|
newuser.save
|
2019-02-09 14:36:32 +01:00
|
|
|
ApplicationSetting.last.update_attributes(password_authentication_enabled_for_web: $use_web_account, signup_enabled: $use_web_account)" | gitlab-rails console
|
2017-06-28 15:41:05 +02:00
|
|
|
|
2018-12-19 00:02:20 +01:00
|
|
|
#=================================================
|
2019-03-16 02:38:12 +01:00
|
|
|
# RECONFIGURE TO TAKE INTO ACCOUNT CHANGES
|
2018-12-19 00:02:20 +01:00
|
|
|
#=================================================
|
2019-03-16 02:38:12 +01:00
|
|
|
ynh_print_info "Reconfigure gitlab..."
|
2018-12-19 00:02:20 +01:00
|
|
|
|
2019-02-09 14:36:32 +01:00
|
|
|
gitlab-ctl reconfigure
|
2017-06-10 10:10:31 +02:00
|
|
|
|
2019-03-16 02:38:12 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
2018-12-19 00:02:20 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2019-03-16 02:38:12 +01:00
|
|
|
ynh_print_info "Configuring SSOwat..."
|
2018-12-19 00:02:20 +01:00
|
|
|
|
2019-03-16 02:38:12 +01:00
|
|
|
# Make app public if necessary
|
|
|
|
if [ $is_public -eq 1 ]; then
|
2019-01-26 14:46:52 +01:00
|
|
|
# unprotected_uris allows SSO credentials to be passed anyway.
|
2019-03-16 02:38:12 +01:00
|
|
|
ynh_app_setting_set $app unprotected_uris "/"
|
2017-06-10 10:10:31 +02:00
|
|
|
fi
|
|
|
|
|
2018-12-19 00:02:20 +01:00
|
|
|
#=================================================
|
2019-03-16 02:38:12 +01:00
|
|
|
# RESTART GITLAB
|
|
|
|
#=================================================
|
|
|
|
ynh_print_info "Restarting gitlab..."
|
|
|
|
|
|
|
|
gitlab_ctl_action --action=restart --line_match="adopted new unicorn master" --log_path="/var/log/gitlab/unicorn/current" --timeout=3600
|
|
|
|
|
2018-12-19 00:02:20 +01:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2019-03-16 02:38:12 +01:00
|
|
|
ynh_print_info "Reloading nginx web server..."
|
2018-12-19 00:02:20 +01:00
|
|
|
|
2019-03-16 02:38:12 +01:00
|
|
|
ynh_systemd_action --action=reload --service_name=nginx
|
2018-12-19 00:02:20 +01:00
|
|
|
|
|
|
|
#=================================================
|
2019-03-16 02:38:12 +01:00
|
|
|
# END OF SCRIPT
|
2018-12-19 00:02:20 +01:00
|
|
|
#=================================================
|
|
|
|
|
2019-03-16 02:38:12 +01:00
|
|
|
ynh_print_info "Installation of $app completed"
|