2011-01-25 03:01:05 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2013-10-25 07:26:05 +00:00
|
|
|
program_version=@VERSION@
|
2011-01-25 03:01:05 +00:00
|
|
|
sysconfdir=@sysconfdir@
|
|
|
|
abuildrepo=/var/lib/buildlab/result
|
2019-11-07 11:28:37 +00:00
|
|
|
sharedir=${ABUILD_SHAREDIR:-@sharedir@}
|
2011-01-25 03:01:05 +00:00
|
|
|
|
|
|
|
BUILD_BASE="build-base"
|
|
|
|
SUDO=${SUDO:-"sudo"}
|
|
|
|
FAKEROOT=${FAKEROOT:-"fakeroot"}
|
|
|
|
APK=${APK:-apk}
|
|
|
|
|
2011-01-25 03:06:04 +00:00
|
|
|
# read config
|
|
|
|
ABUILD_CONF=${ABUILD_CONF:-"$sysconfdir/abuild.conf"}
|
|
|
|
[ -f "$ABUILD_CONF" ] && . "$ABUILD_CONF"
|
|
|
|
|
2011-01-25 03:01:05 +00:00
|
|
|
default_colors() {
|
2016-08-20 13:07:30 +00:00
|
|
|
NORMAL="\033[1;0m"
|
|
|
|
STRONG="\033[1;1m"
|
|
|
|
RED="\033[1;31m"
|
|
|
|
GREEN="\033[1;32m"
|
|
|
|
YELLOW="\033[1;33m"
|
|
|
|
BLUE="\033[1;34m"
|
2011-01-25 03:01:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
default_colors
|
|
|
|
|
|
|
|
is_local() {
|
2016-08-20 13:07:30 +00:00
|
|
|
case "$1" in
|
|
|
|
http://*|ftp://*|https://*|saveas-*://*)
|
|
|
|
return 1;;
|
|
|
|
esac
|
|
|
|
return 0
|
2011-01-25 03:01:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
msg() {
|
|
|
|
local prompt="$GREEN>>>${NORMAL}"
|
2016-08-20 13:07:30 +00:00
|
|
|
[ -z "$quiet" ] && printf "${prompt} $@\n" >&2
|
2011-01-25 03:01:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
error() {
|
|
|
|
local prompt="$RED>>>${NORMAL}"
|
2016-08-20 13:07:30 +00:00
|
|
|
printf "${prompt} $@\n" >&2
|
2011-01-25 03:01:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
die() {
|
|
|
|
error "$@"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
runpart() {
|
2016-08-20 13:07:30 +00:00
|
|
|
local part=$1
|
2011-01-25 03:01:05 +00:00
|
|
|
msg "Running part $part"
|
2016-08-20 13:07:30 +00:00
|
|
|
$part || die "$part failed"
|
2011-01-25 03:01:05 +00:00
|
|
|
}
|
|
|
|
|
2011-09-30 06:42:58 +00:00
|
|
|
is_vserver() {
|
2022-09-12 15:20:47 +00:00
|
|
|
grep -E -q '^VxID:[[:space:]]*[0-9]+' /proc/self/status
|
2011-09-30 06:42:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
do_chroot_open() {
|
|
|
|
local path="$1"
|
|
|
|
if is_vserver; then
|
|
|
|
# vserver does not allow us mount or create devices
|
|
|
|
# but we can create hard links as long as chroot is
|
|
|
|
# on same filesystem as real root
|
|
|
|
rmdir "$path"/proc "$path"/sys "$path"/dev 2>/dev/null
|
|
|
|
ln /dev "$path"/dev
|
|
|
|
ln /proc "$path"/proc
|
|
|
|
ln /sys "$path"/sys
|
|
|
|
|
|
|
|
else
|
|
|
|
mkdir -p "$path"/dev "$path"/proc "$path"/sys
|
|
|
|
mount -o bind /dev "$path"/dev || return 1
|
|
|
|
mount -o bind /proc "$path"/proc
|
|
|
|
mount -o bind /sys "$path"/sys
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
do_chroot_close() {
|
|
|
|
local path="$1"
|
|
|
|
if is_vserver; then
|
|
|
|
rmdir "$path"/dev "$path"/proc "$path"/sys
|
|
|
|
else
|
|
|
|
umount "$path"/dev "$path"/proc "$path"/sys
|
|
|
|
fi
|
|
|
|
}
|
2011-06-22 14:51:41 +00:00
|
|
|
|
2011-01-25 03:01:05 +00:00
|
|
|
do_chroot_action() {
|
|
|
|
local path="$1"
|
|
|
|
local command="$2"
|
|
|
|
|
|
|
|
msg "Doing chroot action '$command' in '$path'..."
|
|
|
|
|
2011-09-30 06:42:58 +00:00
|
|
|
do_chroot_open "$path" || return 1
|
2011-01-25 03:01:05 +00:00
|
|
|
shift;
|
|
|
|
|
|
|
|
# XXX: we have to do this because busybox clobbers us, bleah.
|
|
|
|
echo $* > "$path"/.chroot-action.sh
|
|
|
|
chroot "$path" /bin/sh /.chroot-action.sh
|
|
|
|
rm "$path"/.chroot-action.sh
|
|
|
|
|
2011-09-30 06:42:58 +00:00
|
|
|
do_chroot_close
|
2011-01-25 03:01:05 +00:00
|
|
|
}
|
|
|
|
|
2011-01-25 03:06:04 +00:00
|
|
|
update_chroot() {
|
|
|
|
local path="$1"
|
|
|
|
|
|
|
|
apk --root $path --repositories "$path"/etc/apk/repositories update
|
|
|
|
apk --root $path --repositories "$path"/etc/apk/repositories upgrade -a
|
|
|
|
}
|
|
|
|
|
2011-01-25 03:01:05 +00:00
|
|
|
prepare_chroot() {
|
|
|
|
local path="$1"
|
|
|
|
local version="$2"
|
|
|
|
local mirror="$3"
|
|
|
|
local arch="$4"
|
2011-03-30 02:46:37 +00:00
|
|
|
local enablecache="$5"
|
2011-01-25 03:01:05 +00:00
|
|
|
|
|
|
|
msg "Setting up repositories for mirror $mirror with version $version at $path..."
|
|
|
|
|
|
|
|
mkdir -p "$path"/etc/apk
|
2011-06-22 15:12:43 +00:00
|
|
|
echo "http://$mirror/alpine/$version/main" >> "$path"/etc/apk/repositories
|
|
|
|
echo "http://$mirror/alpine/$version/testing" >> "$path"/etc/apk/repositories
|
2011-01-25 03:01:05 +00:00
|
|
|
|
2011-03-30 02:46:37 +00:00
|
|
|
if [ ! -z "$enablecache" ]; then
|
|
|
|
mkdir -p "$path"/var/cache/apk
|
|
|
|
ln -s /var/cache/apk "$path"/etc/apk/cache
|
|
|
|
fi
|
|
|
|
|
2011-06-22 15:12:43 +00:00
|
|
|
echo "alpine-base" > "$path"/etc/apk/world
|
|
|
|
mkdir -p "$path"/lib/apk/db
|
|
|
|
mkdir -p "$path"/var/lock
|
|
|
|
mkdir -p "$path"/var/cache/apk
|
|
|
|
mkdir -p "$path"/tmp
|
2011-01-25 03:01:05 +00:00
|
|
|
|
|
|
|
mkdir -p "$path"/etc
|
|
|
|
cp /etc/resolv.conf "$path"/etc/resolv.conf
|
|
|
|
|
|
|
|
msg "Updating package lists..."
|
|
|
|
|
2011-06-22 15:12:43 +00:00
|
|
|
apk --arch $buildarch --root $path --repositories "$path"/etc/apk/repositories update
|
2011-01-25 03:01:05 +00:00
|
|
|
|
|
|
|
msg "Installing alpine-base..."
|
|
|
|
|
2011-06-22 15:12:43 +00:00
|
|
|
apk --arch $buildarch --root $path --repositories "$path"/etc/apk/repositories add --initdb alpine-base
|
2011-01-25 03:01:05 +00:00
|
|
|
|
|
|
|
msg "Installing abuild..."
|
|
|
|
|
2011-06-22 15:12:43 +00:00
|
|
|
apk --arch $buildarch --root $path --repositories "$path"/etc/apk/repositories add --initdb abuild
|
2011-01-25 03:01:05 +00:00
|
|
|
|
|
|
|
msg "Installing build-base..."
|
|
|
|
|
2011-06-22 15:12:43 +00:00
|
|
|
apk --arch $buildarch --root $path --repositories "$path"/etc/apk/repositories add --initdb build-base
|
2011-01-25 03:01:05 +00:00
|
|
|
|
|
|
|
msg "Adding abuild user..."
|
|
|
|
|
|
|
|
do_chroot_action "$path" adduser -D -G abuild abuild
|
|
|
|
echo "abuild ALL=NOPASSWD: ALL" >> "$path"/etc/sudoers
|
2011-06-22 15:12:43 +00:00
|
|
|
chmod 440 "$path"/etc/sudoers
|
2011-01-25 03:01:05 +00:00
|
|
|
|
|
|
|
msg "Generating buildlab signing keys..."
|
|
|
|
do_chroot_action "$path" su abuild -c "'abuild-keygen -ai'"
|
2016-08-20 13:07:30 +00:00
|
|
|
|
2011-01-25 03:01:05 +00:00
|
|
|
msg "Setting up repository symlink..."
|
2016-08-20 13:07:30 +00:00
|
|
|
mkdir -p "$path"/home/abuild/.cache/apks
|
2011-01-25 03:01:05 +00:00
|
|
|
do_chroot_action "$path" chown abuild:abuild /home/abuild/${src}
|
|
|
|
do_chroot_action "$path" ln -sf .cache/apks /home/abuild/repo
|
|
|
|
|
|
|
|
msg "Build chroot is ready!"
|
|
|
|
}
|
|
|
|
|
|
|
|
build_package() {
|
|
|
|
local path="$1"
|
|
|
|
local apkbuild="$2"
|
|
|
|
srcdir="$(dirname $apkbuild)"
|
|
|
|
|
|
|
|
msg "Parsing $apkbuild..."
|
|
|
|
. "$apkbuild"
|
|
|
|
|
|
|
|
msg "Copying local sources..."
|
|
|
|
|
|
|
|
mkdir -p "$path"/home/abuild/src
|
|
|
|
chmod 666 "$path"/home/abuild/src
|
|
|
|
|
|
|
|
for src in $source $install; do
|
|
|
|
is_local $src || continue
|
|
|
|
|
|
|
|
msg "${srcdir}/${src} -> ${path}/home/abuild/src/${src} ..."
|
|
|
|
cp ${srcdir}/${src} "${path}"/home/abuild/${src}
|
|
|
|
do_chroot_action "$path" chown abuild:abuild /home/abuild/${src}
|
|
|
|
done
|
|
|
|
|
2011-06-22 14:50:43 +00:00
|
|
|
for i in $triggers; do
|
2011-06-27 21:05:01 +00:00
|
|
|
src=${i%=*}
|
2011-06-22 14:50:43 +00:00
|
|
|
is_local $src || continue
|
|
|
|
|
|
|
|
msg "${srcdir}/${src} -> ${path}/home/abuild/src/${src} ..."
|
|
|
|
cp ${srcdir}/${src} "${path}"/home/abuild/${src}
|
|
|
|
do_chroot_action "$path" chown abuild:abuild /home/abuild/${src}
|
|
|
|
done
|
|
|
|
|
2011-01-25 03:01:05 +00:00
|
|
|
cp $apkbuild "$path"/home/abuild
|
|
|
|
do_chroot_action "$path" chown abuild:abuild /home/abuild/$(basename $apkbuild)
|
|
|
|
|
|
|
|
msg "Invoking abuild..."
|
|
|
|
do_chroot_action "$path" su abuild -c "'cd /home/abuild; abuild -r'"
|
|
|
|
|
|
|
|
msg "Copying back results to ${abuildrepo}..."
|
|
|
|
mkdir -p ${abuildrepo}
|
|
|
|
for papk in "${path}"/home/abuild/*.apk; do
|
|
|
|
apk=$(basename $papk)
|
|
|
|
msg "$papk -> ${abuildrepo}/${apk}"
|
|
|
|
cp $papk ${abuildrepo}/${apk}
|
|
|
|
done
|
|
|
|
|
|
|
|
msg "Cleaning up..."
|
|
|
|
rm -rf "$path"/home/abuild/src
|
|
|
|
rm -rf "$path"/home/abuild/pkg
|
|
|
|
rm -f "$path"/home/abuild/APKBUILD
|
|
|
|
}
|
|
|
|
|
|
|
|
usage() {
|
2016-08-20 13:22:10 +00:00
|
|
|
cat <<-EOF
|
|
|
|
buildlab $program_version
|
|
|
|
|
|
|
|
Common options:
|
|
|
|
|
|
|
|
-q Quiet operation
|
|
|
|
-p Path to buildroot
|
|
|
|
|
|
|
|
Creating build roots (buildlab -C):
|
|
|
|
|
|
|
|
-m APK repository mirror
|
|
|
|
-v APK distribution version
|
|
|
|
-a APK repository architecture
|
|
|
|
-k Enable APK caching
|
|
|
|
|
|
|
|
Updating build roots (buildlab -u):
|
|
|
|
|
|
|
|
No special options.
|
|
|
|
|
|
|
|
Building packages (buildlab -b):
|
|
|
|
|
|
|
|
-b APKBUILD file
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
|
|
|
sudo ./buildlab -C -p /home/nenolod/buildroot -m dl-3.alpinelinux.org -v edge -a x86_64
|
|
|
|
sudo ./buildlab -b /home/nenolod/aports/main/gnome-panel/APKBUILD -p /home/nenolod/buildroot
|
|
|
|
sudo ./buildlab -u -p /home/nenolod/buildroot
|
|
|
|
EOF
|
2011-01-25 03:01:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unset force
|
|
|
|
unset recursive
|
2011-03-30 02:46:37 +00:00
|
|
|
while getopts "chqCkp:v:m:a:b:u" opt; do
|
2011-01-25 03:01:05 +00:00
|
|
|
case $opt in
|
|
|
|
'c') default_colors
|
|
|
|
color_opt="-c";;
|
2016-08-20 13:07:30 +00:00
|
|
|
'h') usage;;
|
|
|
|
'q') quiet="-q";;
|
2011-01-25 03:01:05 +00:00
|
|
|
'C') create="-c";;
|
|
|
|
'p') buildpath="$OPTARG";;
|
|
|
|
'm') buildmirror="$OPTARG";;
|
|
|
|
'v') buildver="$OPTARG";;
|
2011-03-30 02:46:37 +00:00
|
|
|
'a') buildarch="$OPTARG";;
|
|
|
|
'k') enablecache=1;;
|
2011-01-25 03:01:05 +00:00
|
|
|
'b') buildpkg="$OPTARG";;
|
2011-01-25 03:06:04 +00:00
|
|
|
'u') update="-u";;
|
2016-08-20 13:07:30 +00:00
|
|
|
esac
|
2011-01-25 03:01:05 +00:00
|
|
|
done
|
|
|
|
shift $(( $OPTIND - 1 ))
|
|
|
|
|
|
|
|
if [ ! -z "$create" ]; then
|
|
|
|
msg "Creating new chroot at $buildpath..."
|
2011-03-30 02:46:37 +00:00
|
|
|
prepare_chroot $buildpath $buildver $buildmirror $buildarch $enablecache
|
2011-01-25 03:01:05 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -z "$buildpkg" ]; then
|
|
|
|
msg "Building APKBUILD $buildpkg in chroot $buildpath..."
|
|
|
|
build_package $buildpath $buildpkg
|
|
|
|
exit 0
|
|
|
|
fi
|
2011-01-25 03:06:04 +00:00
|
|
|
|
|
|
|
if [ ! -z "$update" ]; then
|
|
|
|
msg "Updating chroot at $buildpath..."
|
|
|
|
update_chroot $buildpath
|
|
|
|
exit 0
|
|
|
|
fi
|