75 lines
2.5 KiB
Bash
75 lines
2.5 KiB
Bash
#!/bin/bash
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
#=================================================
|
|
# CHECK IF RESTARTABLE SERVICES EXIST
|
|
#=================================================
|
|
ynh_script_progression --message="Checking installed apps: minidlna …" --weight=1
|
|
|
|
if ! yunohost app list | grep "id: minidlna" >/dev/null 2>&1 ; then
|
|
ynh_die --message="No restartable app found. aborting installation" --ret-code="1"
|
|
fi
|
|
|
|
|
|
#=================================================
|
|
# INSTALL FILES
|
|
#=================================================
|
|
ynh_script_progression --message="Setting up source files…" --weight=1
|
|
|
|
ynh_add_config --template="index.html" --destination="$install_dir/index.html"
|
|
ynh_add_config --template="restarter.php" --destination="$install_dir/$app.php"
|
|
|
|
chown -R www-data:www-data "$install_dir"
|
|
chmod -R 640 "$install_dir"
|
|
chmod 750 "$install_dir"
|
|
|
|
|
|
#=================================================
|
|
# SUDOERS CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Adding sudoers configuration …" --weight=1
|
|
|
|
ynh_add_config --template="sudoer" --destination="/etc/sudoers.d/$app"
|
|
chown root:root "/etc/sudoers.d/$app"
|
|
chmod 600 "/etc/sudoers.d/$app"
|
|
|
|
#=================================================
|
|
# WEBSERVER CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Adding php-fpm configuration …" --weight=1
|
|
|
|
# find default php version
|
|
php_executable=$(readlink -f "$(which php)")
|
|
echo "${php_executable:(-3)}"
|
|
#ynh_app_setting_set --app=$app --key="phpversion" --value="${php_executable:(-3)}"
|
|
ynh_add_fpm_config --phpversion="${php_executable:(-3)}"
|
|
|
|
|
|
ynh_script_progression --message="Adding nginx configuration …" --weight=1
|
|
# get local subnet address ranges from routing table
|
|
ranges=$(netstat -nr | grep -o "^\(192\.168\|172.\(1[6-9]\|2[0-9]\|3[01]\)\|10\.[0-9]\+\)\.[0-9]\+\.[0-9]\+")
|
|
# add allow statement to nginx config for each subnet range in CIDR notation
|
|
for range in $ranges; do
|
|
case $(echo "$range" | awk -F '.' '{print $1}') in
|
|
192)
|
|
cidr=24
|
|
;;
|
|
172)
|
|
cidr=12
|
|
;;
|
|
10)
|
|
cidr=8
|
|
;;
|
|
esac
|
|
sed -i "/# allowed subnets/a allow ${range}/${cidr}; # added by install script" conf/nginx.conf
|
|
done
|
|
ynh_add_nginx_config
|
|
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
ynh_script_progression --message="Installation of $app completed" --last
|