1#!/usr/bin/ksh 2# 3# install - installer for the DTraceToolkit 4# 5# This is a fairly simple script, most of it is error checking. 6# All the script does is copy the DTraceToolkit files to another directory, 7# with various checks. The user could have copied the files themselves, this 8# script doesn't do anything special to them. It's really here in case 9# people extrace the toolkit and go looking for an installer. 10# 11# 15-May-2005 Brendan Gregg Created this. 12 13DEBUG=0 # print debug data 14TEETH=1 # does this script have teeth 15SLEEP=1 # pause on messages 16PATH=/usr/bin 17 18### Ensure we know where we are, 19dir=${0%/*} 20cd $dir 21(( DEBUG )) && print "DEBUG: dir $dir" 22 23### Print welcome, 24print "DTraceToolkit Installation\n---------------------------" 25cat Version 26print "\nhit Ctrl-C any time you wish to quit.\n\n" 27 28### Fetch location, 29print -n "Enter target directory for installation [/opt/DTT]: " 30read loc junk 31if [[ "$loc" == "" ]]; then loc="/opt/DTT"; fi 32print "" 33(( DEBUG )) && print "DEBUG: loc $loc" 34 35### Sanity check, 36if print "$loc" | grep '^[./]*$' > /dev/null; then 37 print "ERROR1: Location \"$loc\" is ambiguous.\n." 38 (( SLEEP )) && sleep 1 39 print ".\tTry a full path, like \"/opt/DTT\"\n." 40 print ".\tSorry!\n" 41 exit 1 42fi 43 44### Evilness check, 45if print "$loc" | grep '[^a-zA-Z0-9_.-/]' > /dev/null; then 46 print "ERROR2: Sorry, location \"$loc\" contains bad characters.\n." 47 (( SLEEP )) && sleep 1 48 print ".\tTry a path like \"/opt/DTT\"\n." 49 print ".\tSorry!\n" 50 exit 2 51fi 52 53### Process location, 54basename=${loc%/*} 55nodename=${loc##*/} 56if [[ "$basename" == "" ]]; then basename="/"; fi 57(( DEBUG )) && print "DEBUG: basename $basename" 58(( DEBUG )) && print "DEBUG: nodename $nodename" 59 60### Check parent dir exists, 61if [[ ! -d "$basename" ]]; then 62 print "ERROR3: Parent directory \"$basename\" does not exist!\n." 63 (( SLEEP )) && sleep 1 64 print ".\tI'm not sure what you want me to do here, if you were" 65 print ".\tserious about the above parent directory - then run" 66 print ".\ta \"mkdir -p $basename\" first, then rerun this script.\n." 67 print ".\tSorry!\n" 68 exit 3 69fi 70 71### Check parent dir perms, 72if [[ ! -w "$basename" ]]; then 73 print "ERROR4: Can't write to parent directory \"$basename\"!\n." 74 (( SLEEP )) && sleep 1 75 print ".\tSince I can't write to this directory, I can't install the" 76 print ".\tDTraceToolkit. You are currently logged in as,\n." 77 id | sed 's/^/. /' 78 print ".\n.\tand the directory has permissions,\n." 79 ls -ld "$basename" | awk '{ print ".\t\t",$1,$2,$3,$4,"..." }' 80 owner=`ls -ld "$basename" | awk '{ print $3 }'` 81 print ".\n.\tMaybe you need to run \"su - $owner\" first?\n." 82 print ".\tSorry!\n" 83 exit 4 84fi 85 86### Check if toolkit is already installed, 87if [[ -d "$loc" ]]; then 88 print "Warning: Possible old version of the DTraceToolkit found." 89 print "\tThis will DELETE the files in $loc, then install the toolkit." 90 (( SLEEP )) && sleep 1 91 if [[ ! -f "$loc/Version" ]]; then 92 print "\nWARNING: $loc doesn't look like an old DTraceToolkit!" 93 (( SLEEP )) && sleep 1 94 fi 95 print -n "\nContinue (will run \"rm -rf $loc\"). Are you sure (y/N)?: " 96 read ans junk 97 if [[ "$ans" != "y" ]]; then 98 print "\nExiting..." 99 exit 5 100 fi 101 if (( TEETH )); then 102 rm -rf "$loc" 103 else 104 print COMMAND: rm -rf \"$loc\" 105 fi 106fi 107 108### Make new toolkit dir, 109print "\nMaking directory \"$loc\"...\n" 110if (( TEETH )); then 111 mkdir -p "$loc" 112else 113 print COMMAND: mkdir -p \"$loc\" 114fi 115if [[ ! -d "$loc" || ! -w "$loc" ]]; then 116 print "ERROR6: Creation of \"$loc\" failed.\n." 117 (( SLEEP )) && sleep 1 118 print ".\tCheck directory location and try again.\n." 119 print ".\tSorry!\n" 120 exit 6 121fi 122 123### Copy files across, 124print "\nCopying DTraceToolkit files...\n" 125if (( TEETH )); then 126 tar cf - . | (cd "$loc"; tar xvf -) 127else 128 print COMMAND: "tar cf - . | (cd \"$loc\"; tar xvf -)" 129fi 130error=$? 131if [[ ! -f "$loc/install" ]]; then error=1; fi 132if (( error )); then 133 print "ERROR7: Failure during copy.\n." 134 (( SLEEP )) && sleep 1 135 print ".\tCheck source \"$dir\" and destination \"$loc\", then" 136 print ".\ttry again.\n." 137 print ".\tSorry!\n" 138 exit 7 139fi 140 141### Delete installer, 142if (( TEETH )); then 143 rm "$loc/install" 144else 145 print COMMAND: rm \"$loc/install\" 146fi 147 148### Finished, 149print "\nFinished.\n" 150print "Installed to \"$loc\". See $loc/Guide for how to get started.\n" 151 152