![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| sed behavior on hp-ux | andy2000 | Shell Programming and Scripting | 8 | 05-04-2007 10:23 PM |
| Behavior of pthreads | nhrraj | High Level Programming | 4 | 04-21-2006 04:11 AM |
| strange sed behavior | Kevin Pryke | UNIX for Dummies Questions & Answers | 5 | 06-13-2003 05:34 AM |
| ls behavior | AtleRamsli | High Level Programming | 10 | 03-26-2002 07:31 AM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Hello, I have been working on a what I thought was a fairly simple script for installing a software kit on Linux and Unix
I am not new to scripting but am far from being fluent in sh scripting. any assistance would be appreciated. I have an odd bug occuring when executing the script. When executing the script in Interactive mode A series of questions are asked. then verified. If you run the script and do not choose to use the default directory for install. for example: the question asked is Where would you like to install the software? The default is : [ /tmp/username ]" type /bin and press enter here then when asked if you are sure you want to use /bin select N for NO then change it to /var or any other dir. then proceed by selecting Y you will then be told that you have http alreayd running...( this is hardcoded with no checks yet. It is a concept) choose Y or N the script should proceed. Where I am seeing a problem is I get asked the question about http Twice ....Only when I change the default directory twice or more any idea how to prevent this ? better yet Can you explain Why it is doing this so I can prevent this from happening with other scripts ? The code below does not install anything ...it simply generates a log file at this time. Thanks again for any assistance with this bug. RobertMCol Code:
#!/bin/sh
#-----------------------------------------------------------------#
# FUNCTIONS USED BY THIS SCRIPT #
#-----------------------------------------------------------------#
usage()
{
echo "Usage: $0 [ Interactive ] [ AutoInstall ] "
echo " AutoInstall is the Prefered method for Installation "
echo
echo "--------------------------------------------------------------------"
echo "Interactive Mode:"
echo " You will be asked a series of questions regarding Installation configuration"
echo " You can press enter to these questions. Default settings will be used. "
echo " If you change a default. you will be asked to confirm the changes [ Y / N ]"
echo " You must choose Y [ for Yes ] or N [ for No ] in order to proceed "
echo
echo
echo "AutoInstall Mode: *** Prefered Method ***"
echo " This method will install the Software with all defaulted answers"
echo " This is the Preferred method for Installation."
echo " "
echo "Would you like to view the readme file for help? [ Y / N ]"
read ans
Answer=${ans}
check_ans ${Question} ${Answer}
ans1=`echo $ans |tr '[a-z]' '[A-Z]'`
if [ ${ans1} = "Y" ]
then
more readme.txt
clear
echo "Usage: $0 [ Interactive ] [ AutoInstall ] "
echo " AutoInstall is the Prefered method for Installation "
fi
echo
exit 1
}
#-----------------------------------------------------------------#
check_ans()
{
echo $Question
echo $Answer
MyQuestion=$Question
MyAnswer=$2
if [[ ! -n $Answer ]]
then
echo "${Question}"
echo "Please Choose [ Y or N ]"
return 0
fi
echo $Answer >> $LOGOUT
return 1
}
#-----------------------------------------------------------------#
directory_build()
{
# Ensure the installation root directory exists.
if [ ! -d ${INSTALL_ROOT} ]
then
mkdir -p ${INSTALL_ROOT}
if [[ $? -ne 0 ]]
then
echo "Error creating ${INSTALL_ROOT}; installation failed." | tee -a ${LOGOUT}
exit 1
fi
fi
}
#-----------------------------------------------------------------#
check_kit()
{
# Make sure we have only one webserver kit in this directory
WEBSERVER_TAR_FILE_COUNT=`ls $KIT_SEARCH_NAME | wc -l`
#echo tar file count is : $WEBSERVER_TAR_FILE_COUNT
if [ $WEBSERVER_TAR_FILE_COUNT -eq 0 ]
then
echo "No kit found. Nothing to do." |$ tee -a ${LOGOUT}
exit 1
fi
if [ $WEBSERVER_TAR_FILE_COUNT -gt 1 ]
then
echo "Multiple kits found. Remove extra files from this directory and re-run." | tee -a ${LOGOUT}
ls -l $KIT_SEARCH_NAME
exit 1
fi
# Set the name of the webserver kit.
WEBSERVER_TAR_FILE=`ls $KIT_SEARCH_NAME | head -1`
echo "${WEBSERVER_TAR_FILE} Will be used to install" | tee -a ${LOGOUT}
}
process_defaults()
{
echo "Processing Default configuration" | tee -a ${LOGOUT}
}
#-----------------------------------------------------------------#
process_interactive()
{
INSTALL_ROOT=/tmp/username
echo "Where would you like to install the software? The default is : [ /tmp/username ]" | tee -a ${LOGOUT}
read line
if [[ ! -n $line ]]
then
INSTALL_ROOT=/home/users/sbin
else
if [ ${line} != $INSTALL_ROOT ]
then
INSTALL_ROOT=$line
echo "You chose to install in the following PATH [ $line ]. Are you sure ? [Y / N] " |tee -a ${LOGOUT}
Question="Custom INSTALL_ROOT [ Y or N ]"
while read ans
do
Answer=`echo $ans |tr '[a-z]' '[A-Z]'`
check_ans ${Question} ${Answer}
if [[ $? != 0 ]]
then
break
fi
done
if [ ${Answer} != "Y" ]
then
process_interactive
fi
fi
fi
echo "INSTALLATION PATH will be [ ${INSTALL_ROOT} ]" | tee -a ${LOGOUT}
#######
echo ""
echo "I notice you have an httpd server already running"
echo "" |tee -a ${LOGOUT}
echo "Would you like to use your existing httpd server or install Shttpd for our product?" |tee -a ${LOGOUT}
echo "Use existing httpd? [ Y or N ]" |tee -a ${LOGOUT}
Question="Use existing httpd? [ Y or N ]"
while read ans
do
Answer=`echo $ans |tr '[a-z]' '[A-Z]'`
check_ans ${Question} ${Answer}
if [[ $? != 0 ]]
then
break
fi
done
if [ ${Answer} != "Y" ]
then
echo "Installing Shttpd for web client" | tee -a ${LOGOUT}
echo "" | tee -a ${LOGOUT}
else
echo "EXISTING WEB SERVER will be used" | tee -a ${LOGOUT}
echo "" | tee -a ${LOGOUT}
fi
check_kit
}
############# END OF FUNCTIONS
#-----------------------------------------------------------------#
# BEGIN MAIN PROCESSING OF SCRIPT
#-----------------------------------------------------------------#
if [ $# -eq 0 ]
then
usage
else
# DEFINE GLOBAL VARIABLES HERE
KIT_SEARCH_NAME=test.file
INSTALL_ROOT=/tmp/usersname
LOGPATH=/tmp
LOGFILE=Installation.log
LOGOUT=${LOGPATH}/${LOGFILE}
if [ -f ${LOGOUT} ]
then
echo "Logfile already exists. I Will rename to a timestamp.log"
stat_time=`stat -c "%x" ${LOGOUT} |awk -F . '{print $1}'`
logstamp=`echo ${stat_time}|awk '{print $1"_"$2}'`
mv ${LOGOUT} ${LOGPATH}/${logstamp}.${LOGFILE}
echo " ${LOGFILE} was renamed to ${LOGPATH}/${logstamp}.${LOGFILE}"
echo "----------------------------------------------------------------------"
#create new logoutfile now
touch ${LOGOUT}
echo "Created new Logfile ......continuing installation..."
echo ""
echo "Installation Process" >> ${LOGOUT}
echo "`date +%Y-%m-%d-%H:%M:%S` Begin Installation" >> ${LOGOUT}
echo ""
else
touch ${LOGOUT}
echo "Installation Process" >> ${LOGOUT}
echo "`date` Begin Installation" >> ${LOGOUT}
echo ""
fi
if [ "$1" != "Interactive" ]
then
if [ "$1" != "AutoInstall" ]
then
echo "Unknown Option"
usage
fi
INTERACTIVE=0
echo "NEED TO CONFIGURE DEFAULTS" | tee -a ${LOGOUT}
echo "Processing AutoInstall Mode of Installaion" | tee -a ${LOGOUT}
echo ""
else
echo "Processing Interactive Installaion" | tee -a ${LOGOUT}
echo ""
INTERACTIVE=1
fi
fi
#-----------------------------------------------------------------#
# Find out what OS is running
this_os=`uname -s`
case $this_os in
AIX )
ECHO_PREFIX=
ECHO_SUFFIX=\\c
;;
* )
ECHO_PREFIX=-n
ECHO_SUFFIX=
;;
esac
echo "Operating system is ${this_os}" | tee -a ${LOGOUT}
echo "" |tee -a ${LOGOUT}
#-----------------------------------------------------------------#
#-----------------------------------------------------------------#
# Make sure root user is the one executing this script
if [ "${LOGNAME}" != "root" ]
then
echo "Must be root to run $0. Current user is ${LOGNAME}" | tee -a ${LOGOUT}
exit 1
fi
#-----------------------------------------------------------------#
if [ $INTERACTIVE = "0" ]
then
process_defaults
else
process_interactive
fi
|
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|