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

187 lines
5.8 KiB
Text
Raw Normal View History

2017-02-02 19:21:27 +01:00
#!/bin/bash
2018-02-20 17:33:19 +01:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2017-04-21 12:54:39 +02:00
2018-02-20 17:33:19 +01:00
source _common.sh
source /usr/share/yunohost/helpers
2017-02-02 19:21:27 +01:00
2018-02-20 17:33:19 +01:00
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
2018-11-03 21:46:35 +01:00
ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script.
true
}
2018-02-20 17:33:19 +01:00
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
2017-02-02 19:21:27 +01:00
2018-11-03 21:46:35 +01:00
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
2017-02-02 19:21:27 +01:00
domain=$YNH_APP_ARG_DOMAIN
2018-11-03 21:48:16 +01:00
path_url=$YNH_APP_ARG_PATH
2017-02-02 19:21:27 +01:00
is_public=$YNH_APP_ARG_IS_PUBLIC
app=$YNH_APP_INSTANCE_NAME
script_dir=$PWD
2018-11-03 21:46:35 +01:00
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
2017-02-02 19:21:27 +01:00
2018-11-03 21:46:35 +01:00
### If the app uses nginx as web server (written in HTML/PHP in most cases), the final path should be "/var/www/$app".
### If the app provides an internal web server (or uses another application server such as uwsgi), the final path should be "/opt/yunohost/$app"
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
2017-02-02 19:21:27 +01:00
domain_regex=$(echo "$domain" | sed 's@-@.@g')
2018-11-03 21:46:35 +01:00
# 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
2017-02-02 19:21:27 +01:00
CHECK_VAR "$domain_regex" "domain_regex empty"
2018-11-03 21:46:35 +01:00
#=================================================
# FIND AND OPEN A PORT
#=================================================
# Find a free port
port=$(ynh_find_port 8095)
# Open this port
yunohost firewall allow --no-upnp TCP $port 2>&1
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2017-02-02 19:21:27 +01:00
ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app is_public $is_public
ynh_app_setting_set $app port $port
2018-11-03 21:46:35 +01:00
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_install_app_dependencies build-essential libssl-dev libpq-dev
# Install Carton
echo yes | sudo cpan Carton
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2017-02-02 19:21:27 +01:00
ynh_app_setting_set $app final_path $final_path
2018-11-03 21:46:35 +01:00
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
2017-02-02 19:21:27 +01:00
2018-11-03 21:46:35 +01:00
### `ynh_add_nginx_config` will use the file conf/nginx.conf
2017-02-02 19:21:27 +01:00
2018-11-03 21:46:35 +01:00
# Create a dedicated nginx config
ynh_add_nginx_config
2017-02-02 19:21:27 +01:00
2018-11-03 21:46:35 +01:00
#=================================================
# CREATE DEDICATED USER
#=================================================
2017-02-02 19:21:27 +01:00
2018-11-03 21:46:35 +01:00
# Create a system user
ynh_system_user_create $app
#=================================================
2017-04-21 12:54:39 +02:00
## Copy and fix variable into lstu config
2018-11-03 21:46:35 +01:00
#=================================================
2017-02-02 19:21:27 +01:00
2018-11-03 21:46:35 +01:00
cp ../conf/lstu.conf.template "${final_path}/lstu.conf"
ynh_replace_string "__DOMAIN__" "$domain" "${final_path}/lstu.conf"
ynh_replace_string "__PATH__" "$path_url" "${final_path}/lstu.conf"
ynh_replace_string "__PORT__" "$port" "${final_path}/lstu.conf"
2017-02-02 19:21:27 +01:00
2018-11-03 21:46:35 +01:00
secret=$(ynh_string_random 24)
ynh_replace_string "__SECRET__" "$secret" "${final_path}/lstu.conf"
ynh_store_file_checksum "${final_path}/lstu.conf"
2017-02-02 20:04:10 +01:00
2018-11-03 21:46:35 +01:00
#=================================================
# SETUP SYSTEMD
#=================================================
2017-02-02 19:21:27 +01:00
2018-11-03 21:46:35 +01:00
# Create a dedicated systemd config
ynh_add_systemd_config
2017-02-02 19:21:27 +01:00
2018-11-03 21:46:35 +01:00
#=================================================
2017-04-21 12:54:39 +02:00
# Install lstu's dependencies via carton
2018-11-03 21:46:35 +01:00
#=================================================
carton install 2>&1 | sudo tee -a "/var/log/$app/setup_carton.log"
#=================================================
# SETUP LOGROTATE
#=================================================
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
yunohost service add $app --log "/var/log/$app.log"
2017-02-02 19:21:27 +01:00
2018-11-03 21:46:35 +01:00
#=================================================
# SETUP SSOWAT
#=================================================
2017-02-02 19:21:27 +01:00
# Make app public or private
ynh_app_setting_set $app skipped_uris "/"
2017-04-21 12:54:39 +02:00
if [ $is_public -eq 0 ];
then # If the app is private, only the shortened URLs are publics
2017-02-02 19:21:27 +01:00
if [ "$path" == "/" ]; then
2017-04-21 12:54:39 +02:00
path=""
2017-02-02 19:21:27 +01:00
fi
2018-11-03 21:48:16 +01:00
ynh_app_setting_set $app protected_regex "$domain_regex$path_url/login$","$domain_regex$path_url/logout$","$domain_regex$path_url/api$","$domain_regex$path_url/extensions$","$domain_regex$path_url/stats$","$domain_regex$path_url/d/.*$","$domain_regex$path_url/a$","$domain_regex$path_url/$"
2018-11-03 21:46:35 +01:00
else
ynh_replace_string "#--PRIVATE--" "" "/etc/nginx/conf.d/$domain.d/$app.conf"
2017-02-02 19:21:27 +01:00
fi
2018-11-03 21:46:35 +01:00
#=================================================
2017-02-02 19:21:27 +01:00
# Making log symbolic link to /var/log
2018-11-03 21:46:35 +01:00
#=================================================
touch /var/log/$app/production.log
chown $app:$app /var/log/$app/production.log
ln -s /var/log/$app/production.log "$final_path/log/production.log"
2017-02-02 19:21:27 +01:00
2018-11-03 21:46:35 +01:00
#=================================================
2017-04-21 12:54:39 +02:00
# Configure owner
2018-11-03 21:46:35 +01:00
#=================================================
2017-02-02 19:21:27 +01:00
2018-11-03 21:46:35 +01:00
sudo chown -R $app:$app $final_path
2017-04-21 12:54:39 +02:00
2018-11-03 21:46:35 +01:00
#=================================================
# Start lstu
#=================================================
2017-02-02 19:21:27 +01:00
2018-11-03 21:46:35 +01:00
systemctl enable lstu.service
systemctl start lstu.service
2017-02-02 19:21:27 +01:00
2018-11-03 21:46:35 +01:00
#=================================================
# RELOAD NGINX
#=================================================
2017-02-02 19:21:27 +01:00
2017-04-21 12:54:39 +02:00
# Reload Nginx
2017-02-02 19:21:27 +01:00
sudo service nginx reload