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

164 lines
5 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
# Load common variables for all scripts.
source _variables
#=================================================
# MANAGE FAILURE OF THE SCRIPT
#=================================================
ynh_clean_setup () {
# Nettoyage des résidus d'installation non pris en charge par le script remove.
ynh_clean_check_starting
}
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
#=================================================
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
# Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url)
# Check web path availability
ynh_webpath_available $domain $path_url
# Register (book) web path
ynh_webpath_register $app $domain $path_url
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app path $path_url
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
port=$(ynh_find_port 9001) # Look for an available port
ynh_app_setting_set $app port $port
#=================================================
# INSTALL NODEJS
#=================================================
ynh_install_nodejs $nodejs_version
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_app_setting_set $app final_path $final_path
ynh_setup_source "$final_path" # Download, check integrity and uncompress the source from app.src
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_replace_string "__PATH__/" "${path_url%/}/" "../conf/nginx.conf"
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_system_user_create $app $final_path
#=================================================
# 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
#=================================================
# Install dependencies and proceed with the installation
nodedir=$(ynh_get_nodejs_bindir $nodejs_version)
(cd $final_path && PATH=$nodedir:$PATH npm install --production > $install_log 2>&1)
2018-04-03 19:00:18 +02:00
#=================================================
# CONFIGURE
#=================================================
cp ../conf/app.json "$final_path/config/app.json"
ynh_replace_string "__DOMAIN__" "$domain" "$final_path/config/app.json"
cp ../conf/db.json "$final_path/config/db.json"
ynh_store_file_checksum "$final_path/config/app.json"
ynh_store_file_checksum "$final_path/config/db.json"
#=================================================
# SECURING FILES AND DIRECTORIES
#=================================================
# Set files ownership to etherpad
chown -R $app: $final_path
chmod 600 "$final_path/config/db.json" # Restrict access to db.json
#=================================================
# SETUP SYSTEMD
#=================================================
#ynh_replace_string "__NODEJS__" "$nodejs_use_version" "../conf/systemd.service"
ynh_replace_string "__NODE_DIR__" "$nodedir" "../conf/systemd.service"
2018-04-03 19:00:18 +02:00
ynh_replace_string "__PORT__" "$port" "../conf/systemd.service"
ynh_replace_string "__FINAL_PATH__" "$final_path" "../conf/systemd.service"
ynh_add_systemd_config
#=================================================
# ENABLE SERVICE IN ADMIN PANEL
#=================================================
systemctl start $app.service
2018-04-03 19:00:18 +02:00
# Add service to YunoHost monitoring panel
yunohost service add $app
#=================================================
# SETUP FAIL2BAN
#=================================================
#ynh_add_fail2ban_config "/var/log/nginx/$domain-access.log" "<HOST> .* \"POST /mypads/api/auth/login HTTP/1.1\" 400" 5
#=================================================
# RELOAD NGINX
#=================================================
systemctl reload nginx