2016-08-15 15:38:50 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2018-02-08 17:25:54 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
2018-02-07 00:31:25 +01:00
|
|
|
# IMPORT GENERIC HELPERS
|
2020-11-18 17:59:20 +01:00
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
2018-02-07 00:31:25 +01:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2020-11-18 17:59:20 +01:00
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
2018-02-07 00:31:25 +01:00
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
2020-11-18 17:59:20 +01:00
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
2016-08-15 15:38:50 +02:00
|
|
|
|
|
|
|
# Retrieve arguments
|
2017-04-05 21:06:22 +02:00
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
2020-11-20 09:20:50 +01:00
|
|
|
path_url=$YNH_APP_ARG_PATH
|
2017-04-05 21:06:22 +02:00
|
|
|
admin=$YNH_APP_ARG_ADMIN
|
2018-02-07 23:49:32 +01:00
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
2021-11-21 21:38:18 +01:00
|
|
|
architecture=$YNH_ARCH
|
2021-11-07 12:30:23 +01:00
|
|
|
key=$(ynh_string_random)
|
2016-08-15 15:38:50 +02:00
|
|
|
|
2020-11-18 17:59:20 +01:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2020-11-20 09:20:50 +01:00
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Validating installation parameters..." --weight=1
|
2020-11-18 17:59:20 +01:00
|
|
|
|
2020-11-20 09:56:25 +01:00
|
|
|
final_path=/var/www/$app
|
2020-11-20 09:20:50 +01:00
|
|
|
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
|
|
|
|
|
|
|
# Register (book) web path
|
|
|
|
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
2016-08-15 15:38:50 +02:00
|
|
|
|
2020-11-20 09:20:50 +01:00
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Storing installation settings..." --weight=1
|
|
|
|
|
2020-11-20 09:56:25 +01:00
|
|
|
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
2021-11-06 23:42:14 +01:00
|
|
|
ynh_app_setting_set --app=$app --key=admin --value=$admin
|
2020-11-20 09:56:25 +01:00
|
|
|
ynh_app_setting_set --app=$app --key=path --value=$path_url
|
2021-11-21 21:38:18 +01:00
|
|
|
ynh_app_setting_set --app=$app --key=key --value=$key
|
2016-08-15 15:38:50 +02:00
|
|
|
|
2018-02-08 17:25:54 +01:00
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
2020-11-20 09:20:50 +01:00
|
|
|
# FIND AND OPEN A PORT
|
|
|
|
#=================================================
|
2021-08-14 23:09:55 +02:00
|
|
|
ynh_script_progression --message="Finding an available port..." --weight=1
|
2020-11-20 09:20:50 +01:00
|
|
|
|
|
|
|
# Find an available port
|
|
|
|
port=$(ynh_find_port --port=6000)
|
|
|
|
ynh_app_setting_set --app=$app --key=port --value=$port
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE A MYSQL DATABASE
|
|
|
|
#=================================================
|
2020-12-06 15:08:51 +01:00
|
|
|
ynh_script_progression --message="Creating a MySQL database..." --weight=3
|
2018-02-08 17:25:54 +01:00
|
|
|
|
2020-11-20 09:20:50 +01:00
|
|
|
db_name=$(ynh_sanitize_dbid --db_name=$app)
|
|
|
|
db_user=$db_name
|
|
|
|
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
|
|
|
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
|
|
|
|
|
2020-11-20 11:06:54 +01:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring system user..." --weight=1
|
|
|
|
|
|
|
|
# Create a system user
|
|
|
|
ynh_system_user_create --username=$app --home_dir=$final_path
|
|
|
|
|
2020-11-20 09:56:25 +01:00
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Setting up source files..." --weight=3
|
|
|
|
|
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2020-11-20 10:09:41 +01:00
|
|
|
ynh_setup_source --dest_dir=$final_path --source_id="$architecture"
|
2020-11-20 09:56:25 +01:00
|
|
|
|
2021-08-14 23:15:18 +02:00
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
|
|
|
chown -R $app:www-data "$final_path"
|
|
|
|
|
2020-11-20 09:20:50 +01:00
|
|
|
#=================================================
|
2021-11-06 19:10:24 +01:00
|
|
|
# CREATE DATA DIRECTORY
|
2020-11-20 09:20:50 +01:00
|
|
|
#=================================================
|
2021-11-06 19:10:24 +01:00
|
|
|
ynh_script_progression --message="Creating a data directory..." --weight=1
|
2018-02-08 17:25:54 +01:00
|
|
|
|
2021-11-06 19:10:24 +01:00
|
|
|
datadir=/home/yunohost.app/$app
|
|
|
|
ynh_app_setting_set --app=$app --key=datadir --value=$datadir
|
2018-02-07 00:31:25 +01:00
|
|
|
|
2021-11-06 19:10:24 +01:00
|
|
|
mkdir -p $datadir
|
|
|
|
|
2016-08-15 15:38:50 +02:00
|
|
|
# create needed directories
|
2020-11-18 17:59:20 +01:00
|
|
|
mkdir -p "$final_path/custom/conf/auth.d"
|
2021-11-26 16:50:13 +01:00
|
|
|
mkdir -p "$datadir/data/repositories"
|
2021-11-07 15:44:01 +01:00
|
|
|
mkdir -p "$datadir/data/avatars"
|
|
|
|
mkdir -p "$datadir/data/attachments"
|
2020-11-18 17:59:20 +01:00
|
|
|
|
2021-11-26 16:46:39 +01:00
|
|
|
chmod 750 "$datadir"
|
|
|
|
chmod -R o-rwx "$datadir"
|
|
|
|
chown -R $app:www-data "$datadir"
|
|
|
|
|
2020-11-18 17:59:20 +01:00
|
|
|
#=================================================
|
|
|
|
# MODIFY A CONFIG FILE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
if [ "$path_url" = "/" ]
|
|
|
|
then
|
2021-11-07 15:44:13 +01:00
|
|
|
url="$domain"
|
2020-11-18 17:59:20 +01:00
|
|
|
else
|
2021-11-08 21:48:50 +01:00
|
|
|
url="$domain${path_url%/}"
|
2020-11-18 17:59:20 +01:00
|
|
|
fi
|
|
|
|
|
2021-11-07 15:44:13 +01:00
|
|
|
ynh_add_config --template="../conf/app.ini" --destination="$final_path/custom/conf/app.ini"
|
|
|
|
|
|
|
|
chmod 400 "$final_path/custom/conf/app.ini"
|
|
|
|
chown $app:$app "$final_path/custom/conf/app.ini"
|
|
|
|
|
2021-04-23 07:57:08 +02:00
|
|
|
ynh_add_config --template="../conf/ldap.conf" --destination="$final_path/custom/conf/auth.d/ldap.conf"
|
2020-11-18 17:59:20 +01:00
|
|
|
|
2016-08-15 15:38:50 +02:00
|
|
|
# Configure init script
|
2018-02-07 00:31:25 +01:00
|
|
|
ynh_add_systemd_config
|
|
|
|
|
2020-11-18 17:59:20 +01:00
|
|
|
#=================================================
|
2020-11-20 09:20:50 +01:00
|
|
|
# NGINX CONFIGURATION
|
2020-11-18 17:59:20 +01:00
|
|
|
#=================================================
|
2020-12-06 15:08:51 +01:00
|
|
|
ynh_script_progression --message="Configuring NGINX web server..." --weight=2
|
2020-11-20 09:20:50 +01:00
|
|
|
|
2020-12-06 14:56:01 +01:00
|
|
|
# Create a dedicated NGINX config
|
2020-11-20 09:20:50 +01:00
|
|
|
ynh_add_nginx_config
|
2016-08-15 15:38:50 +02:00
|
|
|
|
2018-02-08 17:25:54 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
2021-11-06 19:10:24 +01:00
|
|
|
# SETUP LOGROTATE
|
2020-11-18 17:59:20 +01:00
|
|
|
#=================================================
|
2021-11-06 19:10:24 +01:00
|
|
|
ynh_script_progression --message="Configuring log rotation..." --weight=1
|
2020-11-18 17:59:20 +01:00
|
|
|
|
2021-11-06 19:10:24 +01:00
|
|
|
# Use logrotate to manage application logfile(s)
|
|
|
|
ynh_use_logrotate
|
2018-02-08 17:25:54 +01:00
|
|
|
|
2021-11-07 08:47:53 +01:00
|
|
|
chown -R $app:$app "/var/log/$app"
|
|
|
|
chmod u=rwX,g=rX,o= "/var/log/$app"
|
|
|
|
|
2020-11-18 17:59:20 +01:00
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
|
|
|
|
2020-12-06 14:47:29 +01:00
|
|
|
yunohost service add $app --description="Lightweight Git forge" --log="/var/log/$app/$app.log"
|
2018-02-07 00:31:25 +01:00
|
|
|
|
2020-11-18 17:59:20 +01:00
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2020-12-06 15:08:51 +01:00
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=3
|
2020-11-18 17:59:20 +01:00
|
|
|
|
2020-11-20 09:20:50 +01:00
|
|
|
# Start a systemd service
|
2021-11-07 10:35:21 +01:00
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd"
|
2020-11-20 09:20:50 +01:00
|
|
|
|
2020-12-06 14:40:38 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2021-11-07 10:32:50 +01:00
|
|
|
ynh_script_progression --message="Configuring permissions..." --weight=1
|
2021-05-17 09:45:06 +02:00
|
|
|
|
2021-11-06 23:42:14 +01:00
|
|
|
# Make app public if necessary or protect it
|
|
|
|
if [ $is_public -eq 1 ]
|
|
|
|
then
|
|
|
|
ynh_permission_update --permission="main" --add="visitors"
|
|
|
|
fi
|
2020-12-06 14:40:38 +01:00
|
|
|
|
2020-11-20 09:20:50 +01:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2020-12-06 14:12:04 +01:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
2020-11-20 09:20:50 +01:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
2020-11-18 17:59:20 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|