#!/bin/sh
# Userchecking code based on code generously donated by Manoj.


# The iraf account should be iraf/nobody by default

user="iraf"
gid="65534"
irafexist="0"

mgroup=$(egrep "^$user:" /etc/passwd | cut -d: -f 4 )
groups=$(egrep "$user" /etc/group  | cut -d: -f 3)

echo "mgroup = $mgroup"
echo "groups = $groups"

for group in $mgroup $groups; do
    if [ "X$group" = "X$gid" ]; then
	echo "Found user $user with gid $gid."
	echo "Not creating account."
	irafexist="1"
    fi
done
if [ $irafexist = "0" ]; then
    echo "$user not found."
    echo "Creating user $user with gid $gid."
    adduser --system --home /iraf/iraf/local --disabled-password iraf
fi 
chsh -s /usr/bin/csh iraf
chown -R iraf.nogroup /usr/iraf
chown iraf.nogroup /iraf

cd /iraf/iraf/unix/hlib
echo
echo "Now preparing to run the IRAF setup script."
echo "You will be asked to enter the IRAF root directory."
echo "Be sure to use /iraf/iraf unless you REALLY know what you're doing."
echo

./install -b /usr/bin

echo
echo "Base install complete."
echo "Each user who wishes to use IRAF must run the mkiraf script from the"
echo "home directory before IRAF can be run."
echo

#DEBHELPER#
