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

format files

This commit is contained in:
Pierre Bourré 2019-01-26 14:46:52 +01:00
parent 079f64b387
commit 2c14e80a2b
8 changed files with 113 additions and 125 deletions

View file

@ -22,7 +22,7 @@
"nginx" "nginx"
], ],
"arguments": { "arguments": {
"install" : [ "install": [
{ {
"name": "domain", "name": "domain",
"type": "domain", "type": "domain",
@ -44,7 +44,7 @@
}, },
{ {
"name": "admin", "name": "admin",
"type": "user", "type": "user",
"ask": { "ask": {
"en": "Choose an admin user", "en": "Choose an admin user",
"fr": "Choisissez ladministrateur" "fr": "Choisissez ladministrateur"
@ -71,4 +71,4 @@
} }
] ]
} }
} }

View file

@ -27,20 +27,20 @@ fi
# CREATE FOLDERS # CREATE FOLDERS
#================================================= #=================================================
create_dir() { create_dir() {
mkdir -p "$config_path" mkdir -p "$config_path"
} }
#================================================= #=================================================
# CONFIGURATION FILE FOR GITLAB # CONFIGURATION FILE FOR GITLAB
#================================================= #=================================================
config_gitlab() { config_gitlab() {
ynh_print_info "Configuring Gitlab..." ynh_print_info "Configuring Gitlab..."
create_dir create_dir
gitlab_conf_path="$config_path/gitlab.rb" gitlab_conf_path="$config_path/gitlab.rb"
ynh_backup_if_checksum_is_different $gitlab_conf_path ynh_backup_if_checksum_is_different $gitlab_conf_path
# Gitlab configuration # Gitlab configuration
cp -f ../conf/gitlab.rb $gitlab_conf_path cp -f ../conf/gitlab.rb $gitlab_conf_path
@ -49,14 +49,14 @@ config_gitlab() {
ynh_replace_string "__PORT__" "$port" $gitlab_conf_path ynh_replace_string "__PORT__" "$port" $gitlab_conf_path
ynh_replace_string "__PORTUNICORN__" "$portUnicorn" $gitlab_conf_path ynh_replace_string "__PORTUNICORN__" "$portUnicorn" $gitlab_conf_path
ynh_store_file_checksum $gitlab_conf_path ynh_store_file_checksum $gitlab_conf_path
} }
#================================================= #=================================================
# REMOVE THE CONFIGURATION FILE FOR GITLAB # REMOVE THE CONFIGURATION FILE FOR GITLAB
#================================================= #=================================================
remove_config_gitlab() { remove_config_gitlab() {
ynh_print_info "Removing the configuration file..." ynh_print_info "Removing the configuration file..."
ynh_secure_remove "$config_path/gitlab.rb" ynh_secure_remove "$config_path/gitlab.rb"
} }
@ -80,54 +80,52 @@ update_src_version() {
#================================================= #=================================================
# This function is inspired by the ynh_setup_source function, adapted to deal with .deb files # This function is inspired by the ynh_setup_source function, adapted to deal with .deb files
setup_source() { setup_source() {
local src_id=${1:-app} # If the argument is not given, source_id equals "app" local src_id=${1:-app} # If the argument is not given, source_id equals "app"
update_src_version # Update source file update_src_version # Update source file
# Load value from configuration file (see above for a small doc about this file # Load value from configuration file (see above for a small doc about this file
# format) # format)
local src_url=$(grep 'SOURCE_URL=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-) local src_url=$(grep 'SOURCE_URL=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-)
local src_sum=$(grep 'SOURCE_SUM=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-) local src_sum=$(grep 'SOURCE_SUM=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-)
local src_sumprg=$(grep 'SOURCE_SUM_PRG=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-) local src_sumprg=$(grep 'SOURCE_SUM_PRG=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-)
local src_format=$(grep 'SOURCE_FORMAT=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-) local src_format=$(grep 'SOURCE_FORMAT=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-)
local src_extract=$(grep 'SOURCE_EXTRACT=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-) local src_extract=$(grep 'SOURCE_EXTRACT=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-)
local src_in_subdir=$(grep 'SOURCE_IN_SUBDIR=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-) local src_in_subdir=$(grep 'SOURCE_IN_SUBDIR=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-)
local src_filename=$(grep 'SOURCE_FILENAME=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-) local src_filename=$(grep 'SOURCE_FILENAME=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-)
# Default value # Default value
src_sumprg=${src_sumprg:-sha256sum} src_sumprg=${src_sumprg:-sha256sum}
src_in_subdir=${src_in_subdir:-true} src_in_subdir=${src_in_subdir:-true}
src_format=${src_format:-tar.gz} src_format=${src_format:-tar.gz}
src_format=$(echo "$src_format" | tr '[:upper:]' '[:lower:]') src_format=$(echo "$src_format" | tr '[:upper:]' '[:lower:]')
src_extract=${src_extract:-true} src_extract=${src_extract:-true}
if [ "$src_filename" = "" ] ; then if [ "$src_filename" = "" ]; then
src_filename="${src_id}.${src_format}" src_filename="${src_id}.${src_format}"
fi fi
local local_src="/opt/yunohost-apps-src/${YNH_APP_ID}/${src_filename}" local local_src="/opt/yunohost-apps-src/${YNH_APP_ID}/${src_filename}"
ynh_print_info "Downloading Gitlab files..." ynh_print_info "Downloading Gitlab files..."
if test -e "$local_src" if test -e "$local_src"; then # Use the local source file if it is present
then # Use the local source file if it is present cp $local_src $src_filename
cp $local_src $src_filename else # If not, download the source
else # If not, download the source ynh_print_info $(wget -q --show-progress -O $src_filename $src_url)
ynh_print_info $(wget -q --show-progress -O $src_filename $src_url) fi
fi
# Check the control sum # Check the control sum
echo "${src_sum} ${src_filename}" | ${src_sumprg} -c --status \ echo "${src_sum} ${src_filename}" | ${src_sumprg} -c --status ||
|| ynh_die "Corrupt source" ynh_die "Corrupt source"
ynh_print_info "Installing Gitlab..." ynh_print_info "Installing Gitlab..."
#Fix for the CI #Fix for the CI
if sudo grep -qa container=lxc /proc/1/environ; if sudo grep -qa container=lxc /proc/1/environ; then
then dpkg -i $src_filename || true # This command will fail in lxc env
dpkg -i $src_filename || true # This command will fail in lxc env sed -i 's/command \"cat \/etc\/sysctl.conf \/etc\/sysctl.d\/\*.conf | sysctl -e -p -\"/command \"cat \/etc\/sysctl.conf\"/g' $final_path/embedded/cookbooks/package/resources/sysctl.rb
sed -i 's/command \"cat \/etc\/sysctl.conf \/etc\/sysctl.d\/\*.conf | sysctl -e -p -\"/command \"cat \/etc\/sysctl.conf\"/g' $final_path/embedded/cookbooks/package/resources/sysctl.rb dpkg --configure gitlab-ce || true
dpkg --configure gitlab-ce || true else
else dpkg -i $src_filename || true
dpkg -i $src_filename || true fi
fi;
} }
#================================================= #=================================================
@ -136,40 +134,37 @@ setup_source() {
# This function is inspired by the ynh_systemd_action function # This function is inspired by the ynh_systemd_action function
waiting_to_start() { waiting_to_start() {
ynh_print_info "Waiting for a response from Gitlab..." ynh_print_info "Waiting for a response from Gitlab..."
log_path="/var/log/gitlab/unicorn/current" log_path="/var/log/gitlab/unicorn/current"
if [ ! -f "$log_path" ] if [ ! -f "$log_path" ]; then
then return 0
return 0 fi
fi
line_match_new="adopted new unicorn master" line_match_new="adopted new unicorn master"
line_match_existing="adopted existing unicorn master" line_match_existing="adopted existing unicorn master"
clean_check_starting() { clean_check_starting() {
# Stop the execution of tail # Stop the execution of tail
kill -s 15 $pid_tail 2>&1 kill -s 15 $pid_tail 2>&1
ynh_secure_remove "$templog" 2>&1 ynh_secure_remove "$templog" 2>&1
} }
# Following the starting of the app in its log # Following the starting of the app in its log
local templog="$(mktemp)" local templog="$(mktemp)"
tail -F -n1 "$log_path" > "$templog" & tail -F -n1 "$log_path" >"$templog" &
# get the PID of the tail command # get the PID of the tail command
local pid_tail=$! local pid_tail=$!
for i in $(seq 1 500) for i in $(seq 1 500); do
do if grep --quiet "${line_match_new}" $templog || grep --quiet "${line_match_existing}" $templog; then
if grep --quiet "${line_match_new}" $templog || grep --quiet "${line_match_existing}" $templog echo "Gitlab has correctly started." >&2
then break
echo "Gitlab has correctly started." >&2 fi
break sleep 1
fi echo -n "." >&2
sleep 1 done
echo -n "." >&2
done
clean_check_starting clean_check_starting
} }

View file

@ -16,9 +16,9 @@ source ../settings/scripts/_common.sh
# MANAGE SCRIPT FAILURE # MANAGE SCRIPT FAILURE
#================================================= #=================================================
ynh_clean_setup () { ynh_clean_setup() {
rm /var/opt/gitlab/backups/*_gitlab_backup.tar rm /var/opt/gitlab/backups/*_gitlab_backup.tar
true true
} }

View file

@ -51,14 +51,12 @@ path_url="$new_path"
#================================================= #=================================================
change_domain=0 change_domain=0
if [ "$old_domain" != "$new_domain" ] if [ "$old_domain" != "$new_domain" ]; then
then
change_domain=1 change_domain=1
fi fi
change_path=0 change_path=0
if [ "$old_path" != "$new_path" ] if [ "$old_path" != "$new_path" ]; then
then
change_path=1 change_path=1
fi fi
@ -73,16 +71,15 @@ fi
# Gitlab configuration # Gitlab configuration
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
if [ $change_path -eq 1 ] if [ $change_path -eq 1 ]; then
then
ynh_print_info "Changing path..." ynh_print_info "Changing path..."
sudo gitlab-ctl stop unicorn sudo gitlab-ctl stop unicorn
sudo gitlab-ctl stop sidekiq sudo gitlab-ctl stop sidekiq
# Make a backup of the original nginx config file if modified # Make a backup of the original nginx config file if modified
ynh_backup_if_checksum_is_different "$nginx_conf_path" ynh_backup_if_checksum_is_different "$nginx_conf_path"
# Set global variables for nginx helper # Set global variables for nginx helper
domain="$old_domain" domain="$old_domain"
path_url="$new_path" path_url="$new_path"
# Create a dedicated nginx config # Create a dedicated nginx config
@ -90,11 +87,10 @@ then
fi fi
# Change the domain for nginx # Change the domain for nginx
if [ $change_domain -eq 1 ] if [ $change_domain -eq 1 ]; then
then
ynh_print_info "Changing domain..." ynh_print_info "Changing domain..."
# Delete file checksum for the old conf file location # Delete file checksum for the old conf file location
ynh_delete_file_checksum "$nginx_conf_path" ynh_delete_file_checksum "$nginx_conf_path"
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
# Store file checksum for the new config file location # Store file checksum for the new config file location
@ -109,10 +105,9 @@ config_gitlab
sudo gitlab-ctl reconfigure sudo gitlab-ctl reconfigure
if [ $change_path -eq 1 ] if [ $change_path -eq 1 ]; then
then sudo gitlab-ctl restart
sudo gitlab-ctl restart sudo gitlab-ctl restart unicorn
sudo gitlab-ctl restart unicorn
fi fi
#================================================= #=================================================
@ -127,4 +122,4 @@ systemctl reload nginx
# WAIT # WAIT
#================================================= #=================================================
waiting_to_start waiting_to_start

View file

@ -40,8 +40,8 @@ ynh_webpath_register $app $domain $path_url
#================================================= #=================================================
# Check user parameter # Check user parameter
ynh_user_exists "$admin" \ ynh_user_exists "$admin" ||
|| ynh_die "The chosen admin user does not exist." ynh_die "The chosen admin user does not exist."
#================================================= #=================================================
# STORE SETTINGS FROM MANIFEST # STORE SETTINGS FROM MANIFEST
@ -111,7 +111,7 @@ newuser.admin = true
newuser.confirmed_at = Time.now newuser.confirmed_at = Time.now
newuser.confirmation_token = nil newuser.confirmation_token = nil
newuser.save newuser.save
ApplicationSetting.last.update_attributes(password_authentication_enabled_for_web: $use_web_account, signup_enabled: $use_web_account)" | sudo gitlab-rails console ApplicationSetting.last.update_attributes(password_authentication_enabled_for_web: $use_web_account, signup_enabled: $use_web_account)" | sudo gitlab-rails console
#================================================= #=================================================
# RESTART TO TAKE INTO ACCOUNT CHANGES # RESTART TO TAKE INTO ACCOUNT CHANGES
@ -125,8 +125,8 @@ sudo gitlab-ctl reconfigure
# If app is public, add url to SSOWat conf as skipped_uris # If app is public, add url to SSOWat conf as skipped_uris
if [[ $is_public -eq 1 ]]; then if [[ $is_public -eq 1 ]]; then
# unprotected_uris allows SSO credentials to be passed anyway. # unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set "$app" unprotected_uris "/" ynh_app_setting_set "$app" unprotected_uris "/"
fi fi
#================================================= #=================================================
@ -141,4 +141,4 @@ systemctl reload nginx
# WAIT # WAIT
#================================================= #=================================================
waiting_to_start waiting_to_start

View file

@ -31,7 +31,7 @@ portUnicorn=$(ynh_app_setting_get "$app" unicorn_port)
ynh_print_info "Removing Gitlab..." ynh_print_info "Removing Gitlab..."
# Remove gitlab # Remove gitlab
dpkg --remove gitlab-ce dpkg --remove gitlab-ce
#================================================= #=================================================
# REMOVE CONF GILE # REMOVE CONF GILE
@ -61,14 +61,12 @@ ynh_secure_remove "/var/log/$app"
# CLOSE PORTS # CLOSE PORTS
#================================================= #=================================================
if yunohost firewall list | grep -q "\- $port$" if yunohost firewall list | grep -q "\- $port$"; then
then
echo "Close port $port" >&2 echo "Close port $port" >&2
yunohost firewall disallow TCP $port 2>&1 yunohost firewall disallow TCP $port 2>&1
fi fi
if yunohost firewall list | grep -q "\- $portUnicorn$" if yunohost firewall list | grep -q "\- $portUnicorn$"; then
then
echo "Close port $portUnicorn" >&2 echo "Close port $portUnicorn" >&2
yunohost firewall disallow TCP $portUnicorn 2>&1 yunohost firewall disallow TCP $portUnicorn 2>&1
fi fi
@ -83,4 +81,4 @@ ynh_remove_nginx_config
# REMOVE LOGROTATE CONFIGURATION # REMOVE LOGROTATE CONFIGURATION
#================================================= #=================================================
#ynh_remove_logrotate #ynh_remove_logrotate

View file

@ -29,9 +29,9 @@ source _common.sh
# MANAGE SCRIPT FAILURE # MANAGE SCRIPT FAILURE
#================================================= #=================================================
ynh_clean_setup () { ynh_clean_setup() {
rm /var/opt/gitlab/backups/*_gitlab_backup.tar rm /var/opt/gitlab/backups/*_gitlab_backup.tar
true true
} }
@ -47,10 +47,10 @@ path_url=$(ynh_app_setting_get "$app" path_url)
# CHECK IF THE APP CAN BE RESTORED # CHECK IF THE APP CAN BE RESTORED
#================================================= #=================================================
ynh_webpath_available $domain $path_url \ ynh_webpath_available $domain $path_url ||
|| ynh_die "Path not available: ${domain}${path_url}" ynh_die "Path not available: ${domain}${path_url}"
test ! -d $final_path \ test ! -d $final_path ||
|| ynh_die "There is already a directory: $final_path " ynh_die "There is already a directory: $final_path "
#================================================= #=================================================
# STANDARD RESTORATION STEPS # STANDARD RESTORATION STEPS
@ -111,4 +111,4 @@ gitlab-rake gitlab:check SANITIZE=true
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
systemctl reload nginx systemctl reload nginx

View file

@ -32,7 +32,7 @@ portUnicorn=$(ynh_app_setting_get "$app" unicorn_port)
# Backup the current version of the app # Backup the current version of the app
ynh_backup_before_upgrade ynh_backup_before_upgrade
ynh_clean_setup () { ynh_clean_setup() {
# restore it if the upgrade fails # restore it if the upgrade fails
ynh_restore_upgradebackup ynh_restore_upgradebackup
} }
@ -84,8 +84,8 @@ setup_source $architecture
# If app is public, add url to SSOWat conf as skipped_uris # If app is public, add url to SSOWat conf as skipped_uris
if [[ $is_public -eq 1 ]]; then if [[ $is_public -eq 1 ]]; then
# See install script # See install script
ynh_app_setting_set "$app" unprotected_uris "/" ynh_app_setting_set "$app" unprotected_uris "/"
fi fi
#================================================= #=================================================
@ -99,4 +99,4 @@ systemctl reload nginx
# WAIT # WAIT
#================================================= #=================================================
waiting_to_start waiting_to_start