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