#!/bin/bash
COLUMNS=78

OC_PASS=$(whiptail --passwordbox --title "Enter new password" "Enter new password for user 'admin':" 8 $COLUMNS 3>&1 1>&2 2>&3)
OC_REPEAT=$(whiptail --passwordbox --title "Repeat new password" "Repeat new password for user 'admin':" 8 $COLUMNS 3>&1 1>&2 2>&3)

if [ "$OC_PASS" != "$OC_REPEAT" ]; then
  whiptail --msgbox --title "Error" "Passwords do not match!" 8 $COLUMNS
  exit
fi

sudo -u www-data OC_PASS=$1 php /var/www/owncloud/occ \
               user:resetpassword admin \
               --no-interaction --password-from-env

whiptail --msgbox --title "Success" "Password for user 'admin' changed." 8 $COLUMNS
