This commit is contained in:
Jack L. Frost 2014-11-10 05:25:22 +03:00
commit 68a03488ea
4 changed files with 221 additions and 0 deletions

40
builder-chroot.cfg.sh Executable file
View File

@ -0,0 +1,40 @@
# The config for building packages in chroots
cfg_git_repo="$HOME/git/pkgbuilds.git"
cfg_build_dir="/tmp/build"
cfg_repos_dir="$HOME/public"
cfg_chroot_dir="/tmp/chroot/build"
export GIT_DIR='.git'
cfg_repos=( 'spark' 'spark-extra' )
cfg_packages=(
'spark:spark-rc'
'spark:sinit-spark'
'spark:smdev'
'spark:watchman-sm'
'spark:watchman-sm-services-git'
'spark:xorg-noudev-conf'
'spark-extra:zpm'
'spark-extra:package-query'
'spark-extra:eudev'
'spark-extra:libsystemd-standalone'
'spark-extra:systemd-dummy'
'spark-extra:uselessd'
'spark-extra:scron'
'spark-extra:sdhcp'
'spark-extra:chromium-pepper-flash'
'spark-extra:vte3-select-text'
'spark-extra:termite'
'spark-extra:sinit-sysvcompat'
'spark-extra:posh'
'spark-extra:teamviewer8'
)
# 'spark-extra:cjdns-git'

42
builder-chroot.sh Executable file
View File

@ -0,0 +1,42 @@
#!/usr/bin/env bash
# A simple script to build packages into multiple repos
err() { echo "$1" >&2; }
build_pkg() {
local makepkg_output makepkg_exit_code makepkg_status
IFS=':' read repo package <<< "$1"
[[ -d "${cfg_build_dir}/${package}" ]] || {
err "Package ${package} doesn't exist in ${cfg_build_dir}"
return 1
}
[[ -d "${cfg_repos_dir}/${repo}" ]] || {
echo "Creating ${cfg_repos_dir}/${repo}"
mkdir -p "${cfg_repos_dir}/${repo}" || {
return 1
}
}
echo -n "Building ${package}... "
cd "${cfg_build_dir}/${package}"
sudo /usr/local/bin/makepkg-chroot.sh "${cfg_build_dir}/${package}.chroot" "${cfg_repos_dir}/${repo}"
}
main() {
source 'builder-chroot.cfg.sh'
for i in "${cfg_packages[@]}"; do
build_pkg "$i"
done
for i in "${cfg_repos[@]}"; do
cd "${cfg_repos_dir}/${i}"
repo-add -n "$i.db.tar.gz" *.pkg.tar.xz
done
}
main

62
makepkg-chroot.sh Executable file
View File

@ -0,0 +1,62 @@
#!/usr/bin/env bash
# Config
chroot_base='/var/chroot/root'
# Functions
icat() {
while read; do
echo -e "$REPLY"
done
}
build_script() {
icat <<- EOF
#!/bin/sh
pacman -Sy &>pacman.log
cd '/build'; chown builder:wheel /build
sudo -u builder PKGDEST='/pkg' makepkg -s --noconfirm -L &>makepkg.log
makepkg_exit="\$?"
case "\$makepkg_exit" in
0) echo 'ok';;
17) echo 'already built';;
*) echo 'FAIL';;
esac
exit "\$makepkg_exit"
EOF
}
main() {
chroot_dir="$1"
pkg_dest_dir="$2"
workdir="$PWD"
[[ "${chroot_dir}" ]] || { usage; exit 1; }
/usr/local/bin/mount-chroot.sh -s "$chroot_base" -n 'chroot_build' "$chroot_dir"
mkdir -m777 "$chroot_dir/pkg" "$chroot_dir/build"
mount --bind "$workdir" "$chroot_dir/build"
mount --bind "$pkg_dest_dir" "$chroot_dir/pkg"
build_script > "${chroot_dir}/build/build.sh"
#chmod 755 "${chroot_dir}/build/build.sh"
chroot "${chroot_dir}" sh /build/build.sh
if /usr/local/bin/mount-chroot.sh -u "$chroot_dir"; then
rm -r "${chroot_dir}"{,.work}
else
err "Cannot unmount $chroot_dir"
exit 1
fi
}
main "$@"

77
mount-chroot.sh Executable file
View File

@ -0,0 +1,77 @@
#!/usr/bin/env bash
err() { echo "$1" >&2; }
usage() {
cat <<- EOF
Usage: "${0##*/}" [options] <chroot>
Options:
-s chroot base dir
-n mount name
-u unmount chroot
EOF
}
chroot.mount() {
for i in "$target_dir" "$chroot_base"; do
[[ "$i" ]] || {
usage
return 1
}
done
[[ -d "$chroot_base" ]] || {
err "Chroot base ($chroot_base) does not exist."
return 1
}
mount_name="${mount_name:-chroot}"
for i in "$target_dir" "${target_dir}.work"; do
[[ -d "$i" ]] || {
mkdir -p "$i" || {
return 3
}
}
done
mount -t overlayfs -o lowerdir="$chroot_base",upperdir="$target_dir",workdir="${target_dir}.work" "$mount_name" "$target_dir"
mount -t proc "${mount_name}_proc" "${target_dir}/proc"
mount --rbind /dev "${target_dir}/dev"
mount --rbind /sys "${target_dir}/sys"
}
chroot.umount() {
umount --recursive "$target_dir"
}
main() {
while [[ "$1" ]]; do
case "$1" in
-s) chroot_base="$2"; shift;;
-n) mount_name="$2"; shift;;
-u) action='umount';;
--) shift; break;;
-*)
err "Unknown key: $1"
usage
return 1
;;
*) break;;
esac
shift
done
target_dir="$1"
action="${action:-mount}"
mount_name="${mount_name:-chroot}"
case "$action" in
mount) chroot.mount;;
umount) chroot.umount;;
esac
}
main "$@"