#!/bin/sh
set -eu
echo "Initializing nextcloud $image_version ..."
echo "Upgrading nextcloud from $installed_version ..."
sh -c 'php /var/www/html/occ app:list' | sed -n "/Enabled:/,/Disabled:/p" > /tmp/list_before
sh -c 'php /var/www/html/occ upgrade'
sh -c 'php /var/www/html/occ app:list' | sed -n "/Enabled:/,/Disabled:/p" > /tmp/list_after
echo "The following apps have been disabled:"
diff /tmp/list_before /tmp/list_after | grep '<' | cut -d- -f2 | cut -d: -f1
rm -f /tmp/list_before /tmp/list_after
for i in $(cat apps_enable)
    do 
        app=${i%=*}
        sh -c "php /usr/src/app/nextcloud/occ app:enable $app"
    done
echo "Upgrade finished"
