1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/gitlab_ynh.git synced 2024-09-03 18:36:35 +02:00

Open Ports and add sections

This commit is contained in:
Pierre Bourré 2018-12-19 00:02:20 +01:00
parent a582665596
commit 0b52ed7eb3
5 changed files with 260 additions and 47 deletions

View file

@ -6,7 +6,10 @@ app=$YNH_APP_INSTANCE_NAME
config_path="/etc/$app"
final_path="/opt/$app"
# Detect the system architecture to download the right tarball
#=================================================
# DETECT THE SYSTEM ARCHITECTURE
#=================================================
# Detect the system architecture to download the right file
# NOTE: `uname -m` is more accurate and universal than `arch`
# See https://en.wikipedia.org/wiki/Uname
if [ -n "$(uname -m | grep 64)" ]; then
@ -20,6 +23,9 @@ else
your hardware and the result of the command \"uname -m\"." 1
fi
#=================================================
# CONFIGURE NGINX
#=================================================
config_nginx() {
if [ "$path_url" != "/" ]
then
@ -28,11 +34,19 @@ config_nginx() {
ynh_add_nginx_config
}
#=================================================
# CREATE FOLDERS
#=================================================
create_dir() {
mkdir -p "$config_path"
}
#=================================================
# CONFIGURATION FILE FOR GITLAB
#=================================================
config_gitlab() {
create_dir
gitlab_conf_path="$config_path/gitlab.rb"
ynh_backup_if_checksum_is_different $gitlab_conf_path
@ -47,10 +61,16 @@ config_gitlab() {
ynh_store_file_checksum $gitlab_conf_path
}
#=================================================
# REMOVE THE CONFIGURATION FILE FOR GITLAB
#=================================================
remove_config_gitlab() {
ynh_secure_remove "$config_path/gitlab.rb"
}
#=================================================
# UPDATE SOURCES FILES
#=================================================
update_src_version() {
source ./upgrade.d/upgrade.sh
cp ../conf/arm.src.default ../conf/arm.src
@ -62,9 +82,15 @@ update_src_version() {
ynh_replace_string "__SHA256_SUM__" "$gitlab_x86_64_source_sha256" "../conf/x86-64.src"
}
#=================================================
# INSTALL GITLAB
#=================================================
# This function is inspired by the ynh_setup_source function, adapted to deal with .deb files
setup_source() {
local src_id=${1:-app} # If the argument is not given, source_id equals "app"
update_src_version # Update source file
# Load value from configuration file (see above for a small doc about this file
# format)
local src_url=$(grep 'SOURCE_URL=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-)

View file

@ -3,6 +3,8 @@
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# IMPORT GENERIC HELPERS
source /usr/share/yunohost/helpers
@ -12,6 +14,7 @@ ynh_abort_if_errors
# Import common cmd
source ./_common.sh
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
@ -24,6 +27,10 @@ new_path=$YNH_APP_NEW_PATH
app=$YNH_APP_INSTANCE_NAME
#=================================================
# LOAD SETTINGS
#=================================================
port=$(ynh_app_setting_get "$app" web_port)
portUnicorn=$(ynh_app_setting_get "$app" unicorn_port)
@ -39,7 +46,6 @@ old_path=$(ynh_normalize_url_path $old_path)
domain="$new_domain"
path_url="$new_path"
#=================================================
# CHECK WHICH PARTS SHOULD BE CHANGED
#=================================================
@ -56,16 +62,29 @@ then
change_path=1
fi
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# MODIFY URL IN NGINX
#=================================================
#doc in: https://docs.gitlab.com/omnibus/settings/configuration.html#configuring-the-external-url-for-gitlab
# Gitlab configuration
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
gitlab_conf_path=/etc/gitlab/gitlab.rb
if [ $change_path -eq 1 ]
then
sudo gitlab-ctl stop unicorn
sudo gitlab-ctl stop sidekiq
# Make a backup of the original nginx config file if modified
ynh_backup_if_checksum_is_different "$nginx_conf_path"
# Set global variables for nginx helper
domain="$old_domain"
path_url="$new_path"
# Create a dedicated nginx config
config_nginx
fi
# Change the domain for nginx
@ -73,11 +92,14 @@ if [ $change_domain -eq 1 ]
then
# Delete file checksum for the old conf file location
ynh_delete_file_checksum "$nginx_conf_path"
ynh_secure_remove "$nginx_conf_path"
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
# Store file checksum for the new config file location
ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf"
fi
config_nginx
#=================================================
# CONFIGURE GITLAB
#=================================================
config_gitlab
@ -87,3 +109,11 @@ if [ $change_path -eq 1 ]
then
sudo gitlab-ctl restart
fi
#=================================================
# GENERIC FINALISATION
#=================================================
# RELOAD NGINX
#=================================================
service nginx reload

View file

@ -3,8 +3,9 @@
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source /usr/share/yunohost/helpers
# Exit if an error occurs during the execution of the script
@ -13,70 +14,125 @@ ynh_abort_if_errors
# Load common variables and helpers
source ./_common.sh
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
# 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
# Check domain/path availability
#=================================================
# REGISTER DOMAIN
#=================================================
# Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url)
# This function check also the availability of this one
ynh_webpath_register $app $domain $path_url
#=================================================
# REGISTER DOMAIN
#=================================================
# Check user parameter
ynh_user_exists "$admin" \
|| ynh_die "The chosen admin user does not exist."
mailadmin=$(ynh_user_get_info $admin mail)
port=$(ynh_find_port 8080)
portUnicorn=$(ynh_find_port 9080)
rdmPass=$(ynh_string_random 30)
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
# Save app settings
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
ynh_app_setting_set $app web_port $port
ynh_app_setting_set $app unicorn_port $portUnicorn
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN PORTS
#=================================================
# Modify Nginx configuration file and copy it to Nginx conf directory
# Find free ports
port=$(ynh_find_port 8080)
portUnicorn=$(ynh_find_port 9080)
yunohost firewall allow --no-upnp TCP $port 2>&1
yunohost firewall allow --no-upnp TCP $portUnicorn 2>&1
ynh_app_setting_set $app web_port $port
ynh_app_setting_set $app unicorn_port $portUnicorn
#=================================================
# NGINX CONFIGURATION
#=================================================
# Create a dedicated nginx config
config_nginx
create_dir
#=================================================
# CONFIGURE GITLAB
#=================================================
# Configure gitlab with gitlab.rb file
config_gitlab
# Add dependencies
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_install_app_dependencies openssh-server
# Update to the last version
update_src_version
#=================================================
# DOWNLOAD, CHECK AND INSTALL GITLAB
#=================================================
# Install gitlab
setup_source $architecture
#=================================================
# SPECIFIC SETUP
#=================================================
# GETTING ADMIN INFO AND ADD AS A GITLAB USER
#=================================================
mailadmin=$(ynh_user_get_info $admin mail)
rdmPass=$(ynh_string_random 30)
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
#=================================================
# RESTART TO TAKE INTO ACCOUNT CHANGES
#=================================================
sudo gitlab-ctl reconfigure
#=================================================
# SETUP SSOWAT
#=================================================
# 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
#=================================================
# GENERIC FINALISATION
#=================================================
# RELOAD NGINX
#=================================================
service nginx reload
#=================================================
# SETUP LOGROTATE
#=================================================
# Configure logrotate
#ynh_use_logrotate "/var/log/$app"
# Reload services
#sudo yunohost app ssowatconf
#sudo service nginx reload
#sudo gitlab-ctl restart

View file

@ -1,9 +1,10 @@
#!/bin/bash
set -u
# See comments in install script
app=$YNH_APP_INSTANCE_NAME
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Source YunoHost helpers
source /usr/share/yunohost/helpers
@ -11,22 +12,72 @@ source /usr/share/yunohost/helpers
# Load common variables and helpers
source ./_common.sh
#=================================================
# LOAD SETTINGS
#=================================================
# See comments in install script
app=$YNH_APP_INSTANCE_NAME
port=$(ynh_app_setting_get "$app" web_port)
portUnicorn=$(ynh_app_setting_get "$app" unicorn_port)
#=================================================
# STANDARD REMOVE
#=================================================
# REMOVE GITLAB
#=================================================
# Remove gitlab
dpkg --remove gitlab-ce
#=================================================
# REMOVE CONF GILE
#=================================================
# Remove Config
remove_config_gitlab
# Remove dependencies
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_remove_app_dependencies
# Remove a directory securely
ynh_secure_remove "/etc/$app"
ynh_secure_remove "/opt/$app"
#=================================================
# REMOVE APP MAIN DIR
#=================================================
ynh_secure_remove "$final_path"
ynh_secure_remove "$config_path"
ynh_secure_remove "/var/opt/$app"
# Remove the log files
ynh_secure_remove "/var/log/$app"
# Remove nginx configuration file
#=================================================
# CLOSE PORTS
#=================================================
if yunohost firewall list | grep -q "\- $port$"
then
echo "Close port $port" >&2
yunohost firewall disallow TCP $port 2>&1
fi
if yunohost firewall list | grep -q "\- $portUnicorn$"
then
echo "Close port $portUnicorn" >&2
yunohost firewall disallow TCP $portUnicorn 2>&1
fi
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_remove_nginx_config
#=================================================
# REMOVE LOGROTATE CONFIGURATION
#=================================================
#ynh_remove_logrotate

View file

@ -1,15 +1,21 @@
#!/bin/bash
# Source YunoHost helpers
source /usr/share/yunohost/helpers
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
# IMPORT GENERIC HELPERS
source /usr/share/yunohost/helpers
# Load common variables and helpers
source ./_common.sh
# See comments in install script
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
# Retrieve app settings
@ -20,28 +26,72 @@ is_public=$(ynh_app_setting_get "$app" is_public)
port=$(ynh_app_setting_get "$app" web_port)
portUnicorn=$(ynh_app_setting_get "$app" unicorn_port)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
# TODO: Backup and Restore Scripts
## Backup the current version of the app
#ynh_backup_before_upgrade
#ynh_clean_setup () {
# # restore it if the upgrade fails
# ynh_restore_upgradebackup
#}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# CHECK THE PATH
#=================================================
# Normalize the URL path syntax
path_url=$(ynh_normalize_url_path $path_url)
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# NGINX CONFIGURATION
#=================================================
# Modify Nginx configuration file and copy it to Nginx conf directory
config_nginx
create_dir
#=================================================
# CONFIGURE GITLAB
#=================================================
# Configure gitlab with gitlab.rb file
config_gitlab
# Add dependencies
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_install_app_dependencies openssh-server
# Update to the last version
update_src_version
#=================================================
# DOWNLOAD, CHECK AND INSTALL GITLAB
#=================================================
# Update Gitlab
setup_source $architecture
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP SSOWAT
#=================================================
# If app is public, add url to SSOWat conf as skipped_uris
if [[ $is_public -eq 1 ]]; then
# See install script
ynh_app_setting_set "$app" unprotected_uris "/"
fi
#=================================================
# RELOAD NGINX
#=================================================
# Reload nginx service
sudo service nginx reload
service nginx reload