install revision 235368
1235368Sgnn#!/usr/bin/ksh 2235368Sgnn# 3235368Sgnn# install - installer for the DTraceToolkit 4235368Sgnn# 5235368Sgnn# This is a fairly simple script, most of it is error checking. 6235368Sgnn# All the script does is copy the DTraceToolkit files to another directory, 7235368Sgnn# with various checks. The user could have copied the files themselves, this 8235368Sgnn# script doesn't do anything special to them. It's really here in case 9235368Sgnn# people extrace the toolkit and go looking for an installer. 10235368Sgnn# 11235368Sgnn# 15-May-2005 Brendan Gregg Created this. 12235368Sgnn 13235368SgnnDEBUG=0 # print debug data 14235368SgnnTEETH=1 # does this script have teeth 15235368SgnnSLEEP=1 # pause on messages 16235368SgnnPATH=/usr/bin 17235368Sgnn 18235368Sgnn### Ensure we know where we are, 19235368Sgnndir=${0%/*} 20235368Sgnncd $dir 21235368Sgnn(( DEBUG )) && print "DEBUG: dir $dir" 22235368Sgnn 23235368Sgnn### Print welcome, 24235368Sgnnprint "DTraceToolkit Installation\n---------------------------" 25235368Sgnncat Version 26235368Sgnnprint "\nhit Ctrl-C any time you wish to quit.\n\n" 27235368Sgnn 28235368Sgnn### Fetch location, 29235368Sgnnprint -n "Enter target directory for installation [/opt/DTT]: " 30235368Sgnnread loc junk 31235368Sgnnif [[ "$loc" == "" ]]; then loc="/opt/DTT"; fi 32235368Sgnnprint "" 33235368Sgnn(( DEBUG )) && print "DEBUG: loc $loc" 34235368Sgnn 35235368Sgnn### Sanity check, 36235368Sgnnif print "$loc" | grep '^[./]*$' > /dev/null; then 37235368Sgnn print "ERROR1: Location \"$loc\" is ambiguous.\n." 38235368Sgnn (( SLEEP )) && sleep 1 39235368Sgnn print ".\tTry a full path, like \"/opt/DTT\"\n." 40235368Sgnn print ".\tSorry!\n" 41235368Sgnn exit 1 42235368Sgnnfi 43235368Sgnn 44235368Sgnn### Evilness check, 45235368Sgnnif print "$loc" | grep '[^a-zA-Z0-9_.-/]' > /dev/null; then 46235368Sgnn print "ERROR2: Sorry, location \"$loc\" contains bad characters.\n." 47235368Sgnn (( SLEEP )) && sleep 1 48235368Sgnn print ".\tTry a path like \"/opt/DTT\"\n." 49235368Sgnn print ".\tSorry!\n" 50235368Sgnn exit 2 51235368Sgnnfi 52235368Sgnn 53235368Sgnn### Process location, 54235368Sgnnbasename=${loc%/*} 55235368Sgnnnodename=${loc##*/} 56235368Sgnnif [[ "$basename" == "" ]]; then basename="/"; fi 57235368Sgnn(( DEBUG )) && print "DEBUG: basename $basename" 58235368Sgnn(( DEBUG )) && print "DEBUG: nodename $nodename" 59235368Sgnn 60235368Sgnn### Check parent dir exists, 61235368Sgnnif [[ ! -d "$basename" ]]; then 62235368Sgnn print "ERROR3: Parent directory \"$basename\" does not exist!\n." 63235368Sgnn (( SLEEP )) && sleep 1 64235368Sgnn print ".\tI'm not sure what you want me to do here, if you were" 65235368Sgnn print ".\tserious about the above parent directory - then run" 66235368Sgnn print ".\ta \"mkdir -p $basename\" first, then rerun this script.\n." 67235368Sgnn print ".\tSorry!\n" 68235368Sgnn exit 3 69235368Sgnnfi 70235368Sgnn 71235368Sgnn### Check parent dir perms, 72235368Sgnnif [[ ! -w "$basename" ]]; then 73235368Sgnn print "ERROR4: Can't write to parent directory \"$basename\"!\n." 74235368Sgnn (( SLEEP )) && sleep 1 75235368Sgnn print ".\tSince I can't write to this directory, I can't install the" 76235368Sgnn print ".\tDTraceToolkit. You are currently logged in as,\n." 77235368Sgnn id | sed 's/^/. /' 78235368Sgnn print ".\n.\tand the directory has permissions,\n." 79235368Sgnn ls -ld "$basename" | awk '{ print ".\t\t",$1,$2,$3,$4,"..." }' 80235368Sgnn owner=`ls -ld "$basename" | awk '{ print $3 }'` 81235368Sgnn print ".\n.\tMaybe you need to run \"su - $owner\" first?\n." 82235368Sgnn print ".\tSorry!\n" 83235368Sgnn exit 4 84235368Sgnnfi 85235368Sgnn 86235368Sgnn### Check if toolkit is already installed, 87235368Sgnnif [[ -d "$loc" ]]; then 88235368Sgnn print "Warning: Possible old version of the DTraceToolkit found." 89235368Sgnn print "\tThis will DELETE the files in $loc, then install the toolkit." 90235368Sgnn (( SLEEP )) && sleep 1 91235368Sgnn if [[ ! -f "$loc/Version" ]]; then 92235368Sgnn print "\nWARNING: $loc doesn't look like an old DTraceToolkit!" 93235368Sgnn (( SLEEP )) && sleep 1 94235368Sgnn fi 95235368Sgnn print -n "\nContinue (will run \"rm -rf $loc\"). Are you sure (y/N)?: " 96235368Sgnn read ans junk 97235368Sgnn if [[ "$ans" != "y" ]]; then 98235368Sgnn print "\nExiting..." 99235368Sgnn exit 5 100235368Sgnn fi 101235368Sgnn if (( TEETH )); then 102235368Sgnn rm -rf "$loc" 103235368Sgnn else 104235368Sgnn print COMMAND: rm -rf \"$loc\" 105235368Sgnn fi 106235368Sgnnfi 107235368Sgnn 108235368Sgnn### Make new toolkit dir, 109235368Sgnnprint "\nMaking directory \"$loc\"...\n" 110235368Sgnnif (( TEETH )); then 111235368Sgnn mkdir -p "$loc" 112235368Sgnnelse 113235368Sgnn print COMMAND: mkdir -p \"$loc\" 114235368Sgnnfi 115235368Sgnnif [[ ! -d "$loc" || ! -w "$loc" ]]; then 116235368Sgnn print "ERROR6: Creation of \"$loc\" failed.\n." 117235368Sgnn (( SLEEP )) && sleep 1 118235368Sgnn print ".\tCheck directory location and try again.\n." 119235368Sgnn print ".\tSorry!\n" 120235368Sgnn exit 6 121235368Sgnnfi 122235368Sgnn 123235368Sgnn### Copy files across, 124235368Sgnnprint "\nCopying DTraceToolkit files...\n" 125235368Sgnnif (( TEETH )); then 126235368Sgnn tar cf - . | (cd "$loc"; tar xvf -) 127235368Sgnnelse 128235368Sgnn print COMMAND: "tar cf - . | (cd \"$loc\"; tar xvf -)" 129235368Sgnnfi 130235368Sgnnerror=$? 131235368Sgnnif [[ ! -f "$loc/install" ]]; then error=1; fi 132235368Sgnnif (( error )); then 133235368Sgnn print "ERROR7: Failure during copy.\n." 134235368Sgnn (( SLEEP )) && sleep 1 135235368Sgnn print ".\tCheck source \"$dir\" and destination \"$loc\", then" 136235368Sgnn print ".\ttry again.\n." 137235368Sgnn print ".\tSorry!\n" 138235368Sgnn exit 7 139235368Sgnnfi 140235368Sgnn 141235368Sgnn### Delete installer, 142235368Sgnnif (( TEETH )); then 143235368Sgnn rm "$loc/install" 144235368Sgnnelse 145235368Sgnn print COMMAND: rm \"$loc/install\" 146235368Sgnnfi 147235368Sgnn 148235368Sgnn### Finished, 149235368Sgnnprint "\nFinished.\n" 150235368Sgnnprint "Installed to \"$loc\". See $loc/Guide for how to get started.\n" 151235368Sgnn 152