mirror of
https://github.com/YunoHost-Apps/lufi_ynh.git
synced 2024-09-03 19:36:28 +02:00
207 lines
6.1 KiB
Bash
207 lines
6.1 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# MANAGE SCRIPT FAILURE
|
|
#=================================================
|
|
|
|
ynh_clean_setup () {
|
|
### Remove this function if there's nothing to clean before calling the remove script.
|
|
true
|
|
}
|
|
# 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=$YNH_APP_ARG_PATH
|
|
admin=$YNH_APP_ARG_ADMIN
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
secret=$(ynh_string_random 24)
|
|
|
|
script_dir=$PWD
|
|
|
|
#=================================================
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
#=================================================
|
|
|
|
final_path=/var/www/$app
|
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
|
|
|
domain_regex=$(echo "$domain" | sed 's@-@.@g')
|
|
|
|
# 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 admin $admin
|
|
ynh_app_setting_set $app domain $domain
|
|
ynh_app_setting_set $app is_public $is_public
|
|
ynh_app_setting_set $app port $port
|
|
ynh_app_setting_set $app secret $secret
|
|
|
|
#=================================================
|
|
# STANDARD MODIFICATIONS
|
|
#=================================================
|
|
# FIND AND OPEN A PORT
|
|
#=================================================
|
|
|
|
# Find a free port
|
|
port=$(ynh_find_port 8096)
|
|
# Open this port
|
|
yunohost firewall allow --no-upnp TCP $port 2>&1
|
|
ynh_app_setting_set $app port $port
|
|
|
|
#=================================================
|
|
# INSTALL DEPENDENCIES
|
|
#=================================================
|
|
|
|
ynh_install_app_dependencies build-essential cpanminus
|
|
|
|
#=================================================
|
|
# 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"
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
|
|
# Create a dedicated nginx config
|
|
ynh_add_nginx_config
|
|
if [ "$is_public" = true ];
|
|
then
|
|
sudo sed -i "s@#--PRIVATE--@@g" /etc/nginx/conf.d/$domain.d/$app.conf
|
|
fi
|
|
|
|
#=================================================
|
|
# CREATE DEDICATED USER
|
|
#=================================================
|
|
|
|
# Create a system user
|
|
ynh_system_user_create $app
|
|
|
|
#=================================================
|
|
# Copy and fix variable into lufi config
|
|
#=================================================
|
|
|
|
sudo cp ../conf/lufi.conf.template "${final_path}/lufi.conf"
|
|
ynh_replace_string "__DOMAIN__" "$domain" "${final_path}/lufi.conf"
|
|
ynh_replace_string "__PATH__" "$path" "${final_path}/lufi.conf"
|
|
ynh_replace_string "__PORT__" "$port" "${final_path}/lufi.conf"
|
|
ynh_replace_string "__SECRET__" "$secret" "${final_path}/lufi.conf"
|
|
|
|
#=================================================
|
|
# Set right permissions on new files created at first start
|
|
#=================================================
|
|
|
|
sudo chown -R $app:$app "$final_path"
|
|
|
|
#=================================================
|
|
# Install Carton
|
|
#=================================================
|
|
|
|
echo yes | sudo cpanm Carton
|
|
|
|
#=================================================
|
|
# Install lufi via carton
|
|
#=================================================
|
|
|
|
mkdir -p /var/log/$app/
|
|
pushd $final_path
|
|
carton install 2>&1 | sudo tee -a "/var/log/$app/setup_carton.log"
|
|
popd
|
|
|
|
#=================================================
|
|
# STORE THE CONFIG FILE CHECKSUM
|
|
#=================================================
|
|
|
|
ynh_store_file_checksum "${final_path}/lufi.conf"
|
|
|
|
#=================================================
|
|
# SETUP SYSTEMD
|
|
#=================================================
|
|
|
|
# Create a dedicated systemd config
|
|
ynh_add_systemd_config
|
|
|
|
#=================================================
|
|
## Install cron
|
|
#=================================================
|
|
|
|
cp ../conf/cron_lufi /etc/cron.d/$app
|
|
ynh_replace_string "__FINALPATH__" "$final_path/" "/etc/cron.d/$app"
|
|
chmod +x $final_path/script/lufi
|
|
|
|
#=================================================
|
|
# Making log symbolic link to /var/log
|
|
#=================================================
|
|
|
|
touch /var/log/$app/production.log
|
|
chown www-data: /var/log/$app/production.log
|
|
ln -s /var/log/$app/production.log "$final_path/log/production.log"
|
|
|
|
#=================================================
|
|
# Start lufi
|
|
#=================================================
|
|
|
|
sudo systemctl start $app.service
|
|
|
|
#=================================================
|
|
# SETUP LOGROTATE
|
|
#=================================================
|
|
|
|
# Use logrotate to manage application logfile(s)
|
|
ynh_use_logrotate
|
|
|
|
#=================================================
|
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
|
#=================================================
|
|
|
|
yunohost service add NAME_INIT.D --log "/var/log/FILE.log"
|
|
|
|
#=================================================
|
|
# SETUP SSOWAT
|
|
#=================================================
|
|
|
|
# Make app public if necessary
|
|
if [ $is_public -eq 1 ]
|
|
then
|
|
# unprotected_uris allows SSO credentials to be passed anyway.
|
|
ynh_app_setting_set $app unprotected_uris "/"
|
|
else
|
|
if [ "$path" == "/" ]; then
|
|
path=""
|
|
fi
|
|
ynh_app_setting_set $app protected_regex "$domain_regex$path/stats$","$domain_regex$path/manifest.webapp$","$domain_regex$path/$","$domain_regex$path/d/.*$","$domain_regex$path/m/.*$"
|
|
fi
|
|
|
|
#=================================================
|
|
# RELOAD NGINX
|
|
#=================================================
|
|
|
|
systemctl reload nginx
|