1N/A#!/usr/bin/ksh
1N/A#
1N/A# install - installer for the DTraceToolkit
1N/A#
1N/A# This is a fairly simple script, most of it is error checking.
1N/A# All the script does is copy the DTraceToolkit files to another directory,
1N/A# with various checks. The user could have copied the files themselves, this
1N/A# script doesn't do anything special to them. It's really here in case
1N/A# people extrace the toolkit and go looking for an installer.
1N/A#
1N/A# 15-May-2005 Brendan Gregg Created this.
1N/A
1N/ADEBUG=0 # print debug data
1N/ATEETH=1 # does this script have teeth
1N/ASLEEP=1 # pause on messages
1N/APATH=/usr/bin
1N/A
1N/A### Ensure we know where we are,
1N/Adir=${0%/*}
1N/Acd $dir
1N/A(( DEBUG )) && print "DEBUG: dir $dir"
1N/A
1N/A### Print welcome,
1N/Aprint "DTraceToolkit Installation\n---------------------------"
1N/Acat Version
1N/Aprint "\nhit Ctrl-C any time you wish to quit.\n\n"
1N/A
1N/A### Fetch location,
1N/Aprint -n "Enter target directory for installation [/opt/DTT]: "
1N/Aread loc junk
1N/Aif [[ "$loc" == "" ]]; then loc="/opt/DTT"; fi
1N/Aprint ""
1N/A(( DEBUG )) && print "DEBUG: loc $loc"
1N/A
1N/A### Sanity check,
1N/Aif print "$loc" | grep '^[./]*$' > /dev/null; then
1N/A print "ERROR1: Location \"$loc\" is ambiguous.\n."
1N/A (( SLEEP )) && sleep 1
1N/A print ".\tTry a full path, like \"/opt/DTT\"\n."
1N/A print ".\tSorry!\n"
1N/A exit 1
1N/Afi
1N/A
1N/A### Evilness check,
1N/Aif print "$loc" | grep '[^a-zA-Z0-9_.-/]' > /dev/null; then
1N/A print "ERROR2: Sorry, location \"$loc\" contains bad characters.\n."
1N/A (( SLEEP )) && sleep 1
1N/A print ".\tTry a path like \"/opt/DTT\"\n."
1N/A print ".\tSorry!\n"
1N/A exit 2
1N/Afi
1N/A
1N/A### Process location,
1N/Abasename=${loc%/*}
1N/Anodename=${loc##*/}
1N/Aif [[ "$basename" == "" ]]; then basename="/"; fi
1N/A(( DEBUG )) && print "DEBUG: basename $basename"
1N/A(( DEBUG )) && print "DEBUG: nodename $nodename"
1N/A
1N/A### Check parent dir exists,
1N/Aif [[ ! -d "$basename" ]]; then
1N/A print "ERROR3: Parent directory \"$basename\" does not exist!\n."
1N/A (( SLEEP )) && sleep 1
1N/A print ".\tI'm not sure what you want me to do here, if you were"
1N/A print ".\tserious about the above parent directory - then run"
1N/A print ".\ta \"mkdir -p $basename\" first, then rerun this script.\n."
1N/A print ".\tSorry!\n"
1N/A exit 3
1N/Afi
1N/A
1N/A### Check parent dir perms,
1N/Aif [[ ! -w "$basename" ]]; then
1N/A print "ERROR4: Can't write to parent directory \"$basename\"!\n."
1N/A (( SLEEP )) && sleep 1
1N/A print ".\tSince I can't write to this directory, I can't install the"
1N/A print ".\tDTraceToolkit. You are currently logged in as,\n."
1N/A id | sed 's/^/. /'
1N/A print ".\n.\tand the directory has permissions,\n."
1N/A ls -ld "$basename" | awk '{ print ".\t\t",$1,$2,$3,$4,"..." }'
1N/A owner=`ls -ld "$basename" | awk '{ print $3 }'`
1N/A print ".\n.\tMaybe you need to run \"su - $owner\" first?\n."
1N/A print ".\tSorry!\n"
1N/A exit 4
1N/Afi
1N/A
1N/A### Check if toolkit is already installed,
1N/Aif [[ -d "$loc" ]]; then
1N/A print "Warning: Possible old version of the DTraceToolkit found."
1N/A print "\tThis will DELETE the files in $loc, then install the toolkit."
1N/A (( SLEEP )) && sleep 1
1N/A if [[ ! -f "$loc/Version" ]]; then
1N/A print "\nWARNING: $loc doesn't look like an old DTraceToolkit!"
1N/A (( SLEEP )) && sleep 1
1N/A fi
1N/A print -n "\nContinue (will run \"rm -rf $loc\"). Are you sure (y/N)?: "
1N/A read ans junk
1N/A if [[ "$ans" != "y" ]]; then
1N/A print "\nExiting..."
1N/A exit 5
1N/A fi
1N/A if (( TEETH )); then
1N/A rm -rf "$loc"
1N/A else
1N/A print COMMAND: rm -rf \"$loc\"
1N/A fi
1N/Afi
1N/A
1N/A### Make new toolkit dir,
1N/Aprint "\nMaking directory \"$loc\"...\n"
1N/Aif (( TEETH )); then
1N/A mkdir -p "$loc"
1N/Aelse
1N/A print COMMAND: mkdir -p \"$loc\"
1N/Afi
1N/Aif [[ ! -d "$loc" || ! -w "$loc" ]]; then
1N/A print "ERROR6: Creation of \"$loc\" failed.\n."
1N/A (( SLEEP )) && sleep 1
1N/A print ".\tCheck directory location and try again.\n."
1N/A print ".\tSorry!\n"
1N/A exit 6
1N/Afi
1N/A
1N/A### Copy files across,
1N/Aprint "\nCopying DTraceToolkit files...\n"
1N/Aif (( TEETH )); then
1N/A tar cf - . | (cd "$loc"; tar xvf -)
1N/Aelse
1N/A print COMMAND: "tar cf - . | (cd \"$loc\"; tar xvf -)"
1N/Afi
1N/Aerror=$?
1N/Aif [[ ! -f "$loc/install" ]]; then error=1; fi
1N/Aif (( error )); then
1N/A print "ERROR7: Failure during copy.\n."
1N/A (( SLEEP )) && sleep 1
1N/A print ".\tCheck source \"$dir\" and destination \"$loc\", then"
1N/A print ".\ttry again.\n."
1N/A print ".\tSorry!\n"
1N/A exit 7
1N/Afi
1N/A
1N/A### Delete installer,
1N/Aif (( TEETH )); then
1N/A rm "$loc/install"
1N/Aelse
1N/A print COMMAND: rm \"$loc/install\"
1N/Afi
1N/A
1N/A### Finished,
1N/Aprint "\nFinished.\n"
1N/Aprint "Installed to \"$loc\". See $loc/Guide for how to get started.\n"
1N/A