#!/bin/bash # 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 CLEAN_SETUP () { # Clean installation residues that are not supported by the remove script. # Clean hosts echo "" } TRAP_ON # Active trap to stop the script if an error is detected. # 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 # Check variable is not empty CHECK_VAR "$app" "app name not set" CHECK_VAR "$script_dir" "script_dir not set" CHECK_USER "$admin" # Check username CHECK_PATH # Check and fix path syntax CHECK_DOMAINPATH # Check and fix domain disponibility CHECK_FINALPATH # Check final path # Check domain with regex domain_regex=$(echo "$domain" | sed 's@-@.@g') CHECK_VAR "$domain_regex" "domain_regex empty" FIND_PORT 8095 # Check port availability # Save app settings 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 # Copy files to the right place sudo mkdir "${final_path}" ynh_app_setting_set $app final_path $final_path # Get source SETUP_SOURCE # Copy it to Nginx conf directory sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf if [ "$is_public" = "Yes" ]; then sudo sed -i "s@#--PRIVATE--@@g" /etc/nginx/conf.d/$domain.d/$app.conf fi ynh_package_update ynh_package_install carton ## Copy and fix variable into lufi config 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" secret=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p') CHECK_VAR "$secret" "secret empty" sudo sed -i "s@__SECRET__@$secret@g" "${final_path}/lufi.conf" STORE_MD5_CONFIG "lufi.conf" "${final_path}/lufi.conf" # Enregistre la somme de contrôle du fichier de config # Install systemd script 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 ## Start service auto sudo systemctl enable lufi.service ## Install cron 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 # Install logrotate sed -i "s@__FINALPATH__@$final_path@g" ../conf/logrotate sudo cp ../conf/logrotate /etc/logrotate.d/$app # Install lufi via carton sudo mkdir -p /var/log/$app/ cd $final_path sudo carton install 2>&1 | sudo tee -a "/var/log/$app/setup_carton.log" # Configure le path du dossier perl en fonction de l'architecture système arch_dir=$(ls -1 $final_path/local/lib/perl5/ | grep linux-gnu) if [ "$?" -ne 0 ] then echo "Impossible de trouver le dossier relatif à l'architecture système." | sudo tee -a "/var/log/$app/setup_carton.log" false fi CHECK_VAR "$arch_dir" "arch_dir empty" sudo sed -i "s@__ARCHDIR__@$arch_dir@g" "$final_path/script/lufi" # 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" ]; then 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 # 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" # Configure owner sudo chown -R www-data: $final_path # Start lufi sudo systemctl daemon-reload sudo systemctl start lufi.service sudo systemctl enable lufi.service # 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 if [ "$is_public" = "No" ]; then # Delete public access ynh_app_setting_delete $app unprotected_uris sudo yunohost app ssowatconf fi # Reload Nginx sudo service nginx reload