summaryrefslogtreecommitdiff
path: root/rebootstrap.sh
blob: 150f1eb79c8d096a8eea5238fd5889640413fb0a (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
63
64
65
66
67
68
69
70
71
#!/bin/sh

set -ex

if [ -z $BUILDHOSTS ]; then
	BUILDHOSTS=$HOME/src/myr/buildhosts
fi

build()
{
	host=$1
	os=$2
	wrkdir=$3
	auth=$4
	passwd=$5

	makeprg=gmake
	vcs=git
	remotecmd="ssh $host"
	setpath="mkdir -p $wrkdir/root/bin && export PATH=$PATH:$wrkdir/root/bin"
	showpatch="cd '$wrkdir/mc' && cat update.patch && rm -f update.patch"
	case $os in
	plan9)
		if echo $host | grep '@' > /dev/null; then
			user=$(echo $host | cut -d '@' -f1)
			host=$(echo $host | cut -d '@' -f2)
		fi
		if ! -z $passwd; then
			export PASS=$passwd
		fi
		makeprg=mk
		vcs=hg
		setpath="mkdir -p $wrkdir/root/bin && bind -bc $wrkdir/root/bin /amd64/bin; 
			 mkdir -p $wrkdir/root/lib && bind -bc $wrkdir/root/lib /amd64/lib;
			 mkdir -p $wrkdir/root/sys && bind -bc $wrkdir/root/sys /sys"
		buildcmd="rc -e -c 'webfs; cd $wrkdir/mc ; $setpath; 
			$makeprg bootstrap ; $makeprg install ; $makeprg clean ; git pull ;
			$makeprg genbootstrap ; $vcs diff > update.patch'"
		showpatch="cd $wrkdir/mc ; cat update.patch ; rm -f update.patch"
		remotecmd="drawterm -G -h $host -u $user -a $auth -c "
		;;
	linux|macos)
		makeprg=make
		vcs=git
		buildcmd="cd '$wrkdir/mc' && $setpath && ./configure --prefix=$wrkdir/root
			$makeprg bootstrap && $makeprg install && $makeprg clean && git pull &&
			$makeprg genbootstrap && $vcs diff > update.patch"

		;;
	*)
		buildcmd="cd '$wrkdir/mc' && $setpath && ./configure --prefix=$wrkdir/root
			$makeprg bootstrap && $makeprg install && $makeprg clean && git pull &&
			$makeprg genbootstrap && $vcs diff > update.patch"
		;;
	esac

	$remotecmd "$buildcmd"
	$remotecmd "$showpatch" | patch -p1
}

while IFS= read -r desc; do
	if ! echo $desc | grep '^#'; then
		build $desc < /dev/null
		built=1
	fi
done < $BUILDHOSTS

if [ -z "$built" ]; then
	1>&2 echo "WARNING: no hosts to build on: Please define hosts in $BUILDHOSTS, or set \$BUILDHOSTS"
fi