#!/bin/sh
#
# aryzhov@spasu.net
# add users as per piece of passwd file found in
# site-specific etc prototype
#
[ -z "$SID" ] && SID=/tmp/install_config
[ X$SubrIsRead = XYes ] || . $SID/Scripts/Misc/!Includes/Subroutines
[ X$VarsAreSet = XYes ] || SetJVars
SetRootOpts ; [ X$ROOT != X/ ] && exec Chroot_Script $0 $*

PASSWD=$SID/Profiles/$SITE/SiteConfig/etc/passwd
GROUP=$SID/Profiles/$SITE/SiteConfig/etc/group

for i in passwd shadow group; do cp /etc/$i /etc/$i.pre-`basename $0`; done

[ -f $PASSWD ] || exit 0

[ -f $PASSWD ] && for u in `awk -F: '{print $1}' $PASSWD`; do
  grep "^$u:" /etc/passwd && continue
  grep "^$u:" $PASSWD     >>/etc/passwd
  printf "$u:NP:6445::::::\n" >>/etc/shadow
  uid=`awk -F: '$1=="'$u'" {print $3}' $PASSWD`
  gid=`awk -F: '$1=="'$u'" {print $4}' $PASSWD`
  hom=`awk -F: '$1=="'$u'" {print $6}' $PASSWD`
  mkdir -p $hom || StartShell "Failed to create $hom"   # This will also catch the attempts to chmod/chown /
  chown -R $uid:$gid $hom/.
  chmod    700       $hom/.
done


[ -f $GROUP ] && for g in `awk -F: '{print $1}' $GROUP 2>/dev/null`; do
  grep "^$g:" /etc/group && continue
  grep "^$g:" $GROUP     >>/etc/group
done


chown root:root /export/home/.; chmod 755 /export/home/.
#
# /export/home and all parent dirs can not be chmod'ed to 711,
# because silly IBM DB2 installer wants
#   su - $user -c pwd
# which fails if home's parent dir has x mode only. Stupid.
#
