summaryrefslogtreecommitdiff
path: root/Makeinstall.rc
blob: c44832c2fb1235daa219031c178ce1c90741a0c6 (plain)
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
#!/bin/rc

# This script will install all executables in the current directory to $1
# Directory structure is preserved
# It stores a list of everything it has transferred / created

bin = $1

os = `uname
if (~ $os 'Linux') {
	execarg = (-executable)
} else if (~ $os 'OpenBSD') {
	execarg = (-perm 0755)
} else {
	echo unsupported os: $os >[1=2]
	exit 1
}

scripts = `$nl{find . $execarg -type f ! -name 'Make*' | grep -v '/\.' | sed 's/^\.\///'}

touch .installed .dirsmade
installed = `$nl{cat .installed}
dirsmade  = `$nl{cat .dirsmade}

# Stores lists before exiting.
# This is the last step regardless of success
fn sigexit {
	{for (s in $installed) { echo $s }} > .installed
	{for (d in $dirsmade)  { echo $d }} > .dirsmade
}

for (s in $scripts) {
	d = `$nl{dirname $s}
	if (!~ $d '.') {
		# could use mkdir -p here, however in order to actually keep a
		# list of what's been made, use a for loop

		p = $bin
		for (e in `($nl '/'){echo $d}) {
			p = $p/$e
			if (!test -d $p) {
				echo MKDIR $p
				mkdir $p || exit 1

				# add to list if not already present
				if (!~ $d $dirsmade) {
					dirsmade = ($dirsmade $d)
				}
			}
		}
	}

	if (!cmp -s $s $bin/$s) {
		echo CP $s $bin/$s
		cp $s $bin/$s
		if (!~ $s $installed) {
			installed = ($installed $s)
		}
	}
}

echo everything up to date