3 # User overridable settings
4 PREFIX
=/var
/cache
/archbuilder
5 CHROOT
=$PREFIX/chroot.$$
14 COREPKGS
="glibc pacman coreutils filesystem sudo $PACMAN_PKG" # sudo is here to have it available on archbuilder shell
15 BASEPKGS
="binutils cpio file findutils gawk gettext grep gzip less pcre perl popt ppp sed tar util-linux-ng vi wget which gcc patch pkgconfig make diffutils fakeroot"
16 CONFIGFILES
="/etc/pacman.conf /etc/resolv.conf"
22 if [ $COLOR -ne 0 ]; then
30 if [ $COLOR -ne 0 ]; then
31 echo "\e[34marchbuilder:\e[0m $*"
33 echo "archbuilder: $*"
38 if [ $COLOR -ne 0 ]; then
39 log
"\e[33m - \e[0m$*"
49 local CMD
="/bin/sh -i"
51 #echo "CHROOTCMD: /usr/sbin/chroot $CHROOT /bin/sh -c \"HOME=/root; $CMD\""
52 /usr
/sbin
/chroot
$CHROOT /bin
/sh
-c "HOME=/root; unset LANG; $CMD"
56 local F
=$CHROOT/var
/cache
/pacman
/pkg
58 test -e $F ||
return 0
61 if [ -e $F -a "$( ls $F | wc -l )" -gt 0 ]; then
63 local bn
=$
( basename $fn )
64 if ! [ -e $T/$bn ]; then
65 test "$HEADER" || log
"Caching packages"
77 rsync
-a --del $CHROOT/var
/lib
/pacman
/sync
/ $CACHE/sync
81 log
"Creating chroot ($CHROOT)"
85 mkdir
-p $CHROOT/var
/cache
/pacman
/pkg
86 mkdir
-p $CHROOT/var
/lib
/pacman
/sync
88 mknod
$CHROOT/dev
/console c
5 1
89 mknod
$CHROOT/dev
/null c
1 3
90 mknod
$CHROOT/dev
/zero c
1 5
91 mknod
$CHROOT/dev
/random c
1 8
92 mknod
$CHROOT/dev
/urandom c
1 9
94 chmod 600 $CHROOT/dev
/console
95 chmod 666 $CHROOT/dev
/{null
,zero
,random
,urandom
}
96 chmod 666 $CHROOT/dev
/{null
,zero
,random
,urandom
}
99 mount none
$CHROOT/proc
-t proc
103 log
"Restoring cached packages"
105 local T
=$CHROOT/var
/cache
/pacman
/pkg
107 #if [ -e $F -a "$( ls $F | wc -l )" -gt 0 ]; then
109 #local bn=$( basename $fn )
113 test -d $F -a $
(ls $F|
wc -l) -gt 0 && cp -l $F/* $T
117 if ! [ -e $CACHE/sync
]; then
118 error
"No sync db cache found; run archbuilder init first"
122 log
"Restoring sync db"
123 if ! cp -al $CACHE/sync
/* $CHROOT/var
/lib
/pacman
/sync
; then
124 error
"Error when restoring sync db"
131 log
"Copying config files from host"
132 for fn
in $CONFIGFILES; do
139 log
"Creating archbuilder user"
140 echo "archbuilder:x:1234:100:Arch Builder,,,:/tmp/build:/bin/sh" >> $CHROOT/etc
/passwd
141 echo "archbuilder::14117:0:99999:7:::" >> $CHROOT/etc
/shadow
142 echo "archbuilder ALL=NOPASSWD: ALL" >> $CHROOT/etc
/sudoers
143 mkdir
-p $CHROOT/tmp
/build
144 chown
1234 $CHROOT/tmp
/build
148 log
"Installing core packages"
149 if ! sh
-c "$PACMAN_BIN -S -r $CHROOT --cachedir $CHROOT/var/cache/pacman/pkg -b $CHROOT/var/lib/pacman --noconfirm $COREPKGS $SILENT"; then
150 error
"Error installing pacman, cleaning up"
168 trap - SIGINT
# Reset sigint so that if the user hammers ^C it wont loop
170 test -d $CHROOT/proc
&& umount
$CHROOT/proc
172 log
"Removing chroot"
179 log
"Installing core packages"
180 # powerpill 15.9-1 fails with this, so no $PACMAN_BIN here
181 if ! sh
-c "pacman -Sy -r $CHROOT --cachedir $CHROOT/var/cache/pacman/pkg -b $CHROOT/var/lib/pacman --noconfirm $COREPKGS $SILENT"; then
182 error
"Error installing pacman, cleaning up"
189 log
"Downloading base packages"
190 if ! chroot
"$PACMAN_BIN -Sw --noconfirm $COREPKGS $BASEPKGS $SILENT"; then
191 error
"Error downloading base packages, cleaning up"
203 log
"Downloading updates"
204 if ! chroot
"$PACMAN_BIN -Syuw --noconfirm $SILENT"; then
205 error
"Error syncing & downloading packages"
218 log
"Copying PKGBUILD and related files"
221 cp PKGBUILD
$T/PKGBUILD
223 local INSTALL
=$
( CARCH
=$
(arch
); . .
/PKGBUILD
&& echo $install )
224 if [ "$INSTALL" -a -e $INSTALL ]; then
226 cp $INSTALL $T/$INSTALL
229 local SOURCES
=$
( CARCH
=$
(arch
); . .
/PKGBUILD
&& echo ${source[*]} )
230 if [ "$SOURCES" ]; then
231 for SOURCE
in $SOURCES; do
232 if [ -e "$SOURCE" ]; then
234 cp $SOURCE $T/$SOURCE
236 if [ -e "$( basename $SOURCE )" ]; then
237 local SOURCE
=$
( basename $SOURCE )
239 cp $SOURCE $T/$SOURCE
240 elif [ "$SOURCE" = "$( basename $SOURCE )" ]; then
241 # TODO: Add --ignoremissingsource
242 error
"Source \"$SOURCE\" not found"
250 local PKGNAME
=$
( . .
/PKGBUILD
&& echo $pkgname )
251 if echo $PKGNAME |
grep -q -- '-git$'; then
252 local GITNAME
=$
( . .
/PKGBUILD
&& echo $_gitname )
253 if [ "$GITNAME" -a -d "$GITNAME" -a -d "$GITNAME/.git" ]; then
254 li
"$GITNAME git repo"
256 cp -r "$GITNAME" "$T/src"
258 elif echo $PKGNAME |
grep -q -- '-svn$'; then
259 local SVNMOD
=$
( . .
/PKGBUILD
&& echo $_svnmod )
260 if [ "$SVNMOD" -a -d "$SVNMOD" -a -d "$SVNMOD/.svn" ]; then
261 li
"$SVNMOD svn repo"
263 cp -r "$SVNMOD" "$T/src"
273 test "$OPT_COPYPKGBUILD" && copy_pkgbuild
"$CHROOT/tmp/build"
274 log
"Entering chroot"
275 chroot
"su - archbuilder"
281 if ! [ -e PKGBUILD
]; then
282 error
"No PKGBUILD file found"
288 local T
=$CHROOT/tmp
/build
292 local VERDEPENDS
=$
( . .
/PKGBUILD
&& echo ${depends[*]} ${makedepends[*]} )
293 if [ "$VERDEPENDS" ]; then
294 for DEP
in $VERDEPENDS; do
295 local DEPENDS
="$DEPENDS $( echo $DEP | sed 's,[\<|\>|\=].*$,,' )"
299 log
"Installing base packages & dependencies"
300 if ! chroot
"$PACMAN_BIN --noconfirm -S $BASEPKGS $DEPENDS $SILENT"; then
301 error
"Error installing dependencies"
306 log
"Building package"
307 if ! chroot
"su - archbuilder -c \"makepkg --noconfirm\""; then
308 error
"Error building package"
309 if [ "$OPT_SHELLONERROR" ]; then
310 log
"Invoking shell as requested"
311 chroot
"su - archbuilder"
317 local ARCH
="$( . $T/PKGBUILD && echo $arch )"
318 test $ARCH = "any" || ARCH
=$
(arch
)
319 local PKGNAME
=$
( CARCH
=$
(arch
); .
$T/PKGBUILD
&& echo $pkgname )
320 local PKGVER
=$
( CARCH
=$
(arch
); .
$T/PKGBUILD
&& echo $pkgver )
321 local PKGREL
=$
( CARCH
=$
(arch
); .
$T/PKGBUILD
&& echo $pkgrel )
322 local PKGFULL
=$PKGNAME-$PKGVER-$PKGREL-$ARCH.pkg.
tar.gz
323 if [ -e $T/$PKGFULL ]; then
324 mv $T/$PKGFULL $RESULT/$PKGFULL
325 test "$CHOWN" && chown
$CHOWN $RESULT/$PKGFULL
327 error
"Unable to find resulting package, expected $PKGFULL"
328 if [ "$OPT_SHELLONERROR" ]; then
329 log
"Invoking shell as requested"
330 chroot
"su - archbuilder"
336 if ! cmp -s $T/PKGBUILD PKGBUILD
; then
337 log
"PKGBUILD changed, copying back"
338 cp $T/PKGBUILD PKGBUILD
339 test "$CHOWN" && chown
"$CHOWN" PKGBUILD
346 if [ "$(id -u)" -ne 0 ]; then
347 error
"archbuilder must be run as root"
351 if [ $
( basename ${CACHE}x
) = "x" ]; then
352 error
"CACHE must not end with /"
356 if [ $
( basename ${CHROOT}x
) = "x" ]; then
357 error
"CHROOT must not end with /"
361 if [ $
( basename ${RESULT}x
) = "x" ]; then
362 error
"RESULT must not end with /"
366 # Test that CHROOT & CACHE is on the same filesystem and supports hard links
367 test -e "$CHROOT" || mkdir
-p "$CHROOT"
368 test -e "$CACHE" || mkdir
-p "$CACHE"
373 if [ "$( stat -c %d $CACHE/test )" -ne $
( stat
-c %d
$CHROOT/test ) ]; then
374 error
"CACHE and CHROOT must be on the same filesystem"
375 rm -f $CACHE/test $CHROOT/test $CHROOT/test2
$CACHE/test2
379 if ! ln $CACHE/test $CHROOT/test2
2>/dev
/null
>/dev
/null
; then
380 error
"Needs a filesystem that supports hard-links"
381 rm -f $CACHE/test $CHROOT/test $CHROOT/test2
$CACHE/test2
384 rm -f $CACHE/test $CHROOT/test $CHROOT/test2
$CACHE/test2
386 # Test if the filesystem supports devices
387 if ! mknod
$CHROOT/null c
1 3; then
388 error
"Chroot filesystem doesn't support devices"
391 if ! echo "test" |
tee $CHROOT/null
>/dev
/null
2>/dev
/null
; then
392 error
"Chroot filesystem doens't support devices"
398 # Test if the filesystem supports suid binaries
400 if ! chmod +s
$CHROOT/suid
; then
401 error
"Chroot filesystem doens't support suid binarys"
409 echo "ArchBuilder $VERSION"
411 echo "Usage: archbuilder command [options]"
414 echo "init - Populates sync cache"
415 echo "update - Updates sync cache"
416 echo "shell - Runs a shell in a temporary chroot"
417 echo "build - Builds a package"
420 echo " --copypkgbuild - Copies the PKGBUILD to the chroot, only for shell"
421 echo " --shellonerror - Starts a shell when the package fails to build, only for build"
422 echo " --verbose - Show pacman output"
428 --copypkgbuild) OPT_COPYPKGBUILD
=1 ;;
429 --shellonerror) OPT_SHELLONERROR
=1 ;;
430 --verbose) OPT_VERBOSE
=1 ;;
431 --help) usage
; exit 0 ;;
432 --*) error
"Unknown option \"$1\"" ; exit 1 ;;
437 if ! [ "$CMD" ]; then
442 test "$OPT_VERBOSE" && SILENT
=""
444 trap cleanup_chroot SIGINT
447 if test -e ~
/.archbuilderrc
; then
448 log
"Loading user settings (~/.archbuilderrc)"
451 log
"User settings not found (~/.archbuilderrc)"
472 error
"Unknown command: $CMD"