#!/usr/bin/with-contenv bash

symlinks=( \
/app/www/public/backup \
/app/www/public/logs \
/app/www/public/user \
)

shopt -s globstar dotglob

for i in "${symlinks[@]}"; do
if [[ -d /config/www/"$(basename "$i")" && ! -L "$i"  ]]; then
    rm -rf "$i"
fi
if [[ ! -d /config/www/"$(basename "$i")" && ! -L "$i"  ]]; then
    mv "$i" /config/www/
fi
if [[ -d /config/www/"$(basename "$i")" && ! -L "$i"  ]]; then
    ln -s /config/www/"$(basename "$i")" "$i"
fi
done

shopt -u globstar dotglob

sed -i 's/enable_auto_updates_check: true/enable_auto_updates_check: false/' /config/www/user/plugins/admin/admin.yaml

lsiown -R abc:abc \
    /app \
    /config/www
