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