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

177 lines
5.7 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
path_url=$YNH_APP_ARG_PATH
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
config_path=/home/yunohost.app/$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
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
port=$(ynh_find_port 9001)
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-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: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"
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
touch /var/log/$app/installation.log
install_log=/var/log/$app/installation.log
touch $install_log
chown $app -R /var/log/$app
# Setup logrotate
ynh_use_logrotate
#=================================================
# INSTALL
#=================================================
2021-08-30 23:30:41 +02:00
ynh_script_progression --message="Installing The Lounge..."
2018-04-03 19:00:18 +02:00
2021-08-30 23:30:41 +02:00
pushd $final_path
ynh_use_nodejs
ynh_exec_warn_less NODE_ENV=production npm install --production > $install_log 2>&1
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
2021-08-30 23:30:41 +02:00
ynh_replace_string --match_string="__ENV_PATH__" --replace_string="$PATH" --target_file="../conf/systemd.service"
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"