ddekit bump version
[pkgsrc.git] / minix / pbulk-jail.sh
1 #!/bin/sh
2
3 # Stop execution when an error occurs
4 set -e
5
6 # Certain certainties
7 RELEASE=/usr/src/releasetools/release.sh
8 PKGSRC=/usr/pkgsrc
9 PACKAGEURL="ftp://ftp.minix3.org/pub/minix/packages/`uname -r`/`uname -m`/All/"
10 PACKAGES="
11 gmp mpfr gcc44
12 scmgit-base
13 "
14 JAILROOTBASE=/usr/pbulk-jail
15 BRANCH=minix-master
16 REMOTE=pkgsrc
17 COPY=0
18 FSTYPE=mfs
19
20 # Jail-dependent vars
21 initvars() {
22 # Where to build a pbulk jail
23 if [ "$JAILDEV" ]
24 then umount $JAILDEV || true
25 echo "mkfs.$FSTYPE $JAILDEV .."
26 mkfs.$FSTYPE $JAILDEV
27 JAILROOT=$JAILROOTBASE.`basename $JAILDEV`
28 mkdir $JAILROOT || true
29 mount $JAILDEV $JAILROOT
30 else JAILROOT=$JAILROOTBASE
31 fi
32
33 # Release script used to build the jailed system
34 JAILPKGSRC=$JAILROOT/$PKGSRC
35 PBULK_SH=$PKGSRC/minix/pbulk.sh
36 JAILPBULK_SH=$JAILROOT/$PBULK_SH
37 }
38
39 # How to execute commands there
40 mychroot() {
41 chroot $JAILROOT /bin/sh -c "$*"
42 }
43
44 my_help() {
45 echo "Usage: "
46 echo " # pbulk-jail.sh [-d<dev>] [-t<fstype>] [-A] [-h] [-c]"
47 echo " "
48 echo "Jail options (USE THIS ORDER):"
49 echo " $0 -t<fstype> use mkfs.<fstype> for jail FS; e.g. mfs, ext2"
50 echo " $0 -c copy this pkgsrc tree instead of doing git clone"
51 echo " $0 -r<opts> pass <opts> to release script, e.g. -r-c"
52 echo " $0 -L<url> use <url> for packages; also -L<url> to jailopts"
53 echo " $0 -d<dev> mkfs and use <dev> for jail FS"
54 echo " "
55 echo "Jail actions (MUST BE LAST):"
56 echo " Wipe current jail, if any, build a new jail,"
57 echo " and run a full bulk build in it:"
58 echo " $0 -A"
59 echo " Keep current jail, retry the --build phase, skipping packages"
60 echo " that built successfully in the last run:"
61 echo " $0 -R"
62 }
63
64 makejail() {
65
66 # Execute jail creating script that builds a new minix
67 # in $JAILROOT from the latest git repository
68 cd `dirname $RELEASE`
69 sh `basename $RELEASE` $RELOPTS -j$JAILROOT -p
70
71 return 0
72 }
73
74 makejailpkgsrc() {
75 # Some guest preparation necessary for networking to work
76 (cd /etc
77 for f in hosts resolv.conf
78 do if [ -f $f ]
79 then cp $f $JAILROOT/etc/
80 fi
81 done
82 )
83 (cd /dev && tar cf - . ) | (cd $JAILROOT/dev ; tar xf -)
84
85 echo " * Installing packages $PACKAGES from $PACKAGEURL"
86 for p in $PACKAGES
87 do echo $p ...
88 pkg_add -f -P $JAILROOT $PACKAGEURL/$p
89 done
90
91 PKGSRCMODE=755
92 mkdir -m $PKGSRCMODE -p $JAILPKGSRC
93
94 if [ $COPY -eq 0 ]
95 then
96 # copy our own pkgsrc repository there so the new repository
97 # doesn't have to retrieve objects we already have
98 GITDIR=$JAILPKGSRC/.git
99 mkdir -m $PKGSRCMODE -p $GITDIR
100 synctree -f $PKGSRC/.git $GITDIR >/dev/null
101 ( cd $JAILPKGSRC
102 git remote rm $REMOTE || true
103 git remote add $REMOTE git://git.minix3.org/pkgsrc.git
104 git fetch $REMOTE
105 git checkout -f $REMOTE/$BRANCH
106 )
107
108 # bonus distfiles
109 mkdir -p $PKGSRC/distfiles
110 rsync -r $PKGSRC/distfiles/ $JAILPKGSRC/distfiles/
111 else # copy and use our local pkgsrc repository as it is
112 synctree -f $PKGSRC $JAILPKGSRC >/dev/null
113 fi
114
115 return 0
116 }
117
118 retrybuild() {
119 LOGFILE=jail.log
120 (
121 echo "Redirecting output to $LOGFILE"
122 exec 2>&1
123 set -x
124 echo " * Retrying the --build phase on existing jail."
125 mychroot "cd `dirname $PBULK_SH` && sh `basename $PBULK_SH` --jailed --build"
126 ) | tee $LOGFILE
127 return 0
128 }
129
130 jailall() {
131 LOGFILE=jail.log
132 (
133 echo "Redirecting output to $LOGFILE"
134 exec 2>&1
135 set -x
136 echo " * Building jail."
137 makejail
138 echo " * Building pkgsrc in jail."
139 makejailpkgsrc
140 echo " * Running bulk build."
141 mychroot "cd `dirname $PBULK_SH` && sh `basename $PBULK_SH` --jailed --all"
142 ) | tee $LOGFILE
143 rsync -r $JAILPKGSRC/distfiles/ $PKGSRC/distfiles/
144 echo "rsync -a $JAILPKGSRC/packages/ $USER@kits:/usr/local/www/docs/minix3/pkgsrc/packages/"
145 echo "rsync -a $JAILROOT/usr/pbulk-logs/ $USER@kits:/usr/local/www/docs/minix3/pkgsrc/pbulk-logs/"
146 echo "rsync -a $PKGSRC/distfiles/ $USER@kits:/usr/local/www/docs/minix3/distfiles-backup/"
147 return 0
148 }
149
150 initvars
151
152 if which rsync >/dev/null
153 then :
154 else echo rsync not found
155 exit 1
156 fi
157
158 while getopts "t:L:u:d:ARhr:cb:" opt
159 do
160 case $opt in
161 b) BRANCH=$OPTARG ;;
162 t) FSTYPE=$OPTARG; echo fstpe $FSTYPE ;;
163 c) COPY=1; ;;
164 r) RELOPTS="$RELOPTS $OPTARG";;
165 L) PACKAGEURL=$OPTARG; RELOPTS="$RELOPTS -L$PACKAGEURL";;
166 d) JAILDEV=$OPTARG; initvars; ;;
167 A) jailall; ;;
168 R) retrybuild; ;;
169 *) my_help; exit 1; ;;
170 esac
171 done
172
173 exit 0