home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1999 March B
/
SCO_CASTOR4RRT.iso
/
update701
/
install
/
updpkg.rc
< prev
next >
Wrap
Text File
|
1998-07-28
|
14KB
|
592 lines
#ident "@(#)updpkg.rc 17.2 98/07/28"
#copyright "%c%"
#!/usr/bin/sh
RmExit ()
{
${BIN}/rm -rf ${UPDTMP} 2 >/dev/null
exit $1
}
#
# Minimize the overhead of all those DbgMsg calls...
#
DBG=/var/sadm/pkg/installdbg
if [ -f ${DBG} ]
then
DbgMsg ()
{
echo "$@" 2>&1 >> ${DBG}.log
}
DbgAddFile ()
{
if [ -r "${1}" ]
then
${BIN}/cat ${1} 2>&1 >> ${DBG}.log
else
echo "File ${1} non-existent or unreadable" >> ${DBG}.log
fi
}
else
DbgMsg ()
{
:
}
DbgAddFile ()
{
:
}
fi
#
# Message logger.
#
LogMsg ()
{
echo "$@" >> ${UPDLOGFILE}
}
#
# Find out who the desktop owners are
#
GetDeskTopOwners ()
{
LogMsg "GetDeskTopOwners: `GetText STARTED`"
DbgMsg "GetDeskTopOwners: STARTED"
DeskTopOwn=""
for user in `${BIN}/grep -l owner /usr/X/desktop/LoginMgr/Users/* 2>/dev/null | ${BIN}/sed 's%.*/%%g'`
do
# Concatenate multiple desktop owners.
# Eliminates newlines between owners.
DeskTopOwn="${DeskTopOwn} ${user}"
done
DeskTopOwn=`echo ${DeskTopOwn} | ${BIN}/sed 's/^ //g'`
export DeskTopOwn
LogMsg "GetDeskTopOwners: `GetText COMPLETED` - DeskTopOwn='${DeskTopOwn}'"
DbgMsg "GetDeskTopOwners: COMPLETED - DeskTopOwn='${DeskTopOwn}'"
return 0
}
#
# Stop the work menu,
#
WorkMenuKill ()
{
DbgMsg "WorkMenuKill: STARTED"
if [ -f ${UPDMENUDIR}/working.kill ]
then DbgMsg " WorkMenuKill: work menu needs kill"
. ${UPDMENUDIR}/working.kill
DbgMsg " WorkMenuKill: work menu was killed"
else DbgMsg " WorkMenuKill: work menu was inactive"
fi
DbgMsg "WorkMenuKill: COMPLETED"
return 0
}
#
# Clear Screen. No args passed.
#
MenuClear ()
{
DbgMsg "MenuClear: STARTED"
# Is working menu running, if so kill it.
WorkMenuKill
# Clear the screen.
${USBIN}/menu -c >${TTY}
DbgMsg "MenuClear: COMPLETED"
}
#
# Display and handle basic request messages
#
# $1 - action to perform on the message:
# 1: display to terminal (interactive System msg)
# 2: mail to desktop owner and root
# 3: both 1 and 2 (interactive)
# 4: display to terminal (non-interactive)
# 5: 4 and mail to desktop owner and root
# $2 - message keyword
#
MsgHandler ()
{
DbgMsg "MsgHandler: STARTED"
if [ -f ${UPDINST}/msgfile.txt.${UPDLANG} ]
then
. ${UPDINST}/msgfile.txt.${UPDLANG}
else
. ${UPDINST}/msgfile.txt
fi
# Get message text.
eval "MsgText=\${$2}"
DbgMsg " MsgText=${MsgText}"
# Action perform with message.
case ${1} in
0) # just return message to caller
echo "${MsgText}"
;;
1) # display to terminal as System Message
# with "Strike ENTER when ready" prompt
LogMsg "${MsgText}"
MenuClear
if [ "$SILENT_INSTALL" = "true" ]
then ${BIN}/message -d "${MsgText}" >${TTY}
${BIN}/sleep 10
else ${BIN}/message "${MsgText}" >${TTY}
fi
;;
2) # mail to desktop owner and root
# echo "${MsgText}" | ${BIN}/mailx ${DeskTopOwn} root
LogMsg "${MsgText}"
;;
3) # Do both 1 and 2 above
echo "${MsgText}" | ${BIN}/mailx ${DeskTopOwn} root
LogMsg "${MsgText}"
MenuClear
if [ "$SILENT_INSTALL" = "true" ]
then ${BIN}/message -d "${MsgText}" >${TTY}
${BIN}/sleep 10
else ${BIN}/message "${MsgText}" >${TTY}
fi
;;
4) # display to terminal as a regular message
MenuClear
${BIN}/message -d "${MsgText}" >${TTY}
;;
5) # Do 4 as well as mail to desktop owner and root
echo "${MsgText}" | ${BIN}/mailx ${DeskTopOwn} root
LogMsg "${MsgText}"
MenuClear
${BIN}/message -d "${MsgText}" >${TTY}
;;
esac
DbgMsg "MsgHandler: COMPLETED"
}
#
# Checks to see if package is compatible with installed OS.
#
OSBaseChk ()
{
LogMsg "OSBaseChk: `GetText STARTED`"
DbgMsg "OSBaseChk: STARTED"
#
# on UW7 uname -r -v returns 5 7
# update 1 returns 5 7.0.1
# on UW2.1 uname -r -v returns 4.2MP 2.1
#
InstRel="`${BIN}/uname -r -v`"
DbgMsg " OSBaseChk: IRELEASE='${IRELEASE}', InstRel='${InstRel}'"
for irel in ${IRELEASE}
do
case "${InstRel}" in
5*${irel})
# Must be a Release 5 OS with specified
# version(s) or the same, i.e. an overlay
# installation.
unset irel InstRel
LogMsg "OSBaseChk: `GetText COMPLETED`"
DbgMsg "OSBaseChk: COMPLETED - Rel is 5*${irel}"
return 0
;;
*)
continue
;;
esac
done
DbgMsg "OSBaseChk: COMPLETED - Rel is not 5*${irel}"
#
# Proper Release not installed.
#
MsgHandler 3 UpdBaseMsg
LogMsg "\nUpdBaseMsg:\n${UpdBaseMsg}"
DbgMsg "OSBaseChk: Exit code - 1"
LogMsg "Request: `GetText COMPLEXIT` - 1"
RmExit 1
}
#
# Checks to see if the Kernel Tools are installed
#
KernelToolsChk ()
{
LogMsg "KernelToolsChk: `GetText STARTED`"
DbgMsg "KernelToolsChk: STARTED"
CWD=`pwd`
cd ${CONFBIN}
DbgMsg " KernelToolsChk: If idtools not executable, abort"
if [ ! -x idcheck -o ! -x idbuild -o ! -x idinstall \
-o ! -x idtune -o ! -x idval ]
then
DbgMsg " KernelToolsChk: idtools not executable - abort"
MsgHandler 3 UpdNoToolsMsg
LogMsg "\nUpdNoToolsMsg:\n${UpdNoToolsMsg}"
LogMsg "ChkKernelTools: `GetText COMPLEXIT` - 1\n"
DbgMsg "ChkKernelTools: Exit code - 1\n"
${BIN}/rm -f ${UPDPKGDIR}/!R-Lock!
RmExit 1
fi
cd ${CWD}
LogMsg "ChkKernelTools: `GetText COMPLETED`"
DbgMsg "ChkKernelTools: COMPLETED"
}
# Menu display controller.
# $1 is color
# $2 is menu without ".menu" extension
# $3 optional output file
MenuCmd ()
{
LogMsg "MenuCmd: `GetText STARTED` - ${2}"
DbgMsg "MenuCmd: STARTED with args '${1}' '${2}' '${3}'"
# Is working menu running, if so kill it.
WorkMenuKill
# Setup and display requested menu screen.
menu_colors ${1}
if [ -z "${3}" ]
then
OF=/dev/null
else
OF=${3}
${BIN}/rm -f ${OF}
fi
Menu=${UPDMENUDIR}/${2}.menu
DbgMsg " Menu=${Menu}"
DbgMsg " OF=${OF}"
DbgMsg " UPDTMP=${UPDTMP}"
if [ ! -f ${Menu} ]
then
SrcMenu=${UPDINST}/${2}.menu.${UPDLANG}.Z
[ -f ${SrcMenu} ] || SrcMenu=${UPDINST}/${2}.menu.Z
${BIN}/zcat ${SrcMenu} | ${BIN}/sed -e '/^#ident/d' > ${Menu}
unset SrcMenu
fi
# jillp - menucmd in the locale directories doesn't display 8-bit characters correctly,
# always use the /usr/sbin/menu binary
#DbgMsg " MenuCmd: use new menucmd if available"
#if [ -x ${UPDMENUDIR}/menucmd ]
#then
# ${UPDMENUDIR}/menucmd -r -f ${Menu} -o ${OF} \
# 1>${TTY} 2>${UPDTMP}/menu.err <${TTY}
#else
# ${USBIN}/menu -r -f ${Menu} -o ${OF} \
# 1>${TTY} 2>${UPDTMP}/menu.err <${TTY}
#fi
DbgMsg " updpkg.rc - now using /usr/sbin/menu."
${USBIN}/menu -r -f ${Menu} -o ${OF} \
1>${TTY} 2>${UPDTMP}/menu.err <${TTY}
if [ ${?} -ne 0 ]
then
MenuClear
${BIN}/message "menu: `${BIN}/cat ${UPDTMP}/menu.err`"
LogMsg "MenuCmd: `GetText COMPLEXIT` - 1"
RmExit 1
fi
unset Menu
LogMsg "MenuCmd: `GetText COMPLETED`"
DbgMsg "MenuCmd: COMPLETED"
}
#
# Get a request for a text message, and place it on stdout
#
# $1 - text keyword
GetText ()
{
# Load appropriate message database. Done here to get keywords
# that may be set during execution.
file=${UPDINST}/script.txt.${UPDLANG}
[ -f "${file}" ] || file=${UPDINST}/script.txt
${BIN}/sed -n -e "s/^${1}://p" ${file} 2> /dev/null
unset file
}
#
# Set the locale to C, saving old values
#
SetCLocale ()
{
LogMsg "Locale_C: `GetText STARTED`"
DbgMsg "Locale_C: STARTED"
SAV_TIME=${LC_TIME}
SAV_MESSAGES=${LC_MESSAGES}
SAV_CTYPE=${LC_CTYPE}
SAV_NUMERIC=${LC_NUMERIC}
SAV_LANG=${LANG}
LC_TIME=C
LC_MESSAGES=C
LC_CTYPE=C
LC_NUMERIC=C
LANG=C
export LANG LC_TIME LC_MESSAGES LC_CTYPE LC_NUMERIC
export SAV_LANG SAV_TIME SAV_MESSAGES SAV_CTYPE SAV_NUMERIC
LogMsg "Locale_C: `GetText COMPLETED`"
DbgMsg "Locale_C: COMPLETED"
return 0
}
#
# Restore the locale settings, saved during last call to Locale_C
#
RestoreLocale ()
{
LogMsg "RestoreLocale: `GetText STARTED`"
DbgMsg "RestoreLocale: STARTED"
LC_TIME=${SAV_TIME}
LC_MESSAGES=${SAV_MESSAGES}
LC_CTYPE=${SAV_CTYPE}
LC_NUMERIC=${SAV_NUMERIC}
LANG=${SAV_LANG}
export LANG LC_TIME LC_MESSAGES LC_CTYPE LC_NUMERIC
unset SAV_TIME SAV_MESSAGES SAV_CTYPE SAV_NUMERIC SAV_LANG
LogMsg "RestoreLocale: `GetText COMPLETED`"
return 0
}
#
# Remove a package component
# $1 - package component
# $2 - file to read for the contents database updates
# $3 - log file information
RemoveF ()
{
LogMsg "RemoveF: `GetText STARTED`"
DbgMsg "RemoveF: STARTED args: '${1}' '${2}' '${3}'"
DbgMsg " UPDTMP=${UPDTMP}"
rpkg=${1}
cfile=${2}
ofile=/dev/null
if [ -n "${3}" ]
then
ofile=${3}
fi
DbgMsg " RemoveF: rpkg='${rpkg}', cfile='${cfile}', ofile='${ofile}'"
${BIN}/sort -u ${cfile} | ${USBIN}/removef ${rpkg} - >${ofile} 2>${UPDTMP}/removef.err
if [ ${?} -ne 0 ]
then
LogMsg "RemoveF: ${USBIN}/removef ${rpkg} - <${cfile} >${ofile} `GetText FAILED`"
DbgMsg " RemoveF: ${USBIN}/removef ${rpkg} - <${cfile} >${ofile} failed"
${BIN}/cat ${cfile} >>${UPDLOGFILE}
DbgMsg " RemoveF: ${cfile} Contents:"
DbgAddFile ${cfile}
DbgMsg " RemoveF: ${cfile} Contents End"
${BIN}/cat ${UPDTMP}/removef.err >>${UPDLOGFILE}
DbgMsg " RemoveF: ${UPDTMP}/removef.err Contents:"
DbgAddFile ${UDPTMP}/removef.err
DbgMsg " RemoveF: ${UPDTMP}/removef.err Contents End\n"
else
LogMsg "RemoveF: ${USBIN}/removef ${rpkg} - <${cfile} >${ofile} `GetText SUCCEEDED`"
DbgMsg " RemoveF: ${USBIN}/removef ${rpkg} - <${cfile} >${ofile} succeeded"
fi
unset rpkg cfile ofile
LogMsg "RemoveF: `GetText COMPLETED`"
DbgMsg "RemoveF: COMPLETED"
return 0
}
#
# Does the final remove on a package to finalize contents file
# $1 - package component
# $2 - log file info
#
RemoveFClose ()
{
LogMsg "RemoveFClose: `GetText STARTED`"
DbgMsg "RemoveFClose: STARTED args: '${1}' '${2}'"
rpkg=${1}
ofile=/dev/null
if [ -n "${2}" ]
then
ofile=${2}
fi
DbgMsg " RemoveFClose: rpkg='${rpkg}', ofile='${ofile}'"
${USBIN}/removef -f ${rpkg} >${ofile} 2>${UPDTMP}/removef.err
if [ ${?} -ne 0 ]
then
LogMsg " RemoveFClose: ${USBIN}/removef -f ${rpkg} >${ofile} `GetText FAILED`"
DbgMsg " RemoveFClose: ${USBIN}/removef -f ${rpkg} >${ofile} failed"
${BIN}/cat ${UPDTMP}/removef.err >>${UPDLOGFILE}
DbgMsg " RemoveF: ${UPDTMP}/removef.err Contents:"
DbgAddFile ${UDPTMP}/removef.err
DbgMsg " RemoveF: ${UPDTMP}/removef.err Contents End\n"
else
LogMsg "RemoveFClose: ${USBIN}/removef -f ${rpkg} >${ofile} `GetText SUCCEEDED`"
DbgMsg "RemoveFClose: ${USBIN}/removef -f ${rpkg} >${ofile} succeeded"
fi
unset rpkg ofile
LogMsg "RemoveFClose: `GetText COMPLETED`"
DbgMsg "RemoveFClose: COMPLETED"
return 0
}
#
# Start or update an existing working screen display
# $1 - Package Text Message being processed
# "-d" means delete existing message file
# $2 - Percentage completed
#
WorkMenu ()
{
LogMsg "WorkMenu: `GetText STARTED`"
DbgMsg "WorkMenu: STARTED args: '${1}' '${2}'"
WORKING=${UPDMENUDIR}/working
[ -n "${1}" ] && MSG="${1}"
[ -n "${2}" ] && GAUGE=${2} || GAUGE=0
[ ${GAUGE} -eq 0 ] && WorkMenuKill
echo "echo MSG=\"${MSG}\"; echo PCT=${GAUGE}%; echo GAUGE=${GAUGE}" \
>${WORKING}.sh
[ -f ${WORKING}.kill ] || {
${BIN}/chmod 755 ${WORKING}.sh
menu_colors regular
UPD_PKGSH="" \
${USBIN}/menu -r -f ${UPDMENUDIR}/wrking.menu \
-o /dev/null 1>${TTY} 2>/dev/null <${TTY} &
${BIN}/cat >${WORKING}.kill <<EOF_KILL
${BIN}/kill $! 2>/dev/null
for i in 1 2 3 4
do ${BIN}/kill $! 2>/dev/null || break
${BIN}/sleep 1
done
${BIN}/rm -f ${WORKING}.kill
EOF_KILL
}
LogMsg "WorkMenu: `GetText COMPLETED` - msg=[${1}] pct=[${2}]"
DbgMsg "WorkMenu: COMPLETED - msg=[${1}] pct=[${2}]"
return 0
}
#
# Place perm, own, grp definitions in ${UPDTMP}/perms - only works for rwx
#
GetPerms () # $1 is the file to get permissions on
{
DbgMsg "GetPerms: STARTED on ${1}"
line=`${BIN}/ls -l ${1} | ${BIN}/sed 's/ */ /g'`
perm=`echo "${line}" | ${BIN}/cut -d' ' -f1`
own=`echo "${line}" | ${BIN}/cut -d' ' -f3`
grp=`echo "${line}" | ${BIN}/cut -d' ' -f4`
p1=`echo "${perm}" | cut -c2-4`
p2=`echo "${perm}" | cut -c5-7`
p3=`echo "${perm}" | cut -c8-10`
nperm="0"
for part in "$p1" "$p2" "$p3"
do
num=0
[ "`echo "${part}" | grep "r"`" ] && num=`${BIN}/expr ${num} + 4`
[ "`echo "${part}" | grep "w"`" ] && num=`${BIN}/expr ${num} + 2`
[ "`echo "${part}" | grep "x"`" ] && num=`${BIN}/expr ${num} + 1`
nperm="${nperm}${num}"
done
DbgMsg " Permissions: ${nperm} ${own} ${grp}"
echo "perm=\"${nperm}\"" > ${UPDTMP}/perms
echo "own=\"${own}\"" >> ${UPDTMP}/perms
echo "grp=\"${grp}\"" >> ${UPDTMP}/perms
DbgMsg " GetPerms: CONTENTS of ${UPDTMP}/perms START"
DbgAddFile ${UPDTMP}/perms
DbgMsg " GetPerms: CONTENTS of ${UPDTMP}/perms END"
DbgMsg "GetPerms: COMPLETED"
}
#
# Responsible for checking if there is enough space on disk, and how much
# space is required in each file system.
#
CheckSpace ()
{
# Now, create file ${UPDTMP}/fsspace with stuff to include in menu
# Assume max of 10 chars for numbers.
printf "%11s%11s%11s%11s %s\n" \
"${AVAILABLE_SPACE_MSG1}" "${REQUIRED_SPACE_MSG1}" \
"${AVAILABLE_INODES_MSG1}" "${REQUIRED_INODES_MSG1}" \
"${MOUNT_POINT_MSG1}" > ${UPDTMP}/fsspace
printf "%11s%11s%11s%11s %s\n" \
"${AVAILABLE_SPACE_MSG2}" "${REQUIRED_SPACE_MSG2}" \
"${AVAILABLE_INODES_MSG2}" "${REQUIRED_INODES_MSG2}" \
"${MOUNT_POINT_MSG2}" >> ${UPDTMP}/fsspace
if [ "${CLASSES}" = "" ]
then
DF=1
UPD_BKUP_KB=0
UPD_FLOPPY=0
return 0
fi
[ -x ${UPDMENUDIR}/checkall ] || {
${BIN}/cp ${UPDINST}/checkall ${UPDMENUDIR}/checkall
${BIN}/chmod 555 ${UPDMENUDIR}/checkall
}
${UPDMENUDIR}/checkall ${UPDINST}/Files ${UPDBKUPDIR}/bkupvars \
${CLASSES} >> ${UPDTMP}/fsspace
space_status=$?
[ -s ${UPDBKUPDIR}/bkupvars ] && . ${UPDBKUPDIR}/bkupvars || DF=0
rm -f ${UPDBKUPDIR}/bkupvars
case ${space_status} in
0) return 0
;;
2) echo "\n${NO_DISK_MSG}" >> ${UPDTMP}/fsspace
return 1
;;
3) echo "\n${NO_INODE_MSG}" >> ${UPDTMP}/fsspace
return 1
;;
*) return 1
;;
esac
}
#
# Remove the temporary entries specified and update the contents file
#
RemoveTemps ()
{
DbgMsg " RemoveTemps: Removing $1 entries"
grep "^${1}[ /]" /var/sadm/install/contents | awk '{print $1}' |
removef $PKGINST - >/dev/null 2>&1
rm -rf $1 >/dev/null 2>&1
DbgMsg " RemoveTemps: Removing $1 entries complete"
}
MenuLang ()
{
if [ -f ${UPDINST}/menukey.txt.${UPDLANG} ]
then
. ${UPDINST}/menukey.txt.${UPDLANG}
else
. ${UPDINST}/menukey.txt
fi
if [ -f /etc/inst/locale/${UPDLANG}/menus/menu_colors.sh ]
then
. /etc/inst/locale/${UPDLANG}/menus/menu_colors.sh
else
. /etc/inst/locale/C/menus/menu_colors.sh
fi
}