#!/bin/bash
set -e
OCC="sudo -u apache php /var/www/owncloud/occ"

echo "=== STEP 1: Create group 'versioning_users' ==="
$OCC group:add versioning_users 2>&1 || true

echo
echo "=== STEP 2: Add all non-pavon users to the group ==="
for u in Martell anaise bst jburger mara minrec rohrbach sysadmin themarcgroup; do
    $OCC group:add-member versioning_users --member "$u" 2>&1 || true
done

echo
echo "=== STEP 3: Verify membership ==="
$OCC group:list-members versioning_users 2>&1

echo
echo "=== STEP 4: Disable files_versions globally ==="
$OCC app:disable files_versions 2>&1

echo
echo "=== STEP 5: Re-enable for versioning_users group only ==="
$OCC app:enable files_versions --groups versioning_users 2>&1

echo
echo "=== STEP 6: Verify app status ==="
$OCC app:list 2>&1 | grep -A 2 -i versions
echo
echo "=== STEP 7: Verify pavon excluded ==="
$OCC user:list-groups pavon 2>&1
