ddekit bump version
[pkgsrc.git] / minix / pbulk.sh
1 #!/bin/sh
2
3 #####
4 ##
5 ## Minix pBulk Bootstrap Script
6 ##
7 #####
8
9 # Stop execution when an error occurs
10 set -e
11 set -x
12
13 # Set output verbosity (0=quiet, 1=normal, 2=debug)
14 PKG_DEBUG_LEVEL=2
15
16 # This is set if we are running from a jail hierarchy.
17 # If so, we don't have to be too careful with wiping out
18 # directories; we are running in a throw-away, reproducible
19 # environment.
20 JAILED=0
21
22 pbulksh_help() {
23 echo "Usage: "
24 echo " $0 --fetch Pre-fetch distfiles"
25 echo " $0 --bootstrap Do the initial bootstrap"
26 echo " $0 --backup Backup /usr/pkg to a safe place"
27 echo " $0 --bin-kit Create a binary kit"
28 echo " $0 --build Execute bulkbuild"
29 echo " $0 --restore Restore /usr/pkg"
30 echo " $0 --all Do all steps mentioned above (except fetch)"
31 echo " $0 --help Display this message"
32 }
33
34 # Run `bmake fetch` for every package in limited_list.pbulk. Potential uses:
35 # making a (local) distfiles mirror for all Minix packages.
36 # downloading the distfiles once and then using them for multiple jails.
37 # decreasing the chances of a pkg failing due to fetch errors during a build.
38 pbulksh_fetch() {
39
40 for pkg in $(cat limited_list.pbulk)
41 do
42 cd ../${pkg}
43 bmake fetch
44 cd ../../minix
45 done
46 }
47
48 # Preparation -- bootstraps a pkgsrc installation into /usr/pbulk
49 pbulksh_bootstrap() {
50
51 dirs="/usr/pbulk /usr/pbulk-packages /usr/tmp/pbulk-bootstrap /usr/tmp/pbulk-outer /usr/pbulk-logs /usr/pkgsrc/packages/$(uname -r)/"
52
53 if [ $JAILED = 1 ]
54 then rm -rf $dirs
55 fi
56
57 for d in $dirs
58 do if [ -d $d ]
59 then echo "$d exists."
60 echo "please remove all of $dirs"
61 echo "Then re-run me."
62 exit 1
63 fi
64 done
65
66 cd /usr/pkgsrc
67
68
69 # Trim the .ifdef BSD_PKG_MK and .endif lines to make a "fragment"
70 # and adapt a few path to the ones expected for pbulk
71 sed \
72 -e '/.*BSD_PKG_MK/d' \
73 -e 's@LOCALBASE?=.*@LOCALBASE= /usr/pbulk@' \
74 -e 's@VARBASE?=.*@VARBASE= /usr/pbulk/var@' \
75 -e 's@PKG_DBDIR?=.*@PKG_DBDIR= /usr/pbulk/.pkgdb@' \
76 -e 's@WRKOBJDIR?=.*@WRKOBJDIR= /usr/tmp/pbulk-outer@' \
77 /usr/pkgsrc/minix/mk.conf.minix \
78 > /usr/pkgsrc/minix/mk.conf.minix.pbulk
79
80 env CFLAGS="-march=i586" sh ./bootstrap/bootstrap --prefix=/usr/pbulk \
81 --varbase=/usr/pbulk/var \
82 --workdir=/usr/tmp/pbulk-bootstrap \
83 --pkgdbdir=/usr/pbulk/.pkgdb \
84 --mk-fragment=/usr/pkgsrc/minix/mk.conf.minix.pbulk
85
86 rm -rf /usr/tmp/pbulk-bootstrap
87 rm -rf /usr/pkgsrc/packages/$(uname -r)/
88
89 # Install pbulk into /usr/pbulk
90 cd /usr/pkgsrc/pkgtools/pbulk
91 env PATH=/usr/pbulk/bin:/usr/pbulk/sbin:${PATH} bmake install package
92 sed -e 's/OP_SYS_VER/'$(uname -r)'/g' /usr/pkgsrc/minix/pbulk.conf > /usr/pbulk/etc/pbulk.conf
93 }
94
95 # In order to build proper packages, we need to work in /usr/pkg.
96 # Here, we back up /usr/pkg as well as VARBASE.
97 pbulksh_backup() {
98
99 dirs="/usr/pkg.sav /usr/var.sav"
100 for d in $dirs
101 do if [ -d $d ]
102 then echo "$d exists."
103 echo "Did you already run --backup?"
104 exit 1
105 fi
106 done
107
108 mv /usr/pkg /usr/pkg.sav
109 mkdir /usr/pkg
110 mv /usr/var /usr/var.sav
111 mkdir /usr/var
112
113 # Fix symlinks
114 ln -sf /usr/pkg.sav/bin/clang /usr/bin/cc
115 ln -sf /usr/pkg.sav/bin/strip /usr/bin/strip
116 }
117
118 # Create a bootstrap a binary kit. pbulk needs this.
119 pbulksh_bin_kit() {
120
121 dirs="/usr/pkg.sav /usr/var.sav"
122 for d in $dirs
123 do if [ ! -d $d ]
124 then echo "$d doesn't exist."
125 echo "Re-run with --backup to back it up"
126 exit 1
127 fi
128 done
129
130 cd /usr/pkgsrc
131 rm -f /usr/pkgsrc/bootstrap/bootstrap.tar.gz
132 sh ./bootstrap/cleanup
133
134 # Trim the .ifdef BSD_PKG_MK and .endif lines to make a "fragment"
135 sed -e '/ifdef.*BSD_PKG_MK/d;$d' /usr/pkgsrc/minix/mk.conf.minix > /usr/pkgsrc/minix/mk.conf.minix.frag
136
137 env PATH=/usr/pbulk/bin:/usr/pbulk/sbin:/usr/pkg.sav/gcc44/bin:/usr/pkg.sav/bin:/usr/pkg.sav/sbin:${PATH} CFLAGS="-march=i586" LD_LIBRARY_PATH=/usr/pkg.sav/lib sh ./bootstrap/bootstrap \
138 --mk-fragment=/usr/pkgsrc/minix/mk.conf.minix.frag \
139 --gzip-binary-kit=/usr/pkgsrc/bootstrap/bootstrap.tar.gz \
140 --varbase=/usr/var \
141 --pkgdbdir=/usr/var/db/pkg
142 rm -f /usr/pkgsrc/minix/mk.conf.minix.frag
143
144 rm -rf /usr/pbulk-packages
145 rm -rf /usr/pkgsrc/packages/$(uname -r)/
146
147 # Use the same mk.conf that our users instead of the hybrid auto-generated mk.conf from bootstrap
148 cd /usr/pkgsrc/bootstrap
149 mkdir temp
150 mv bootstrap.tar.gz temp
151 cd temp
152 tar xzf bootstrap.tar.gz
153 cp /usr/pkgsrc/minix/mk.conf.minix usr/pkg/etc/mk.conf
154 tar hzcf ../bootstrap.tar.gz usr
155 cd ..
156 rm -rf temp
157 cd /usr/pkgsrc
158 }
159
160 # Perform the bulk build. Most configuration is in pbulk.conf
161 pbulksh_build() {
162
163
164 if [ ! -f /usr/pkgsrc/bootstrap/bootstrap.tar.gz ]
165 then
166 echo "/usr/pkgsrc/bootstrap/bootstrap.tar.gz doesn't exist"
167 echo "Re-run with --bin-kit to create it"
168 exit 1
169 fi
170
171 if [ ! -d /usr/pbulk ]
172 then
173 echo "/usr/pbulk doesn't exist"
174 echo "Re-run with --bootstrap to create it"
175 exit 1
176 fi
177
178 env PATH=/bin:/sbin:/usr/pkg.sav/bin:/usr/pkg.sav/sbin:/usr/bin:/usr/sbin:/usr/pbulk/bin:/usr/pbulk/sbin:/usr/pkg.sav/gcc44/bin:${PATH} LD_LIBRARY_PATH=/usr/pkg.sav/lib /usr/pbulk/bin/bulkbuild
179 }
180
181 # Restore the backed up /usr/pkg and /usr/var
182 pbulksh_restore() {
183
184 dirs="/usr/pkg.sav /usr/var.sav"
185 for d in $dirs
186 do if [ ! -d $d ]
187 then echo "$d doesn't exist."
188 echo "Can't restore without it."
189 exit 1
190 fi
191 done
192
193 rm -rf /usr/pkg
194 mv /usr/pkg.sav /usr/pkg
195 rm -rf /usr/var
196 mv /usr/var.sav /usr/var
197
198 # Fix symlinks
199 ln -sf /usr/pkg/bin/clang /usr/bin/cc
200 ln -sf /usr/pkg/bin/strip /usr/bin/strip
201 }
202
203 pbulksh_all() {
204
205 pbulksh_bootstrap
206 pbulksh_backup
207 pbulksh_bin_kit
208 pbulksh_build
209 pbulksh_restore
210 }
211
212 if [ $1 = --jailed ]
213 then JAILED=1
214 shift
215 fi
216
217 case $1 in
218 "--fetch") pbulksh_fetch; break;;
219 "--bootstrap") pbulksh_bootstrap; break;;
220 "--backup") pbulksh_backup; break;;
221 "--bin-kit") pbulksh_bin_kit; break;;
222 "--build") pbulksh_build; break;;
223 "--restore") pbulksh_restore; break;;
224 "--all") pbulksh_all; break;;
225 "--help") pbulksh_help; break;;
226 *) pbulksh_help; break;;
227 esac