#!/bin/sh -e

##########################################################################
#   Synopsis:
#       auto-sync-pxe-root-pw
#
#   Description:
#       Sync the default root password in a PXE install image to the
#       current root password.
#
#   Arguments:
#       None
#
#   Returns:
#       0 on success, non-zero otherwise
#
#   Files:
#       LOCALBASE/etc/auto-admin/pxe, /etc/master.passwd
#
#   See also:
#       auto-pxe-installer-setup(1), passwd(1)
#       
#   History:
#   Date        Name        Modification
#   2021-12-23  J Bacon     Begin
##########################################################################

usage()
{
    printf "Usage: $0\n"
    exit 1
}


##########################################################################
#   Main
##########################################################################

if [ $# != 0 ]; then
    usage
fi

case $(auto-ostype) in
FreeBSD)
    : ${LOCALBASE:=/usr/local}
    
    rootpw=$(awk -F : '$1 == "root" { print $2 }' /etc/master.passwd)
    #echo $rootpw
    prefix=$(awk '$1 == "prefix" { print $2 }' $LOCALBASE/etc/auto-admin/pxe)
    for dir in $prefix/images/*; do
	# No auto-transfer-pw under chroot, use chpass/usermod directly
	chroot $dir chpass -p "$rootpw" root
	#awk -F : '$1 == "root" { print $2 }' $dir/etc/master.passwd
    done
    ;;

*)
    auto-unsupported-os $0
    ;;

esac
