2017-02-07 22:51:47 +01:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
2017-04-01 16:53:29 +02:00
|
|
|
|
# Exit on command errors and treat unset variables as an error
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
|
|
source .fonctions # Loads the generic functions usually used in the script
|
|
|
|
|
source /usr/share/yunohost/helpers # Source app helpers
|
2017-02-07 22:51:47 +01:00
|
|
|
|
|
|
|
|
|
CLEAN_SETUP () {
|
2017-04-01 16:53:29 +02:00
|
|
|
|
# Clean installation residues that are not supported by the remove script.
|
|
|
|
|
# Clean hosts
|
2017-02-07 22:51:47 +01:00
|
|
|
|
echo ""
|
|
|
|
|
}
|
2017-04-01 16:53:29 +02:00
|
|
|
|
TRAP_ON # Active trap to stop the script if an error is detected.
|
2017-02-07 22:51:47 +01:00
|
|
|
|
|
|
|
|
|
# Retrieve arguments
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
script_dir=$PWD
|
|
|
|
|
|
2017-04-03 13:02:08 +02:00
|
|
|
|
# Check variable is not empty
|
2017-02-07 22:51:47 +01:00
|
|
|
|
CHECK_VAR "$app" "app name not set"
|
|
|
|
|
CHECK_VAR "$script_dir" "script_dir not set"
|
|
|
|
|
|
2017-04-03 13:02:08 +02:00
|
|
|
|
CHECK_USER "$admin" # Check username
|
2017-02-07 22:51:47 +01:00
|
|
|
|
|
2017-04-03 13:02:08 +02:00
|
|
|
|
CHECK_PATH # Check and fix path syntax
|
|
|
|
|
CHECK_DOMAINPATH # Check and fix domain disponibility
|
2017-02-07 22:51:47 +01:00
|
|
|
|
|
2017-04-03 13:02:08 +02:00
|
|
|
|
CHECK_FINALPATH # Check final path
|
2017-02-07 22:51:47 +01:00
|
|
|
|
|
2017-04-03 13:02:08 +02:00
|
|
|
|
# Check domain with regex
|
2017-02-07 22:51:47 +01:00
|
|
|
|
domain_regex=$(echo "$domain" | sed 's@-@.@g')
|
|
|
|
|
CHECK_VAR "$domain_regex" "domain_regex empty"
|
|
|
|
|
|
2017-05-13 15:47:35 +02:00
|
|
|
|
port=$(ynh_find_port 8096) # Check port availability
|
2017-02-07 22:51:47 +01:00
|
|
|
|
|
2017-04-03 13:02:08 +02:00
|
|
|
|
# Save app settings
|
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
|
|
|
|
|
|
2017-04-03 14:04:18 +02:00
|
|
|
|
# Install build-essential
|
|
|
|
|
ynh_package_update
|
|
|
|
|
ynh_package_install build-essential
|
2017-02-07 22:51:47 +01:00
|
|
|
|
|
2017-04-03 13:02:08 +02:00
|
|
|
|
# Copy files to the right place
|
2017-04-01 16:53:29 +02:00
|
|
|
|
sudo mkdir "${final_path}"
|
2017-02-07 22:51:47 +01:00
|
|
|
|
ynh_app_setting_set $app final_path $final_path
|
|
|
|
|
|
2017-04-03 13:02:08 +02:00
|
|
|
|
# Get source
|
|
|
|
|
SETUP_SOURCE
|
2017-02-07 22:51:47 +01:00
|
|
|
|
|
2017-04-03 13:02:08 +02:00
|
|
|
|
# Copy it to Nginx conf directory
|
2017-02-07 22:51:47 +01:00
|
|
|
|
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
|
|
|
|
|
2017-04-01 16:53:29 +02:00
|
|
|
|
if [ "$is_public" = "Yes" ];
|
|
|
|
|
then
|
|
|
|
|
sudo sed -i "s@#--PRIVATE--@@g" /etc/nginx/conf.d/$domain.d/$app.conf
|
|
|
|
|
fi
|
2017-02-07 22:51:47 +01:00
|
|
|
|
|
2017-04-03 13:02:08 +02:00
|
|
|
|
## Copy and fix variable into lufi config
|
2017-04-01 16:53:29 +02:00
|
|
|
|
sudo cp ../conf/lufi.conf.template "${final_path}/lufi.conf"
|
|
|
|
|
sudo sed -i "s@__DOMAIN__@$domain@g" "${final_path}/lufi.conf"
|
|
|
|
|
sudo sed -i "s@__PATH__@$path@g" "${final_path}/lufi.conf"
|
|
|
|
|
sudo sed -i "s@__PORT__@$port@g" "${final_path}/lufi.conf"
|
2017-02-07 22:51:47 +01:00
|
|
|
|
|
2017-04-03 13:10:45 +02:00
|
|
|
|
secret=$(ynh_string_random 24)
|
2017-02-07 22:51:47 +01:00
|
|
|
|
CHECK_VAR "$secret" "secret empty"
|
2017-04-01 16:53:29 +02:00
|
|
|
|
sudo sed -i "s@__SECRET__@$secret@g" "${final_path}/lufi.conf"
|
2017-04-03 13:10:45 +02:00
|
|
|
|
STORE_MD5_CONFIG "lufi.conf" "${final_path}/lufi.conf"
|
2017-02-07 22:51:47 +01:00
|
|
|
|
|
2017-04-03 13:02:08 +02:00
|
|
|
|
# Install systemd script
|
2017-04-01 18:19:41 +02:00
|
|
|
|
sudo cp ../conf/lufi.service /etc/systemd/system/lufi.service
|
|
|
|
|
sudo chown root: /etc/systemd/system/lufi.service
|
|
|
|
|
sudo sed -i "s@__FINALPATH__@$final_path/@g" /etc/systemd/system/lufi.service
|
2017-04-03 13:02:08 +02:00
|
|
|
|
## Start service auto
|
2017-04-01 18:19:41 +02:00
|
|
|
|
sudo systemctl enable lufi.service
|
2017-02-07 22:51:47 +01:00
|
|
|
|
|
2017-04-03 13:02:08 +02:00
|
|
|
|
## Install cron
|
2017-02-07 22:51:47 +01:00
|
|
|
|
sudo cp ../conf/cron_lufi /etc/cron.d/$app
|
|
|
|
|
sudo sed -i "s@__FINALPATH__@$final_path/@g" /etc/cron.d/$app
|
|
|
|
|
sudo chmod +x $final_path/script/lufi
|
|
|
|
|
|
2017-04-03 13:02:08 +02:00
|
|
|
|
# Install logrotate
|
2017-02-07 22:51:47 +01:00
|
|
|
|
sed -i "s@__FINALPATH__@$final_path@g" ../conf/logrotate
|
|
|
|
|
sudo cp ../conf/logrotate /etc/logrotate.d/$app
|
|
|
|
|
|
2017-04-03 14:04:18 +02:00
|
|
|
|
# Install Carton
|
2017-04-19 01:53:54 +02:00
|
|
|
|
echo yes | sudo cpan Carton
|
2017-04-03 14:04:18 +02:00
|
|
|
|
|
2017-04-03 13:02:08 +02:00
|
|
|
|
# Install lufi via carton
|
2017-02-07 22:51:47 +01:00
|
|
|
|
sudo mkdir -p /var/log/$app/
|
|
|
|
|
cd $final_path
|
|
|
|
|
sudo carton install 2>&1 | sudo tee -a "/var/log/$app/setup_carton.log"
|
|
|
|
|
|
|
|
|
|
# Change variables in nginx configuration
|
|
|
|
|
sudo sed -i "s@__PATH__@$path@g" /etc/nginx/conf.d/$domain.d/$app.conf
|
|
|
|
|
sudo sed -i "s@__PORT__@$port@g" /etc/nginx/conf.d/$domain.d/$app.conf
|
|
|
|
|
|
|
|
|
|
# Make app public or private
|
|
|
|
|
ynh_app_setting_set $app skipped_uris "/"
|
|
|
|
|
if [ "$is_public" = "No" ];
|
2017-04-03 13:02:08 +02:00
|
|
|
|
then
|
2017-02-07 22:51:47 +01:00
|
|
|
|
if [ "$path" == "/" ]; then
|
2017-04-03 13:02:08 +02:00
|
|
|
|
path=""
|
2017-02-07 22:51:47 +01:00
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
# Making log symbolic link to /var/log
|
|
|
|
|
sudo touch /var/log/$app/production.log
|
|
|
|
|
sudo chown www-data: /var/log/$app/production.log
|
|
|
|
|
sudo ln -s /var/log/$app/production.log "$final_path/log/production.log"
|
|
|
|
|
|
2017-04-03 13:02:08 +02:00
|
|
|
|
# Configure owner
|
2017-02-07 22:51:47 +01:00
|
|
|
|
sudo chown -R www-data: $final_path
|
|
|
|
|
|
|
|
|
|
# Start lufi
|
2017-04-01 18:19:41 +02:00
|
|
|
|
sudo systemctl daemon-reload
|
|
|
|
|
sudo systemctl start lufi.service
|
|
|
|
|
sudo systemctl enable lufi.service
|
2017-04-01 16:53:29 +02:00
|
|
|
|
|
2017-02-07 22:51:47 +01:00
|
|
|
|
# Set right permissions on new files created at first start
|
|
|
|
|
sudo chown -R www-data: "$final_path"
|
|
|
|
|
|
|
|
|
|
# Add lufi as a service
|
|
|
|
|
sudo yunohost service add lufi -l $final_path/log/production.log
|
|
|
|
|
|
2017-04-01 16:53:29 +02:00
|
|
|
|
if [ "$is_public" = "No" ];
|
|
|
|
|
then
|
2017-04-03 13:02:08 +02:00
|
|
|
|
# Delete public access
|
2017-04-01 16:53:29 +02:00
|
|
|
|
ynh_app_setting_delete $app unprotected_uris
|
|
|
|
|
sudo yunohost app ssowatconf
|
|
|
|
|
fi
|
2017-02-07 22:51:47 +01:00
|
|
|
|
|
2017-04-03 13:02:08 +02:00
|
|
|
|
# Reload Nginx
|
2017-04-03 18:12:57 +02:00
|
|
|
|
sudo service nginx reload
|