config() {
    NEW="$1"
    OLD="$(dirname $NEW)/$(basename $NEW .new)"
    # If there's no config file by that name, mv it over:
    if [ ! -r $OLD ]; then
        mv $NEW $OLD
    elif [ "$(cat $OLD | md5sum)" = "$(cat $NEW | md5sum)" ]; then
        # toss the redundant copy
        rm $NEW
    fi
    # Otherwise, we leave the .new copy for the admin to consider...
	
}

preserve_perms() {
    NEW="$1"
    OLD="$(dirname $NEW)/$(basename $NEW .new)"
    if [ -e $OLD ]; then
        cp -avr $OLD ${NEW}.incoming
        cat $NEW > ${NEW}.incoming
        mv ${NEW}.incoming $NEW
    fi
    config $NEW
	
}

# set /dev/ttyS0 serial port list entry to /dev/ttyAMA0 in /etc/inittab
# this will prevent the 'INIT: Id "s0" respawning too fast' error
if grep -q '^s0:12345' etc/inittab ; then
  sed -i -e 's/s0:12345:respawn:\/sbin\/agetty 115200 ttyS0 vt100/s0:12345:respawn:\/sbin\/agetty -L ttyAMA0 9600 vt100/g' etc/inittab
fi

# enable PermitRootLogin in /etc/ssh/sshd_config
if grep -q '^#PermitRootLogin' etc/ssh/sshd_config ; then
  sed -Ei 's/#PermitRootLogin.*/PermitRootLogin yes/g' etc/ssh/sshd_config
  echo " + PermitRootLogin in /etc/ssh/sshd_config - ENABLED"
fi

