mirror of
https://github.com/YunoHost-Apps/zap_ynh.git
synced 2024-09-03 20:36:07 +02:00
117 lines
3.4 KiB
Bash
Executable file
117 lines
3.4 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
ynh_script_progression --message="Loading installation settings..."
|
|
|
|
version=$(grep STD_VERSION $install_dir/boot.php | cut -c 38- | rev | cut -c 5- | rev)
|
|
last_update=$(grep update_time: /etc/yunohost/apps/$app/settings.yml | cut -c 14-)
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading source files..."
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
# ynh_setup_source --dest_dir="$install_dir"
|
|
|
|
if [ `cd $install_dir && git rev-parse --is-inside-work-tree` ]; then
|
|
pushd "$install_dir"
|
|
git pull --quiet
|
|
cd extend/addon/zaddons
|
|
git pull --quiet
|
|
cd ../../..
|
|
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
|
|
for x in `ls` ; do
|
|
if [ -L "$x" ] && ! [ -e "$x" ]; then
|
|
echo "removing dead symlink $x" ;
|
|
rm -- "$x";
|
|
fi;
|
|
done
|
|
popd
|
|
chmod -R 775 $install_dir/store
|
|
else
|
|
|
|
# Create a temporary directory
|
|
tmpdir="$(ynh_smart_mktemp 6000)"
|
|
# Backup the config file in the temp dir
|
|
cp -a "$install_dir/.htconfig.php" "$tmpdir/.htconfig.php"
|
|
cp -a "$install_dir/store" "$tmpdir/store"
|
|
cp -a "$install_dir/php.log" "$tmpdir/php.log"
|
|
cp -a "$install_dir/cache" "$tmpdir/cache"
|
|
|
|
# Remove the app directory securely
|
|
ynh_secure_remove "$install_dir"
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
ynh_setup_source --dest_dir="$install_dir"
|
|
|
|
cp -a "$tmpdir/cache" "${install_dir}"
|
|
cp -a "$tmpdir/store" "${install_dir}"
|
|
cp -a "$tmpdir/.htconfig.php" "${install_dir}"
|
|
cp -a "$tmpdir/php.log" "${install_dir}"
|
|
ynh_secure_remove --file="$tmpdir"
|
|
chmod -R 775 $install_dir/store
|
|
mkdir $install_dir/addon
|
|
ynh_setup_source --dest_dir="$install_dir/addon" --source_id="app_addons"
|
|
fi
|
|
|
|
chmod 750 "$install_dir"
|
|
chmod -R o-rwx "$install_dir"
|
|
chown -R $app:www-data "$install_dir"
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..."
|
|
|
|
# Create a dedicated nginx config
|
|
ynh_add_nginx_config
|
|
|
|
# Create a dedicated php-fpm config
|
|
ynh_add_fpm_config
|
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
ynh_use_logrotate --non-append
|
|
|
|
ynh_add_config --template="poller-cron" --destination="/etc/cron.d/$app"
|
|
chown root: "/etc/cron.d/$app"
|
|
chmod 644 "/etc/cron.d/$app"
|
|
|
|
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="Upgrade of $app completed"
|