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