home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1999 March B
/
SCO_CASTOR4RRT.iso
/
nws
/
install
/
nwsclnt
/
misc_func
< prev
next >
Wrap
Text File
|
1998-08-19
|
6KB
|
326 lines
# @(#)misc_func 1.3
#
# miscellaneous functions for the server set request scripts
#
function ClearScreen
{
[ -n "$DEBUG" ] && set -x
ccall altprintf "@string_t:"!\\\033[2J\\\033[H!""
return 0
}
function GoodBye
{
[ -n "$DEBUG" ] && set -x
if [ $SMART_START == "FALSE" ]
then
ClearScreen
call endwin
fi
exit $1
}
#
# This function sets the proper locale. It is called by all
# packaging scripts except the nws set request script.
#
# Related function: InitLocale
#
function SetLocale
{
[ -n "$DEBUG" ] && set -x
# There is a prescribed list of LOCALE variables to check.
# If none are set coming in to this request script, then
# default to the C locale.
LOCALE=${LC_ALL:-${LC_MESSAGES:-${LANG:-C}}}
# Set C locale environment variable for help and strings files.
C_LANGDEP_SCRIPTS=/etc/inst/locale/C/menus/nws
# Set environment variable to find help (.hcf) and strings files
# in the proper locale.
if [ -s /etc/inst/locale/${LOCALE}/menus/nws/set_strings ]
then
LANGDEP_SCRIPTS=/etc/inst/locale/${LOCALE}/menus/nws
else
LANGDEP_SCRIPTS=${C_LANGDEP_SCRIPTS}
fi
}
function ViewInfo
{
[ -n "$DEBUG" ] && set -x
# This uglieness allows the helpwin function to be used
# for viewing information outside of a "help" context.
# We need to change the footers so they don't reference
# the "help" context. When we're done, we set the footers
# back to their original values.
TMP1=$FIRST_PAGE_FOOTER
TMP2=$LAST_PAGE_FOOTER
TMP3=$MIDDLE_PAGE_FOOTER
TMP4=$ONLY_PAGE_FOOTER
FIRST_PAGE_FOOTER=$X_FIRST_PAGE_FOOTER
LAST_PAGE_FOOTER=$X_LAST_PAGE_FOOTER
MIDDLE_PAGE_FOOTER=$X_MIDDLE_PAGE_FOOTER
ONLY_PAGE_FOOTER=$X_ONLY_PAGE_FOOTER
helpwin $1
input_handler
FIRST_PAGE_FOOTER=$TMP1
LAST_PAGE_FOOTER=$TMP2
MIDDLE_PAGE_FOOTER=$TMP3
ONLY_PAGE_FOOTER=$TMP4
return 0
}
function putfoot
{
[ -n "$DEBUG" ] && set -x
cdecl longp 'page=&pg'
cprint -v PAGE page
#
# There seems to be a bug in setting PAGE
# correctly.
#
if (( $PAGE == 0 ))
then
let PAGE=PAGE+1
fi
if (( $HELP_PAGES == 1 ))
then
footer "$ONLY_PAGE_FOOTER"
elif (( $PAGE == 1 ))
then
footer "$FIRST_PAGE_FOOTER"
elif (( $PAGE == $HELP_PAGES ))
then
footer "$LAST_PAGE_FOOTER"
else
footer "$MIDDLE_PAGE_FOOTER"
fi
}
function helpwin
{
[ -n "$DEBUG" ] && set -x
typeset basefil=$1 fil=$LANGDEP_SCRIPTS/help/$1.hcf line a OIFS="$IFS" IFS="$IFS" page
if [ ! -f "$fil" ]
then
# print -u2 Cannot open $fil
return 1
fi
typeset IFS=
{
read title
read related
read line
} <$fil
typeset IFS="$OIFS"
set -- $line
HELP_PAGES=$1
set -- $related ${RELATED_HELPS}
open_help -help "wclose \$WCURRENT; helphelp $basefil $*" -page "putfoot" "$fil"
cdecl longp 'height=&Help_height' 'width=&Help_width'
cprint -v HELP_HEIGHT height
cprint -v HELP_WIDTH width
place_window -below 0 $HELP_WIDTH $HELP_HEIGHT -fg $HELP_FG -bg $HELP_BG -title "$title" -border_fg $HELP_FG -current 'msg; putfoot'
run_help "$fil"
}
function helphelp
{
[ -n "$DEBUG" ] && set -x
typeset i titles
typeset basefil="$1"
shift
integer max=${#MOREHELP_TITLE} j=0
typeset args=
for i
do
case " $args " in
*" $i "*)
;;
*)
args="$args $i"
esac
done
set -- $args
for i
do
{
read titles[j]
} <$LANGDEP_SCRIPTS/help/$i.hcf
if (( max < ${#titles[j]} ))
then
max=${#titles[j]}
fi
j=j+1
done
place_window -left 0 $max+2 $# -fg $HELP_FG -bg $HELP_BG -border_fg $HELP_FG -title "$MOREHELP_TITLE" -current 'footer "$MOREHELP_FOOTER"'
typeset wid=$CURWIN
open_menu -exit 'wclose $wid; destroy_menu $mid'
typeset mid=$MID
typeset open=1
typeset use
j=0
for i
do
add_menu_item -select "wclose $wid; destroy_menu $mid; helpwin $i $basefil" "${titles[j]}"
j=j+1
done
run_menu $mid 0
}
#
# Create NetWare users and groups
#
function CreateUsersAndGroups
{
[ -n "$DEBUG" ] && set -x
typeset -i gid found
GREP="/usr/bin/fgrep"
AWK="/usr/bin/awk"
USERADD="/usr/sbin/useradd"
USERDEL="/usr/sbin/userdel"
GROUPDEL="/usr/sbin/groupdel"
GROUPADD="/usr/sbin/groupadd"
PASSWD="/usr/bin/passwd"
#
# Create nwgroup
#
ENTRY=`$GREP nwgroup /etc/group`
if [ -n "$ENTRY" ]
then
# nwgroup was found but we need to make sure the gid is within range
gid=`echo $ENTRY | $AWK '{FS=":"} {print $3}'`
if [ $gid -lt 100 ]
then
# nwgroup has a gid less than 100. We don't need to do anything.
found=1
else
# The gid on nwgroup is too large. Delete nwgroup.
$GROUPDEL nwgroup 1>&2
found=0
fi
else
# nwgroup not found
found=0
fi
if [ $found -eq 0 ]
then
# Find the first free gid starting at 50.
let gid=50
while : # always true
do
if [ $gid -ge 100 ]
then
# Too many iterations. Something is wrong.
print -u2 "$CANNOT_CREATE_NWGROUP"
break
fi
$GREP ":$gid:" /etc/group > /dev/null 2>&1
if [ $? -eq 0 ]
then
# This gid already in use, so skip.
let gid=gid+1
continue
fi
$GROUPADD -g $gid nwgroup 1>&2
if [ $? -eq 0 ]
then
# Group added successfully
break
else
# Some problem adding the group. Try next.
let gid=gid+1
continue
fi
done
fi
AddUser "nwroot" $gid "50" "NetWare Administrator without a UnixWare Account"
AddUser "nwuser" $gid "51" "NetWare user without a UnixWare Account"
AddUser "nwprint" $gid "52" "NetWare Print User"
return 0
}
function AddUser
{
[ -n "$DEBUG" ] && set -x
typeset -i uid
user="$1"
gid="$2"
uid="$3"
name="$4"
ENTRY=`$GREP $user /etc/passwd`
if [ -n "$ENTRY" ]
then
# user was found, but we need to see if it has the correct gid
user_gid=`echo $ENTRY | $AWK '{FS=":"} {print $4}`
if [ $user_gid -eq $gid ]
then
# found the correct gid. We don't need to do anything
found=1
else
# user does not have the correct gid
# delete old user and create a new one.
$USERDEL -n 0 $user 1>&2
found=0
fi
else
# nwprint not found
found=0
fi
if [ $found -eq 0 ]
then
# Find the first free uid starting at $uid.
while : # always true
do
if [ $uid -ge 100 ]
then
# Too many iterations. Something is wrong.
print -u2 "$CANNOT_CREATE_USER"
break
fi
$USERADD -u $uid -g $gid -c "$name" "$user" 1>&2
if [ $? -eq 0 ]
then
# user added successfully.
break
else
# Some problem adding the user. UID probably already taken. Try next.
let uid=uid+1
continue
fi
done
fi
return 0
}