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
    elif [ -f /.installer-version ]; then
        # We're in the Installer, so overwrite the Installer-specific file
        mv $NEW $OLD
    fi
    # Otherwise, we leave the .new copy for the admin to consider...
	
}

# Remove any duplicate line entries in fstab
if [ -f /tag/README ] ; then 
    sed -i '$!N; /^\(.*\)\n\1$/!P; D' /mnt/etc/fstab
fi

# Determine status of system ROOTDEV 
if [ -f /tag/README ] ; then 
    # Get ROOTDEV via blkid in the Installer
	ROOTDEV=$(cat /mnt/etc/fstab | grep " / " | cut -d' ' -f1)
elif [ -b /dev/mmcblk0p2 ]; then
    # Get ROOTDEV via findmnt on installed system
    ROOTDEV=$(findmnt -n -o SOURCE /)
else
    # Assume the default ROOTDEV 
    ROOTDEV='/dev/mmcblk0p3'  
fi

# Determine status of system ROOTFSTYPE
if [ -f /tag/README ] ; then 
    # Get ROOTFSTYPE from /mnt/etc/fstab in the Installer
    ROOTFSTYPE=$(grep " / " /mnt/etc/fstab | awk '{print $3}')
elif [ -b /dev/mmcblk0p2 ]; then
    # Get ROOTFSTYPE on installed system
    ROOTFSTYPE=$(awk '/\/root/ {print $3}' /proc/mounts)
else
    # Assume the default ROOTFSTYPE [ext4]
    ROOTFSTYPE="ext4"
fi

# Write ROOTDEV and ROOTFSTYPE to cmdline.txt.new file
sed -i -e "s|@DEVROOT@|${ROOTDEV}|" -e "s|@ROOTFSTYPE@|${ROOTFSTYPE}|" boot/cmdline.txt.new

# Roll the config()
config boot/cmdline.txt.new

# Double-sync - /boot is a vfat filesystem
sync;sync
