2018-02-08 17:25:54 +01:00
|
|
|
#=================================================
|
|
|
|
# SET ALL CONSTANTS
|
|
|
|
#=================================================
|
|
|
|
|
2016-08-15 15:38:50 +02:00
|
|
|
# Detect the system architecture to download the right tarball
|
2016-10-18 00:09:26 +02:00
|
|
|
# NOTE: `uname -m` is more accurate and universal than `arch`
|
|
|
|
# See https://en.wikipedia.org/wiki/Uname
|
2020-11-20 10:09:41 +01:00
|
|
|
ynh_detect_arch(){
|
|
|
|
local architecture
|
2020-11-20 10:22:05 +01:00
|
|
|
if [ -n "$(uname -m | grep 64)" ]; then
|
|
|
|
architecture="x86-64"
|
|
|
|
elif [ -n "$(uname -m | grep 86)" ]; then
|
|
|
|
architecture="i386"
|
|
|
|
elif [ -n "$(uname -m | grep arm)" ]; then
|
|
|
|
architecture="armv7"
|
|
|
|
else
|
|
|
|
ynh_die "Unable to detect your achitecture, please open a bug describing \
|
|
|
|
your hardware and the result of the command \"uname -m\"." 1
|
2020-11-20 10:40:14 +01:00
|
|
|
fi
|
|
|
|
echo $architecture
|
2020-11-20 10:09:41 +01:00
|
|
|
}
|
|
|
|
|
2018-02-08 17:25:54 +01:00
|
|
|
#=================================================
|
|
|
|
# DEFINE ALL COMMON FONCTIONS
|
|
|
|
#=================================================
|
|
|
|
|
2018-02-07 00:31:25 +01:00
|
|
|
create_dir() {
|
2018-02-08 10:11:36 +01:00
|
|
|
mkdir -p "$final_path/data"
|
2018-06-07 22:18:45 +02:00
|
|
|
mkdir -p "$final_path/custom/conf/auth.d"
|
2018-02-07 00:31:25 +01:00
|
|
|
mkdir -p "$DATA_PATH/avatars"
|
|
|
|
mkdir -p "$DATA_PATH/attachments"
|
|
|
|
mkdir -p "/var/log/$app"
|
|
|
|
}
|
|
|
|
|
|
|
|
config_gogs() {
|
2018-02-08 00:09:28 +01:00
|
|
|
ynh_backup_if_checksum_is_different "$final_path/custom/conf/app.ini"
|
|
|
|
|
2018-02-08 15:06:12 +01:00
|
|
|
cp ../conf/app.ini "$final_path/custom/conf"
|
2018-02-08 00:09:28 +01:00
|
|
|
|
2018-02-07 00:31:25 +01:00
|
|
|
if [ "$path_url" = "/" ]
|
|
|
|
then
|
2018-02-08 00:09:28 +01:00
|
|
|
ynh_replace_string "__URL__" "$domain" "$final_path/custom/conf/app.ini"
|
2018-02-07 00:31:25 +01:00
|
|
|
else
|
2018-02-08 00:09:28 +01:00
|
|
|
ynh_replace_string "__URL__" "$domain${path_url%/}" "$final_path/custom/conf/app.ini"
|
2018-02-07 00:31:25 +01:00
|
|
|
fi
|
2018-02-08 00:09:28 +01:00
|
|
|
|
|
|
|
ynh_replace_string "__REPOS_PATH__" "$REPO_PATH" "$final_path/custom/conf/app.ini"
|
2021-05-17 09:45:06 +02:00
|
|
|
ynh_replace_string "__DB_PWD__" "$db_pwd" "$final_path/custom/conf/app.ini"
|
|
|
|
ynh_replace_string "__DB_NAME__" "$db_name" "$final_path/custom/conf/app.ini"
|
2018-02-08 00:09:28 +01:00
|
|
|
ynh_replace_string "__DOMAIN__" "$domain" "$final_path/custom/conf/app.ini"
|
|
|
|
ynh_replace_string "__KEY__" "$key" "$final_path/custom/conf/app.ini"
|
|
|
|
ynh_replace_string "__DATA_PATH__" "$DATA_PATH" "$final_path/custom/conf/app.ini"
|
|
|
|
ynh_replace_string "__PORT__" $port "$final_path/custom/conf/app.ini"
|
2018-02-08 10:11:36 +01:00
|
|
|
ynh_replace_string "__APP__" $app "$final_path/custom/conf/app.ini"
|
2018-02-08 00:09:28 +01:00
|
|
|
|
2018-05-17 21:22:35 +02:00
|
|
|
if [[ "$is_public" = '1' ]]
|
|
|
|
then
|
|
|
|
ynh_replace_string "__PRIVATE_MODE__" "false" "$final_path/custom/conf/app.ini"
|
|
|
|
else
|
|
|
|
ynh_replace_string "__PRIVATE_MODE__" "true" "$final_path/custom/conf/app.ini"
|
|
|
|
fi
|
|
|
|
|
2021-04-23 07:57:08 +02:00
|
|
|
ynh_add_config --template="../conf/ldap.conf" --destination="$final_path/custom/conf/auth.d/ldap.conf"
|
2018-06-07 22:18:45 +02:00
|
|
|
|
2018-02-08 00:09:28 +01:00
|
|
|
ynh_store_file_checksum "$final_path/custom/conf/app.ini"
|
2018-02-07 00:31:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
set_permission() {
|
|
|
|
chown -R $app:$app "$final_path"
|
|
|
|
chown -R $app:$app "/home/$app"
|
|
|
|
chown -R $app:$app "/var/log/$app"
|
|
|
|
chmod u=rwX,g=rX,o= "$final_path"
|
|
|
|
chmod u=rwX,g=rX,o= "/home/$app"
|
|
|
|
chmod u=rwX,g=rX,o= "/var/log/$app"
|
|
|
|
}
|
2018-04-25 10:52:42 +02:00
|
|
|
|
|
|
|
set_access_settings() {
|
2021-05-17 09:45:06 +02:00
|
|
|
if [ $is_public -eq 1 ]
|
2018-04-25 10:52:42 +02:00
|
|
|
then
|
2021-05-17 09:45:06 +02:00
|
|
|
ynh_permission_update --permission="main" --add="visitors"
|
2018-04-25 10:52:42 +02:00
|
|
|
else
|
|
|
|
# For an access to the git server by https in private mode we need to allow the access to theses URL :
|
|
|
|
# - "DOMAIN/PATH/USER/REPOSITORY/info/refs"
|
|
|
|
# - "DOMAIN/PATH/USER/REPOSITORY/git-upload-pack"
|
|
|
|
# - "DOMAIN/PATH/USER/REPOSITORY/git-receive-pack"
|
|
|
|
|
|
|
|
excaped_domain=${domain//'.'/'%.'}
|
|
|
|
excaped_domain=${excaped_domain//'-'/'%-'}
|
|
|
|
excaped_path=${path_url//'.'/'%.'}
|
|
|
|
excaped_path=${excaped_path//'-'/'%-'}
|
|
|
|
ynh_app_setting_set $app skipped_regex "$excaped_domain$excaped_path/[%w-.]*/[%w-.]*/git%-receive%-pack,$excaped_domain$excaped_path/[%w-.]*/[%w-.]*/git%-upload%-pack,$excaped_domain$excaped_path/[%w-.]*/[%w-.]*/info/refs"
|
|
|
|
fi
|
|
|
|
}
|
2020-10-11 22:45:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
# Start or restart a service and follow its booting
|
|
|
|
#
|
|
|
|
# usage: ynh_check_starting "Line to match" [Log file] [Timeout] [Service name]
|
|
|
|
#
|
|
|
|
# | arg: Line to match - The line to find in the log to attest the service have finished to boot.
|
|
|
|
# | arg: Log file - The log file to watch
|
|
|
|
# | arg: Service name
|
|
|
|
# /var/log/$app/$app.log will be used if no other log is defined.
|
|
|
|
# | arg: Timeout - The maximum time to wait before ending the watching. Defaut 300 seconds.
|
|
|
|
ynh_check_starting () {
|
|
|
|
local line_to_match="$1"
|
|
|
|
local service_name="${4:-$app}"
|
|
|
|
local app_log="${2:-/var/log/$service_name/$service_name.log}"
|
|
|
|
local timeout=${3:-300}
|
2020-11-20 09:33:27 +01:00
|
|
|
}
|
2020-11-20 09:28:52 +01:00
|
|
|
|