2018-12-16 23:05:12 +01:00
|
|
|
#=================================================
|
|
|
|
# SET ALL CONSTANTS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
config_path="/etc/$app"
|
|
|
|
final_path="/opt/$app"
|
|
|
|
|
2018-12-19 00:02:20 +01:00
|
|
|
#=================================================
|
|
|
|
# DETECT THE SYSTEM ARCHITECTURE
|
|
|
|
#=================================================
|
|
|
|
# Detect the system architecture to download the right file
|
2018-12-16 23:05:12 +01:00
|
|
|
# NOTE: `uname -m` is more accurate and universal than `arch`
|
|
|
|
# See https://en.wikipedia.org/wiki/Uname
|
|
|
|
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
|
|
|
|
|
2018-12-19 00:02:20 +01:00
|
|
|
#=================================================
|
|
|
|
# CREATE FOLDERS
|
|
|
|
#=================================================
|
2018-12-16 23:05:12 +01:00
|
|
|
create_dir() {
|
|
|
|
mkdir -p "$config_path"
|
2017-06-20 19:09:43 +02:00
|
|
|
}
|
|
|
|
|
2018-12-19 00:02:20 +01:00
|
|
|
#=================================================
|
|
|
|
# CONFIGURATION FILE FOR GITLAB
|
|
|
|
#=================================================
|
2018-12-16 23:05:12 +01:00
|
|
|
config_gitlab() {
|
2018-12-19 00:02:20 +01:00
|
|
|
create_dir
|
2018-12-19 00:34:06 +01:00
|
|
|
|
2018-12-16 23:05:12 +01:00
|
|
|
gitlab_conf_path="$config_path/gitlab.rb"
|
2017-06-20 19:09:43 +02:00
|
|
|
|
2018-12-16 23:05:12 +01:00
|
|
|
ynh_backup_if_checksum_is_different $gitlab_conf_path
|
2017-06-20 19:09:43 +02:00
|
|
|
|
2018-12-16 23:05:12 +01:00
|
|
|
# Gitlab configuration
|
|
|
|
cp -f ../conf/gitlab.rb $gitlab_conf_path
|
2017-06-20 19:09:43 +02:00
|
|
|
|
2018-12-16 23:05:12 +01:00
|
|
|
ynh_replace_string "__GENERATED_EXTERNAL_URL__" "https://$domain${path_url%/}" $gitlab_conf_path
|
|
|
|
ynh_replace_string "__PORT__" "$port" $gitlab_conf_path
|
|
|
|
ynh_replace_string "__PORTUNICORN__" "$portUnicorn" $gitlab_conf_path
|
2017-06-20 19:09:43 +02:00
|
|
|
|
2018-12-16 23:05:12 +01:00
|
|
|
ynh_store_file_checksum $gitlab_conf_path
|
2017-06-20 19:09:43 +02:00
|
|
|
}
|
|
|
|
|
2018-12-19 00:02:20 +01:00
|
|
|
#=================================================
|
|
|
|
# REMOVE THE CONFIGURATION FILE FOR GITLAB
|
|
|
|
#=================================================
|
2018-12-16 23:05:12 +01:00
|
|
|
remove_config_gitlab() {
|
|
|
|
ynh_secure_remove "$config_path/gitlab.rb"
|
2017-06-20 19:09:43 +02:00
|
|
|
}
|
|
|
|
|
2018-12-19 00:02:20 +01:00
|
|
|
#=================================================
|
|
|
|
# UPDATE SOURCES FILES
|
|
|
|
#=================================================
|
2018-12-16 23:05:12 +01:00
|
|
|
update_src_version() {
|
|
|
|
source ./upgrade.d/upgrade.sh
|
|
|
|
cp ../conf/arm.src.default ../conf/arm.src
|
|
|
|
ynh_replace_string "__VERSION__" "$gitlab_version" "../conf/arm.src"
|
|
|
|
ynh_replace_string "__SHA256_SUM__" "$gitlab_arm_source_sha256" "../conf/arm.src"
|
2017-06-20 19:09:43 +02:00
|
|
|
|
2018-12-16 23:05:12 +01:00
|
|
|
cp ../conf/x86-64.src.default ../conf/x86-64.src
|
|
|
|
ynh_replace_string "__VERSION__" "$gitlab_version" "../conf/x86-64.src"
|
|
|
|
ynh_replace_string "__SHA256_SUM__" "$gitlab_x86_64_source_sha256" "../conf/x86-64.src"
|
2017-06-20 19:09:43 +02:00
|
|
|
}
|
|
|
|
|
2018-12-19 00:02:20 +01:00
|
|
|
#=================================================
|
|
|
|
# INSTALL GITLAB
|
|
|
|
#=================================================
|
|
|
|
# This function is inspired by the ynh_setup_source function, adapted to deal with .deb files
|
|
|
|
setup_source() {
|
2018-12-16 23:05:12 +01:00
|
|
|
local src_id=${1:-app} # If the argument is not given, source_id equals "app"
|
2017-06-20 19:09:43 +02:00
|
|
|
|
2018-12-19 00:02:20 +01:00
|
|
|
update_src_version # Update source file
|
|
|
|
|
2017-06-20 19:09:43 +02:00
|
|
|
# Load value from configuration file (see above for a small doc about this file
|
|
|
|
# format)
|
2018-12-16 23:05:12 +01:00
|
|
|
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_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_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_filename=$(grep 'SOURCE_FILENAME=' "$YNH_CWD/../conf/${src_id}.src" | cut -d= -f2-)
|
2017-06-20 19:09:43 +02:00
|
|
|
|
|
|
|
# Default value
|
|
|
|
src_sumprg=${src_sumprg:-sha256sum}
|
|
|
|
src_in_subdir=${src_in_subdir:-true}
|
|
|
|
src_format=${src_format:-tar.gz}
|
|
|
|
src_format=$(echo "$src_format" | tr '[:upper:]' '[:lower:]')
|
2018-12-16 23:05:12 +01:00
|
|
|
src_extract=${src_extract:-true}
|
2017-06-20 19:09:43 +02:00
|
|
|
if [ "$src_filename" = "" ] ; then
|
|
|
|
src_filename="${src_id}.${src_format}"
|
|
|
|
fi
|
|
|
|
local local_src="/opt/yunohost-apps-src/${YNH_APP_ID}/${src_filename}"
|
|
|
|
|
|
|
|
if test -e "$local_src"
|
|
|
|
then # Use the local source file if it is present
|
|
|
|
cp $local_src $src_filename
|
|
|
|
else # If not, download the source
|
2018-12-16 23:05:12 +01:00
|
|
|
local out=`wget -nv -O $src_filename $src_url 2>&1` || ynh_print_err $out
|
2017-06-20 19:09:43 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Check the control sum
|
|
|
|
echo "${src_sum} ${src_filename}" | ${src_sumprg} -c --status \
|
|
|
|
|| ynh_die "Corrupt source"
|
|
|
|
|
2019-01-05 00:13:07 +01:00
|
|
|
#Fix for the CI
|
|
|
|
if sudo grep -qa container=lxc /proc/1/environ;
|
|
|
|
then
|
|
|
|
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
|
2019-01-13 15:44:16 +01:00
|
|
|
dpkg --configure gitlab-ce || true
|
2019-01-05 00:13:07 +01:00
|
|
|
else
|
2019-01-13 15:44:16 +01:00
|
|
|
dpkg -i $src_filename || true
|
2019-01-05 00:13:07 +01:00
|
|
|
fi;
|
2019-01-13 15:44:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# WAIT
|
|
|
|
#=================================================
|
|
|
|
# This function is inspired by the ynh_systemd_action function
|
|
|
|
waiting_to_start() {
|
|
|
|
|
|
|
|
echo "Start Waiting"
|
|
|
|
|
|
|
|
log_path="/var/log/gitlab/unicorn/current"
|
|
|
|
|
|
|
|
if [ ! -f "$log_path" ]
|
|
|
|
then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
line_match_new="adopted new unicorn master"
|
|
|
|
line_match_existing="adopted existing unicorn master"
|
|
|
|
|
|
|
|
clean_check_starting() {
|
|
|
|
# Stop the execution of tail
|
|
|
|
kill -s 15 $pid_tail 2>&1
|
|
|
|
ynh_secure_remove "$templog" 2>&1
|
|
|
|
}
|
|
|
|
|
|
|
|
# Following the starting of the app in its log
|
|
|
|
local templog="$(mktemp)"
|
|
|
|
tail -F -n1 "$log_path" > "$templog" &
|
|
|
|
# get the PID of the tail command
|
|
|
|
local pid_tail=$!
|
|
|
|
|
2019-01-15 22:57:23 +01:00
|
|
|
for i in $(seq 1 500)
|
2019-01-13 15:44:16 +01:00
|
|
|
do
|
2019-01-13 18:39:57 +01:00
|
|
|
if grep --quiet "${line_match_new}" $templog || grep --quiet "${line_match_existing}" $templog
|
2019-01-13 15:44:16 +01:00
|
|
|
then
|
2019-01-13 18:39:57 +01:00
|
|
|
echo "Gitlab has correctly started." >&2
|
2019-01-13 15:44:16 +01:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
sleep 1
|
|
|
|
echo -n "." >&2
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "Stop Waiting"
|
|
|
|
|
|
|
|
clean_check_starting
|
2017-06-20 19:09:43 +02:00
|
|
|
}
|