1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/timeoff_ynh.git synced 2024-09-03 20:35:59 +02:00
timeoff_ynh/scripts/install

206 lines
6.6 KiB
Text
Raw Normal View History

2018-04-03 19:00:18 +02:00
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE FAILURE OF THE SCRIPT
#=================================================
ynh_abort_if_errors # Active trap pour arrêter le script si une erreur est détectée.
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
domain=$YNH_APP_ARG_DOMAIN
2021-08-31 07:49:17 +02:00
path_url="/"
2021-08-30 23:49:05 +02:00
language=$YNH_APP_ARG_LANGUAGE
2021-08-31 08:14:43 +02:00
is_public=$YNH_APP_ARG_IS_PUBLIC
2018-04-03 19:00:18 +02:00
app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
#=================================================
2021-08-30 23:12:28 +02:00
ynh_script_progression --message="Validating installation parameters..."
2018-04-03 19:00:18 +02:00
2021-08-30 23:12:28 +02:00
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
2018-04-03 19:00:18 +02:00
# Register (book) web path
2021-08-30 23:12:28 +02:00
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
2018-04-03 19:00:18 +02:00
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2021-08-30 23:30:41 +02:00
ynh_script_progression --message="Storing installation settings..."
2018-04-03 19:00:18 +02:00
2021-08-30 23:30:41 +02:00
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
2021-08-30 23:49:05 +02:00
ynh_app_setting_set --app=$app --key=language --value=$language
2018-04-03 19:00:18 +02:00
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
2021-08-30 23:30:41 +02:00
ynh_script_progression --message="Finding an available port..."
2018-04-03 19:00:18 +02:00
2021-08-30 23:30:41 +02:00
# Find an available port
2022-02-09 17:56:47 +01:00
port=$(ynh_find_port --port=3000)
2021-08-30 23:30:41 +02:00
ynh_app_setting_set --app=$app --key=port --value=$port
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
# INSTALL DEPENDENCIES
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
ynh_script_progression --message="Installing dependencies..."
2018-04-03 19:00:18 +02:00
2021-08-31 14:19:24 +02:00
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..."
2021-08-30 23:30:41 +02:00
# Install Nodejs
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
# CREATE DEDICATED USER
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
ynh_script_progression --message="Configuring system user..."
2018-04-03 19:00:18 +02:00
2021-08-30 23:30:41 +02:00
# Create a system user
ynh_system_user_create --username=$app --home_dir="$final_path"
2018-04-03 19:00:18 +02:00
2021-08-30 23:49:05 +02:00
#=================================================
# CREATE A MYSQL DATABASE
#=================================================
2021-08-31 14:19:24 +02:00
# ynh_script_progression --message="Creating a MySQL database..."
2021-08-30 23:49:05 +02:00
2021-08-31 14:19:24 +02: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
2021-08-30 23:49:05 +02:00
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
# DOWNLOAD, CHECK AND UNPACK SOURCE
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
ynh_script_progression --message="Setting up source files..."
2018-04-03 19:00:18 +02:00
2021-08-30 23:30:41 +02:00
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir=$final_path
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
2021-08-31 15:00:39 +02:00
#chmod -R +x "$final_path/bin"
2018-04-03 19:00:18 +02:00
2021-11-29 22:05:09 +01:00
#=================================================
# CREATE DATA DIRECTORY
#=================================================
ynh_script_progression --message="Creating a data directory..." --weight=1
datadir=/home/yunohost.app/$app
ynh_app_setting_set --app=$app --key=datadir --value=$datadir
mkdir -p $datadir
chmod 750 "$datadir"
chmod -R o-rwx "$datadir"
chown -R $app:www-data "$datadir"
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
# NGINX CONFIGURATION
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
ynh_script_progression --message="Configuring NGINX web server..."
2018-04-03 19:00:18 +02:00
2021-08-30 23:30:41 +02:00
# Create a dedicated NGINX config
ynh_add_nginx_config
2018-04-03 19:00:18 +02:00
#=================================================
# SPECIFIC SETUP
#=================================================
# HANDLE LOG FILES AND LOGROTATE
#=================================================
# Create log directory
mkdir -p /var/log/$app
chown $app -R /var/log/$app
# Setup logrotate
ynh_use_logrotate
#=================================================
# INSTALL
#=================================================
2021-08-31 12:21:08 +02:00
ynh_script_progression --message="Installing TimeOff..."
2018-04-03 19:00:18 +02:00
2021-08-30 23:30:41 +02:00
pushd $final_path
ynh_use_nodejs
2022-02-09 17:58:00 +01:00
ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm install
2021-08-30 23:30:41 +02:00
popd
2018-04-03 19:00:18 +02:00
#=================================================
# CONFIGURE
#=================================================
2021-08-30 23:30:41 +02:00
ynh_script_progression --message="Modifying a config file..."
2018-04-03 19:00:18 +02:00
2021-08-30 23:30:41 +02:00
ynh_add_config --template="../conf/app.json" --destination="$final_path/config/app.json"
ynh_add_config --template="../conf/db.json" --destination="$final_path/config/db.json"
2018-04-03 19:00:18 +02:00
2021-08-30 23:30:41 +02:00
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..."
2018-04-03 19:00:18 +02:00
2022-02-09 17:56:47 +01:00
env_path="$PATH"
2021-08-30 23:30:41 +02:00
ynh_add_systemd_config
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
# INTEGRATE SERVICE IN YUNOHOST
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
ynh_script_progression --message="Integrating service in YunoHost..."
2018-04-03 19:00:18 +02:00
2021-08-30 23:30:41 +02:00
yunohost service add $app --description="Manage employee absences" --log="/var/log/$app/$app.log"
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
# START SYSTEMD SERVICE
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
ynh_script_progression --message="Starting a systemd service..."
2018-04-03 19:00:18 +02:00
2021-08-30 23:30:41 +02:00
# Start a systemd service
ynh_systemd_action --service_name=$app --action=start --log_path=systemd
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
# SETUP SSOWAT
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
ynh_script_progression --message="Configuring permissions..."
2018-04-03 19:00:18 +02:00
2021-08-30 23:30:41 +02:00
# Make app public if necessary
if [ $is_public -eq 1 ]
then
ynh_permission_update --permission="main" --add="visitors"
fi
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
# RELOAD NGINX
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
ynh_script_progression --message="Reloading NGINX web server..."
2018-04-03 19:00:18 +02:00
2021-08-30 23:30:41 +02:00
ynh_systemd_action --service_name=nginx --action=reload
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
# END OF SCRIPT
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
ynh_script_progression --message="Installation of $app completed"