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

208 lines
6.1 KiB
Text
Raw Normal View History

2017-02-07 22:51:47 +01:00
#!/bin/bash
2018-09-02 11:08:06 +02:00
#=================================================
# 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
2017-02-07 22:51:47 +01:00
}
2018-09-02 11:08:06 +02:00
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
2017-02-07 22:51:47 +01:00
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
2018-09-02 11:08:06 +02:00
secret=$(ynh_string_random 24)
2017-02-07 22:51:47 +01:00
script_dir=$PWD
2018-09-02 11:08:06 +02:00
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
2017-02-07 22:51:47 +01:00
2018-09-02 11:08:06 +02:00
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
2017-02-07 22:51:47 +01:00
2018-09-02 11:08:06 +02:00
domain_regex=$(echo "$domain" | sed 's@-@.@g')
2017-02-07 22:51:47 +01:00
2018-09-02 11:08:06 +02:00
# Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url)
2017-02-07 22:51:47 +01:00
2018-09-02 11:08:06 +02:00
# Check web path availability
ynh_webpath_available $domain $path_url
# Register (book) web path
ynh_webpath_register $app $domain $path_url
2017-02-07 22:51:47 +01:00
2018-09-02 11:08:06 +02:00
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2017-02-07 22:51:47 +01:00
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
2018-09-02 11:08:06 +02:00
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
2017-02-07 22:51:47 +01:00
2018-09-02 11:08:06 +02:00
#=================================================
# INSTALL DEPENDENCIES
#=================================================
2017-02-07 22:51:47 +01:00
2018-09-02 11:08:06 +02:00
ynh_install_app_dependencies build-essential cpanminus
2017-02-07 22:51:47 +01:00
2018-09-02 11:08:06 +02:00
#=================================================
# 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"
2017-02-07 22:51:47 +01:00
2018-09-02 11:08:06 +02:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2017-02-07 22:51:47 +01:00
2018-09-02 11:08:06 +02:00
# 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
2017-02-07 22:51:47 +01:00
2018-09-02 11:08:06 +02:00
#=================================================
# CREATE DEDICATED USER
#=================================================
2017-02-07 22:51:47 +01:00
2018-09-02 11:08:06 +02:00
# Create a system user
ynh_system_user_create $app
2017-02-07 22:51:47 +01:00
2018-09-02 11:08:06 +02:00
#=================================================
# Copy and fix variable into lufi config
#=================================================
2017-02-07 22:51:47 +01:00
2018-09-02 11:08:06 +02:00
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
#=================================================
2017-02-07 22:51:47 +01:00
2018-09-02 11:08:06 +02:00
sudo chown -R $app:$app "$final_path"
2017-02-07 22:51:47 +01:00
2018-09-02 11:08:06 +02:00
#=================================================
# Install Carton
2018-09-02 11:08:06 +02:00
#=================================================
2017-08-18 15:59:21 +02:00
echo yes | sudo cpanm Carton
2018-09-02 11:08:06 +02:00
#=================================================
# Install lufi via carton
2018-09-02 11:08:06 +02:00
#=================================================
2017-02-07 22:51:47 +01:00
2018-09-02 11:08:06 +02:00
mkdir -p /var/log/$app/
pushd $final_path
carton install 2>&1 | sudo tee -a "/var/log/$app/setup_carton.log"
popd
2017-02-07 22:51:47 +01:00
2018-09-02 11:08:06 +02:00
#=================================================
# STORE THE CONFIG FILE CHECKSUM
#=================================================
ynh_store_file_checksum "${final_path}/lufi.conf"
#=================================================
# SETUP SYSTEMD
#=================================================
2017-02-07 22:51:47 +01:00
2018-09-02 11:08:06 +02:00
# 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
#=================================================
2017-02-07 22:51:47 +01:00
# Making log symbolic link to /var/log
2018-09-02 11:08:06 +02:00
#=================================================
2017-02-07 22:51:47 +01:00
2018-09-02 11:08:06 +02:00
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"
2017-02-07 22:51:47 +01:00
2018-09-02 11:08:06 +02:00
#=================================================
2017-02-07 22:51:47 +01:00
# Start lufi
2018-09-02 11:08:06 +02:00
#=================================================
2018-09-02 11:08:06 +02:00
sudo systemctl start $app.service
2017-02-07 22:51:47 +01:00
2018-09-02 11:08:06 +02:00
#=================================================
# SETUP LOGROTATE
#=================================================
2017-02-07 22:51:47 +01:00
2018-09-02 11:08:06 +02:00
# 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
2018-09-02 11:08:06 +02:00
# 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
2017-02-07 22:51:47 +01:00
2018-09-02 11:08:06 +02:00
#=================================================
# RELOAD NGINX
#=================================================
systemctl reload nginx