1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/linuxdash_ynh.git synced 2024-09-03 19:36:07 +02:00
linuxdash_ynh/scripts/install

142 lines
4.2 KiB
Text
Raw Normal View History

2014-06-02 13:38:03 +02:00
#!/bin/bash
2018-01-29 00:55:27 +01:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2016-02-03 12:59:58 +01:00
2018-01-29 00:55:27 +01:00
source _common.sh
source /usr/share/yunohost/helpers
2014-06-02 13:38:03 +02:00
2018-01-29 00:55:27 +01:00
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
2014-06-02 13:38:03 +02:00
2018-01-29 00:55:27 +01:00
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
user=$YNH_APP_ARG_USER
app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
2016-02-03 16:41:20 +01:00
2016-02-03 12:59:58 +01:00
final_path=/var/www/$app
2018-01-29 00:55:27 +01:00
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
ynh_app_setting_set $app user $user
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_install_app_dependencies supervisor
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_app_setting_set $app final_path $final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
#=================================================
# FIND AND OPEN A PORT
#=================================================
# Find a free port
port=$(ynh_find_port 8081)
# Open this port
yunohost firewall allow --no-upnp TCP $port 2>&1
ynh_app_setting_set $app port $port
2014-06-02 13:38:03 +02:00
2018-01-29 00:55:27 +01:00
# For v2.0 only
# ynh_replace_string "default=80" "default=$port" "$final_path/app/server/index.py"
ynh_replace_string "'localhost', 8081" "'localhost', $port" "$final_path/python-server.py"
#=================================================
# NGINX CONFIGURATION
#=================================================
# Create a dedicated nginx config
if [ "$path_url" != "/" ]
then
ynh_replace_string "^#sub_path_only" "" "../conf/nginx.conf"
fi
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
# Create a system user
ynh_system_user_create $app
#=================================================
# SPECIFIC SETUP
#=================================================
# SET SUPERVISOR
#=================================================
2014-06-02 13:38:03 +02:00
# Set as a service with supervisor
2018-01-29 00:55:27 +01:00
cp ../conf/supervisor.conf /etc/supervisor/conf.d/$app.conf
ynh_replace_string "__APP__" "$app" "/etc/supervisor/conf.d/$app.conf"
ynh_replace_string "__FINALPATH__" "$final_path" "/etc/supervisor/conf.d/$app.conf"
ynh_replace_string "__USER__" "$app" "/etc/supervisor/conf.d/$app.conf"
supervisorctl update
supervisorctl restart $app
#=================================================
# REMOVE GOOGLE !!!
#=================================================
sed --in-place "/googlecode\|googleapis/d" "$final_path/index.html"
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions to app files
chown -R root: $final_path
#=================================================
# SETUP SSOWAT
#=================================================
# Restrict access to admin only
yunohost app addaccess --users=$user $app
#=================================================
# RELOAD NGINX
#=================================================
systemctl reload nginx