|
|
DataMuseum.dkPresents historical artifacts from the history of: Rational R1000/400 Tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about Rational R1000/400 Tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T i
Length: 22161 (0x5691)
Types: TextFile
Names: »install_lib«
└─⟦1e97d88e5⟧ Bits:30000533 8mm tape, Rational 1000, RATIONAL ASIS (AIX) 110.2.4.15
└─⟦this⟧ »./releases/asis.110.2.4.15/install/install_lib«
#! /bin/sh
# @(#)install_lib $Revision: 1.12 $ $Date: 1994/01/17 17:43:35 $
# @(#)Copyright(c) 1993,1994 by Rational.
#
# MODULE SPECIFICATION
# Name:
# install_lib
#
# Subsystem:
# install
#
# Description:
# Library functions for the installation scripts.
#
NO=0
YES=1
TRUE=0
FALSE=1
DOL=$
PROGNAME=${command:-`basename $0`}
HOSTNAME=`hostname`
SYS_NAME=`uname -s`
#-----------------------------------------------------------------
# Set the path to look for commands only in the system directories.
#-----------------------------------------------------------------
#
# Doing this avoids problems when the user has scripts or programs
# on his path with the same name as a system command that we choose
# to use.
if [ "$SYS_NAME" = AIX ]
then
PATH=/bin:/usr/bin:/usr/ucb:/etc
sym_link='-L'
else
PATH=/bin:/usr/bin:/usr/ucb:/usr/5bin:/etc
sym_link='-h'
fi
export PATH
rows_columns=`stty size 2>/dev/null`
if [ -n "$rows_columns" ]
then
COLS=`echo $rows_columns | awk '{print $2}'`
if [ $COLS -eq 0 ]
then
COLS=78
else
COLS=`expr $COLS - 2`
fi
else
COLS=78
fi
SEP=`echo "-------------------------------------------------------------------------------------------------------------------------------------------------" |
cut -c1-$COLS`
FMT="fmt -$COLS"
#=======================================================================
# Functions to implement a simple user interface.
#=======================================================================
#------------------------------------------------------------------------
fmt_mesg() {
#------------------------------------------------------------------------
#
# Display message.
#
echo
echo $* | eval $FMT
}
#-----------------------------------------------------------------
get_input() {
#-----------------------------------------------------------------
#
# Get input from the user, providing a prompt value.
#
while true
do
echo
echo -n "$1 [$2] "
read result
if [ -n "$result" ]
then
return
else
if [ -n "$2" ]
then
result=$2
return
else
echo "You must enter a value."
fi
fi
done
}
#-----------------------------------------------------------------
get_yn() {
#-----------------------------------------------------------------
#
# Get and validate a yes/no answer.
#
while true
do
get_input "$1" "$2"
case $result in
[Yy]*) result=yes; return ;;
[Nn]*) result=no; return ;;
*) echo "Please enter 'y' or 'n'." ;;
esac
done
}
#-----------------------------------------------------------------
ask_ok() {
#-----------------------------------------------------------------
#
# Ask the user if his entries are OK.
#
fmt_mesg "If you have made any mistakes, answer 'no' and all the
prompts in this dialog will repeat. Simply press Enter
or Return for those values that you don't want to change."
get_yn "Are these entries OK?" yes
if [ "$result" = yes ]
then
more=0
else
more=1
fi
}
#=======================================================================
# Functions to implement a simple database.
#=======================================================================
install_dir=${install_dir:-.}
inst_db=$install_dir/.install.db
install_defaults=$install_dir/.install_defaults
state_info=$install_dir/.license_data
#-----------------------------------------------------------------
get_var() {
#-----------------------------------------------------------------
#
# Get a variable from the install database.
# If the variable is not in the database return arg 2 or blank line.
#
if [ -r $inst_db ]
then
grep "^$1 " $inst_db | sed -e "s/$1 //g"
else
echo "$2"
fi
}
#-----------------------------------------------------------------
put_var() {
#-----------------------------------------------------------------
#
# Put a variable into the install database.
#
# We create a temporary file in /tmp rather than in the
# current (install) directory because root may not have
# permissions in the install directory if the file system
# is NFS mounted. Yes, paradoxically, the installer can
# have more permissions than root if the file system is
# NFS mounted.
#
touch $inst_db
if [ -w $inst_db ]
then
if grep "^$1 " $inst_db > /dev/null
then
inst_db_new=/tmp/inst_db_new.$$
sed -e "s?^$1 .*?$1 $2?g" $inst_db > $inst_db_new
cp $inst_db_new $inst_db
/bin/rm -f $inst_db_new
chmod 666 $inst_db > /dev/null 2>&1
else
echo "$1 $2" >> $inst_db
fi
else
fmt_mesg "Install cannot update it's installation database.
This may mean that you will get some warnings about
installing this product in the wrong order."
fi
}
#=======================================================================
# Misc. Functions
#=======================================================================
#-----------------------------------------------------------------
mkdir_p() {
#-----------------------------------------------------------------
#
# mkdir -p does not work correctly under AIX 3.2.
#
_DIR=/
for dir in `echo $1 | sed -e 's?/? ?g'`
do
if [ "$dir" != "/" -a \
"$dir" != "." -a \
"$dir" != ".." ]
then
_DIR=${_DIR}$dir
if [ ! -d $_DIR ]
then
if mkdir $_DIR
then
:
else
return 1
fi
fi
_DIR=${_DIR}/
fi
done
}
#-----------------------------------------------------------------
forbid_root() {
#-----------------------------------------------------------------
#
# Don't allow root to run a script.
#
if id | grep "uid=0(root)" >/dev/null
then
fmt_mesg "You cannot be root to run $PROGNAME.
Please run it as the user who is
to own the product files." >&2
exit 1
fi
}
#-----------------------------------------------------------------
require_root() {
#-----------------------------------------------------------------
#
# Require that root run a script
#
if id | grep "uid=0(root)" >/dev/null
then
:
else
echo "You must be root to run $PROGNAME." >&2
exit 1
fi
}
#-----------------------------------------------------------------
set_cpath() {
#-----------------------------------------------------------------
#
# Set symbolic link '<directory>/.Rational_Location to <permanent name>.
#
# optional Arg 1: -f = force creation of .Rational_Location if it
# already exists.
# Arg 1: directory
# Arg 2: permanent name
#
if [ $# -lt 2 ]
then
echo "usage: set_cpath [-f] <directory> <permanent_name>" >&2
return $FALSE
fi
_force=no
if [ "$1" = '-f' ]
then
_force=yes
shift
fi
if [ -d $1 ]
then
if [ ! -d $1/.Rational_Location -o $_force = yes ]
then
/bin/rm -f $1/.Rational_Location
ln -s $2 $1/.Rational_Location
return $?
else
echo "set_cpath: $1/.Rational_Location already exists" >&2
return $FALSE
fi
else
echo "set_cpath: $1 not found" >&2
return $FALSE
fi
}
#-----------------------------------------------------------------
cpath() {
#-----------------------------------------------------------------
#
# Return the 'permanent name' path of <arg 1> directory, by searching
# up the directory path for a .Rational_Location symbolic link.
# If one is not found, return <arg 1>.
#
# Arg 1: directory
#
if [ $# -ne 1 ]
then
echo "usage: cpath <directory>" >&2
return $FALSE
fi
_normal_name=$1
_suffix=
case $1 in
. ) _path_name=`pwd` ;;
* ) _path_name=$1 ;;
esac
while [ -n "$_path_name" -a "$_path_name" != / ]
do
if [ $sym_link $_path_name/.Rational_Location ]
then
_normal_name=`ls -l $_path_name/.Rational_Location |
sed -e 's/.*->\(.*\)/\1/g'`
if [ -n "$_suffix" ]
then
_normal_name=$_normal_name/$_suffix
fi
break
fi
if [ -z "$_suffix" ]
then
_suffix=`basename $_path_name`
else
_suffix=`basename $_path_name`/$_suffix
fi
_path_name=`dirname $_path_name`
done
echo $_normal_name
return $TRUE
}
#-----------------------------------------------------------------
is_a_link() {
#-----------------------------------------------------------------
#
# Arg 1 is a symbolic link file. If the file exists as a symbolic
# link, display the file name that it points to and return TRUE.
# If the file does not exist, return FALSE.
#
if [ $sym_link $1 ]
then
# Arg 5 is the file arg 1 points to.
file $1 | awk '{print $5}' | sed -e 's/\.$//'
return $TRUE
else
return $FALSE
fi
}
#-----------------------------------------------------------------
make_link() {
#-----------------------------------------------------------------
#
# Make or replace symbolic link arg2 to point to arg 1.
# Do not make link if a agr2 is a regular file or a directory.
#
if [ -f $2 ]
then
return $FALSE
elif [ -d $2 ]
then
return $FALSE
elif [ $sym_link $2 ]
then
# Replace it
/bin/rm -f $2
fi
ln -s $1 $2
}
#-----------------------------------------------------------------
is_a_rational_location() {
#-----------------------------------------------------------------
#
# If arg1 is a Rational subsystem directory or
# display the output of cpath of this directory and return TRUE.
#
# If arg1 is a directory which contains a .Rational_Location,
# display the 'value' of the .Rational_Location and return TRUE.
#
# Depends on the cpath program, install_dir and ARCH being set
#
if [ `basename $1` = .Rational_Location ]
then
is_a_link $1
return $?
elif [ -d $1 ]
then
if echo $1 | grep '\.ss$' >/dev/null
then
if [ $sym_link $1/.Rational_Location ]
then
if is_a_link $1/.Rational_Location
then
return $TRUE
fi
fi
if $install_dir/$ARCH/cpath $1 2>/dev/null
then
return $TRUE
else
/bin/rm -f core
return $FALSE
fi
else
return $FALSE
fi
else
return $FALSE
fi
}
#-----------------------------------------------------------------
mk_links() {
#-----------------------------------------------------------------
#
# Make logical links of files in arg 2 dir in arg 1 dir.
#
for file in `ls -A $2`
do
if rational_loc=`is_a_rational_location $2/$file`
then
make_link $rational_loc $1/.Rational_Location
elif file_to_link=`is_a_link $2/$file`
then
make_link $file_to_link $1/$file
elif [ -d $1/$file ]
then
mk_links $1/$file $2/$file
else
make_link $2/$file $1/$file
fi
done
}
#-----------------------------------------------------------------
separator() {
#-----------------------------------------------------------------
#
# Print a line of dashes.
#
echo
echo $SEP
echo
}
#=======================================================================
# Functions to sequence the install operations.
#=======================================================================
#-----------------------------------------------------------------
more_cmd() {
#-----------------------------------------------------------------
#
# Determine which version of "more" to use.
#
if [ "$SYS_NAME" = AIX ]
then
pg -e $*
else
more $*
fi
}
#=======================================================================
# Boilerplate for the installation scripts.
#=======================================================================
#-----------------------------------------------------------------
banner() {
#-----------------------------------------------------------------
#
# Product banner
#
echo "
$1
Product: $2
Version: $3
Copyright(c) $4 by Rational."
}
#-----------------------------------------------------------------
narrate() {
#-----------------------------------------------------------------
#
# If we are not silent, then print a message to tell the user
# what's happening.
#
if [ $silent_flag -eq 0 ]
then
echo "$*"
fi
}
#------------------------------------------------------------------------
error() {
#------------------------------------------------------------------------
#
# Display Error: message.
#
fmt_mesg "$PROGNAME: Error: $*" >&2
}
#------------------------------------------------------------------------
fatal() {
#------------------------------------------------------------------------
#
# Display Error: message. and exit
#
fmt_mesg "$PROGNAME: Error: $*" >&2
exit 1
}
#------------------------------------------------------------------------
warning() {
#------------------------------------------------------------------------
#
# Display Warning: message.
#
fmt_mesg "$PROGNAME: Warning: $*" >&2
}
#------------------------------------------------------------------------
set_ord() {
#------------------------------------------------------------------------
#
# Set the variable 'ORD' to 'st', 'nd', or 'rd' for strings like:
# 1st, 2nd, 33rd, etc.
#
case $1 in
*1) echo -n st ;;
*2) echo -n nd ;;
*3) echo -n rd ;;
*[4-9]) echo -n th ;;
esac
}
#------------------------------------------------------------------------
set_s() {
#------------------------------------------------------------------------
#
# Return an 's' if arg1 not 1. This improves our grammar.
#
if [ $1 -ne 1 ]
then
echo -n "s"
fi
}
#------------------------------------------------------------------------
is_are() {
#------------------------------------------------------------------------
#
# Return 'is' if arg1 is 1. Return 'are' if arg1 not 1.
# This improves our grammar.
#
if [ $1 -eq 1 ]
then
echo -n is
else
echo -n are
fi
}
#------------------------------------------------------------------------
press_cr() {
#------------------------------------------------------------------------
#
# Wait for enter to be pressed
#
echo
echo -n "Press Return to continue. "
read enter
unset enter
}
#------------------------------------------------------------------------
# Setup traps for cleanup. Signal 0: call cleanup.
# Signal 1 2 3 and 15: call sig_cleanup.
#------------------------------------------------------------------------
trap sig_cleanup 1 2 3 4 15
trap cleanup 0
#-----------------------------------------------------------------
set_trap() {
#-----------------------------------------------------------------
#
# Function sets the trap function when interrupts or signals occur.
# Clean up on signals or interrupts.
#
trap sig_trap 1 2 3 4 15
}
#------------------------------------------------------------------------
sig_cleanup() {
#------------------------------------------------------------------------
#echo "Caught signal."
exit 1
}
#------------------------------------------------------------------------
cleanup() {
#------------------------------------------------------------------------
#
# Called on signals to delete our temporary files
#
if [ -s $install_dir/cleanup_functions.$$ ]
then
. $install_dir/cleanup_functions.$$
fi
if [ -s $install_dir/cleanup_files.$$ ]
then
. $install_dir/cleanup_files.$$
fi
/bin/rm -f $install_dir/cleanup_functions.$$ \
$install_dir/cleanup_files.$$
}
#------------------------------------------------------------------------
add_cleanup_file() {
#------------------------------------------------------------------------
#
# Append files to be deleted when exitting script.
#
echo "/bin/rm -f $*" >> $install_dir/cleanup_files.$$
}
#------------------------------------------------------------------------
add_cleanup_func() {
#------------------------------------------------------------------------
#
# Append functions to a list of functions to be called when exitting script.
#
for _funct in $*
do
echo "$_funct" >> $install_dir/cleanup_functions.$$
done
}
#------------------------------------------------------------------------
check_and_set_arch() {
#------------------------------------------------------------------------
#
# Check our architecture, set APEX_ARCH and ARCH if possible.
#
# Warning: the uname -m command on AIX does not provide a usable
# value, so we convert AIX to rs6k. Also, the machine
# kind for SPARCstation 2s is 'sun4c'. It is best
# to first use the name of the operating system before using forms
# of the uname command that are system specific.
case $SYS_NAME in
AIX)
APEX_ARCH=rs6k
;;
SunOS)
case `/bin/uname -r` in
4.*)
APEX_ARCH=sun4
;;
5.*)
APEX_ARCH=sun4_solaris
;;
*)
APEX_ARCH=UNKNOWN
;;
esac
;;
OSF1)
case `/bin/uname -m` in
alpha)
APEX_ARCH=alpha_osf
;;
*)
APEX_ARCH=UNKNOWN
;;
esac
;;
*)
APEX_ARCH=UNKNOWN
;;
esac
ARCH=$APEX_ARCH
export APEX_ARCH ARCH
if [ $APEX_ARCH = UNKNOWN ]
then
return $FALSE
else
return $TRUE
fi
}
#------------------------------------------------------------------------
system_name() {
#------------------------------------------------------------------------
#
# Return a name for arg1 or ARCH.
# if arg1 is not set assume ARCH to be set. (see check_and_set_arch)
#
case ${1:-$ARCH} in
sun4 )
echo "Sparc/SunOS"
;;
rs6k )
echo "RS/6000/AIX"
;;
alpha_osf )
echo "DEC/Alpha"
;;
sun4_solaris )
echo "Sparc/Solaris"
;;
esac
}
#------------------------------------------------------------------------
read_prod_desc() {
#------------------------------------------------------------------------
#
# Verfiy the product description file is present for this ARCH and source it.
#
if [ -r $install_dir/prod_desc.$ARCH ]
then
. $install_dir/prod_desc.$ARCH
else
fmt_mesg "The product description file is missing:
$install_dir/prod_desc.$ARCH"
fmt_mesg "The $command script cannot continue."
product_desc=`(cd $install_dir; ls prod_desc.* 2>/dev/null)`
_n=`echo $product_desc | wc -w`
if [ $_n -eq 0 ]
then
fatal There are no product description files.
elif [ $_n -eq 1 ]
then
echo You have the following product description file: $product_desc
ARCH=`echo $product_desc | sed -e "s?prod_desc\.??g"`
fatal You need to run $command from a `system_name` machine.
else
echo "You have the following product description files:"
echo $product_desc
echo "You need to run $command from one of these machine types:"
for _prod_desc in $product_desc
do
ARCH=`echo $_prod_desc | sed -e "s?prod_desc\.??g"`
echo " `system_name`"
done
exit 1
fi
fi
}
#------------------------------------------------------------------------
save_vars() {
#------------------------------------------------------------------------
#
# Save state information for a future run
# state_info must be defined before calling this function.
#
cat /dev/null > $state_info
echo "SV_VERBOSE_MODE=$SV_VERBOSE_MODE" >> $state_info
echo "SV_LIC_FILE_NAME=$SV_LIC_FILE_NAME" >> $state_info
echo "SV_VERIFY_WITH_RSH=$SV_VERIFY_WITH_RSH" >> $state_info
echo "SV_NODE_LOCKED=$SV_NODE_LOCKED" >> $state_info
echo "SV_NL_HOSTID=$SV_NL_HOSTID" >> $state_info
echo "SV_DISPLAY=$SV_DISPLAY" >> $state_info
chmod a+w $state_info 2>/dev/null
}
#------------------------------------------------------------------------
load_vars() {
#------------------------------------------------------------------------
#
# Restore state information from the previous run, or set defaults.
#
if [ -f "$state_info" ]
then
. $state_info
case "$SV_VERBOSE_MODE" in
$YES ) SV_VERBOSE_MODE=yes ;;
[Yy]* ) SV_VERBOSE_MODE=yes ;;
* ) SV_VERBOSE_MODE=no ;;
esac
case "$SV_VERIFY_WITH_RSH" in
$YES ) SV_VERIFY_WITH_RSH=yes ;;
[Yy]* ) SV_VERIFY_WITH_RSH=yes ;;
* ) SV_VERIFY_WITH_RSH=no ;;
esac
else
SV_VERBOSE_MODE=yes
SV_LIC_FILE_NAME=$APEX_LIC_FILE
SV_VERIFY_WITH_RSH=yes
SV_NODE_LOCKED=no
fi
}
#-----------------------------------------------------------------
restore_defaults() {
#-----------------------------------------------------------------
if [ -s $install_defaults.sav ]
then
mv $install_defaults.sav $install_defaults
fi
if [ -s $inst_db.sav ]
then
mv $inst_db.sav $inst_db
fi
}
# End of install_lib.