#!/bin/sh

# Create empty password file
#--------------------------------
if [ ! -f /etc/BackupPC/webconfig.user ]; then
	/bin/touch /etc/BackupPC/webconfig.users
	/bin/chown webconfig /etc/BackupPC/webconfig.users
fi


# Patch config.pl for backuppc user
#--------------------------------
/bin/sed -i -e "/^\$Conf{CgiAdminUsers}/ c\$Conf{CgiAdminUsers} = 'backuppc';" /etc/BackupPC/config.pl


# Add to sudoers for local backup
#-------------------------------
if ! grep 'backuppc ALL=NOPASSWD' /etc/sudoers > /dev/null; then
    /usr/bin/logger -p local6.notice -t installer "Adding BackupPC sudoers entry"
    # add RF at beginning as default sudoers does not contain a RF
    echo -e "\nbackuppc ALL=NOPASSWD: /bin/gtar, /usr/bin/rsync" >> /etc/sudoers
    /bin/chmod 0440 /etc/sudoers
fi

# Patch Samba - remove -N flag to permit authentication
#-------------------------------
/bin/sed -i -e "s/$userName -E -N/$userName -E/" /etc/BackupPC/config.pl
