#!/bin/sh
# Author: Blake, Kuo-Lien Huang
# License: GPL
# Description: change client's root password

imagehost="/var/lib/diskless/default"

# must be root
ID=`id -u`
if [ "$ID" != "0" ]; then
  echo "You must be root to use this script."
  echo "Use sudo to enable it for users."
  exit 1
fi

# chroot 
chroot $imagehost/root passwd root

# copy passwd shadow to all clients
for host in `ls $imagehost`; do

  if [ "$host" = "." -o "$host" = ".." -o "$host" = "root" ]; then continue; fi

  cp $imagehost/root/etc/passwd $imagehost/$host/etc
  if [ -f $imagehost/root/etc/shadow ]; then
    cp $imagehost/root/etc/shadow $imagehost/$host/etc
  fi
  
done
