install revision 1.1.1.1 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
13 DEBUG=0 # print debug data
14 TEETH=1 # does this script have teeth
15 SLEEP=1 # pause on messages
16 PATH=/usr/bin
17
18 ### Ensure we know where we are,
19 dir=${0%/*}
20 cd $dir
21 (( DEBUG )) && print "DEBUG: dir $dir"
22
23 ### Print welcome,
24 print "DTraceToolkit Installation\n---------------------------"
25 cat Version
26 print "\nhit Ctrl-C any time you wish to quit.\n\n"
27
28 ### Fetch location,
29 print -n "Enter target directory for installation [/opt/DTT]: "
30 read loc junk
31 if [[ "$loc" == "" ]]; then loc="/opt/DTT"; fi
32 print ""
33 (( DEBUG )) && print "DEBUG: loc $loc"
34
35 ### Sanity check,
36 if 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
42 fi
43
44 ### Evilness check,
45 if 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
51 fi
52
53 ### Process location,
54 basename=${loc%/*}
55 nodename=${loc##*/}
56 if [[ "$basename" == "" ]]; then basename="/"; fi
57 (( DEBUG )) && print "DEBUG: basename $basename"
58 (( DEBUG )) && print "DEBUG: nodename $nodename"
59
60 ### Check parent dir exists,
61 if [[ ! -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
69 fi
70
71 ### Check parent dir perms,
72 if [[ ! -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
84 fi
85
86 ### Check if toolkit is already installed,
87 if [[ -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
106 fi
107
108 ### Make new toolkit dir,
109 print "\nMaking directory \"$loc\"...\n"
110 if (( TEETH )); then
111 mkdir -p "$loc"
112 else
113 print COMMAND: mkdir -p \"$loc\"
114 fi
115 if [[ ! -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
121 fi
122
123 ### Copy files across,
124 print "\nCopying DTraceToolkit files...\n"
125 if (( TEETH )); then
126 tar cf - . | (cd "$loc"; tar xvf -)
127 else
128 print COMMAND: "tar cf - . | (cd \"$loc\"; tar xvf -)"
129 fi
130 error=$?
131 if [[ ! -f "$loc/install" ]]; then error=1; fi
132 if (( 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
139 fi
140
141 ### Delete installer,
142 if (( TEETH )); then
143 rm "$loc/install"
144 else
145 print COMMAND: rm \"$loc/install\"
146 fi
147
148 ### Finished,
149 print "\nFinished.\n"
150 print "Installed to \"$loc\". See $loc/Guide for how to get started.\n"
151
152