1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/zap_ynh.git synced 2024-09-03 20:36:07 +02:00
zap_ynh/scripts/install
2024-01-24 13:16:16 +01:00

114 lines
3.3 KiB
Bash
Executable file

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
email=$(ynh_user_get_info --username=$admin --key=mail)
random_string=$(ynh_string_random --length=48)
timezone=$(cat /etc/timezone)
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_print_info "Storing installation settings..."
ynh_app_setting_set --app=$app --key=random_string --value=$random_string
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up Zap source files..."
ynh_setup_source --dest_dir="$install_dir"
# Make addon Directory and unpack the addons to this directory
ynh_script_progression --message="Setting up Zap addons source files..."
pushd "$install_dir"
mkdir -p extend/addon/zaddons
mkdir addon
ynh_setup_source --dest_dir="$install_dir/extend/addon/zaddons" --source_id="app_addons"
filelist=(`ls extend/addon/zaddons`)
cd addon
for a in "${filelist[@]}" ; do
base=`basename $a`
if [ $base = '.git' ]; then
#echo 'ignoring git'
continue;
fi
if [ ! -d ../extend/addon/zaddons/$base ]; then
#echo $a 'not a directory'
continue;
fi
if [ -x $base ]; then
#echo $base 'file exists'
continue;
fi
echo linking $base
ln -s ../extend/addon/zaddons/$base $base
done
popd
# 3 - Some extra folders
ynh_script_progression --message="Creating smarty3 folder for personal data..."
mkdir -p "${install_dir}/store"
mkdir -p "${install_dir}/cache/smarty3"
chmod -R 775 $install_dir/store $install_dir/cache
# Create php.log inside for logs
touch "$install_dir/php.log"
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..." --weight=1
ynh_add_config --template="htconfig.php" --destination="$install_dir/.htconfig.php"
chmod 400 "$install_dir/.htconfig.php"
chown $app:$app "$install_dir/.htconfig.php"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..."
# Create a dedicated nginx config
ynh_add_nginx_config
# Create a dedicated php-fpm config
ynh_add_fpm_config
ynh_add_config --template="poller-cron" --destination="/etc/cron.d/$app"
chown root: "/etc/cron.d/$app"
chmod 644 "/etc/cron.d/$app"
# Use logrotate to manage application logfile(s)
ynh_use_logrotate "$install_dir/php.log"
ynh_add_fail2ban_config --logpath="$install_dir/php.log" --failregex="^.*auth\.php.*failed login attempt.*from IP <HOST>.*$" --max_retry="5"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed"