Browse Source

new tools

Signed-off-by: fbt <fbt@fleshless.org>
master
Jack L. Frost 5 years ago
parent
commit
e705636929
  1. 54
      builder-chroot
  2. 9
      builder-chroot.cfg
  3. 9
      builder-chroot.cfg.sh
  4. 48
      builder-chroot.sh
  5. 70
      lxf
  6. 62
      makepkg-chroot.sh
  7. 44
      makepkg-overlay
  8. 77
      mount-chroot.sh

54
builder-chroot

@ -1,54 +0,0 @@
#!/usr/bin/env bash
# A simple script to build packages into multiple repos
err() { echo "$1" >&2; }
build_pkg() {
declare package repo
package="$1"
repo="$2"
echo -n "Building ${repo}/${package}... "
cd "/tmp/build-${package}"
sudo /usr/local/bin/makepkg-chroot.sh "${cfg_build_dir}/${package}.chroot" "${cfg_repos_dir}/${repo}"
}
main() {
source 'builder-chroot.cfg'
package="$1"
repo_name="$2"
# if [[ -f "/tmp/build-${package}/.spark.repo" ]]; then
# repo_name=$( <"/tmp/build-${package}/.spark.repo" )
# else
# err "Repo not specified, not building package."
# return 1
# fi
if [[ ! -d "${cfg_repos_dir}/${repo_name}" ]]; then
echo "Creating ${cfg_repos_dir}/${repo_name}"
mkdir -p "${cfg_repos_dir}/${repo_name}" || {
return 1
}
fi
build_pkg "$package" "$repo_name"
cd "${cfg_repos_dir}/${repo_name}"
printf 'Cleaning the %s repo...\n' "$repo_name"
"$HOME/scripts/repo-clean" > repo_clean.log
printf 'Signing packages...\n'
"$HOME/scripts/repo-sign" > repo_sign.log
printf 'Adding packages to the %s repo...\n' "$repo_name"
repo-add -n "${repo_name}.db.tar.gz" *.pkg.tar.xz &> update.log
printf 'Done\n'
}
main "$@"

9
builder-chroot.cfg

@ -1,9 +0,0 @@
# The config for building packages in chroots
cfg_git_repo="$HOME/git/pkgbuilds.git"
cfg_build_dir="/tmp"
cfg_repos_dir="$HOME/public"
cfg_chroot_dir="/tmp/chroot"
export GIT_DIR='.git'

9
builder-chroot.cfg.sh

@ -1,9 +0,0 @@
# 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'

48
builder-chroot.sh

@ -1,48 +0,0 @@
#!/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
repo="$1"
package="$2"
[[ -d "${cfg_build_dir}/repos/${repo}/${package}" ]] || {
err "Package ${package} doesn't exist in ${cfg_build_dir}/repos/${repo}"
return 1
}
[[ -d "${cfg_repos_dir}/${repo}" ]] || {
echo "Creating ${cfg_repos_dir}/${repo}"
mkdir -p "${cfg_repos_dir}/${repo}" || {
return 1
}
}
echo -n "Building ${repo}/${package}... "
cd "${cfg_build_dir}/repos/${repo}/${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_build_dir}/repos"/*; do
repo_name="${i##*/}"
repos+=( "$repo_name" )
for r in "$i"/*; do
build_pkg "$repo_name" "${r##*/}"
done
done
for i in "${repos[@]}"; do
cd "${cfg_repos_dir}/${i}"
repo-add -n "${i}.db.tar.gz" *.pkg.tar.xz
done
}
main

70
lxf

@ -0,0 +1,70 @@
#!/usr/bin/env bash
mkconf() {
for i in "${includes[@]}"; do
echo "lxc.include = $lxf_conf_dir/$i.conf"
done
echo "lxc.rootfs.path = $lxf_cont_dir/$cont_name/rootfs"
echo "lxc.uts.name = $cont_name"
}
mount_cont() {
ov-mount -n "$cont_name" "$rootfs" "$cont_dir/rootfs"
}
lxf_conf_dir='/etc/lxf/conf'
lxf_cont_dir='/var/lib/lxf/cont'
lxf_rootfs_dir='/var/lib/lxf/fs'
[[ -f '/etc/lxf.conf' ]] && source '/etc/lxf.conf'
while (( $# )); do
case $1 in
(-i) includes+=( "$2" ); shift;;
(-r) rootfs="$2"; shift;;
(--cont-dir) lxf_cont_dir=$2; shift;;
(--conf-dir) lxf_conf_dir=$2; shift;;
(--) shift; break;;
(-*) echo "Unknown key: $1" >&2: exit 1;;
(*) break;;
esac
shift
done
action=$1; shift; [[ $action ]] || exit 1
cont_name=$1; shift; [[ $cont_name ]] || exit 1
cont_dir="$lxf_cont_dir/$cont_name"
case $action in
(create|new)
[[ "$rootfs" ]] || exit 1
rootfs="$lxf_rootfs_dir/$rootfs"
[[ -d "$cont_dir" ]] && {
printf 'Container already exists: %s\n' "$cont_dir" >&2
exit 1
}
mkdir -p "$cont_dir" || exit $?
mkconf > "$cont_dir/config"
mount_cont
;;
(mount)
mountpoint -q "$cont_dir/rootfs" && {
printf 'Container already mounted: %s\n' "$cont_dir/rootfs" >&2
exit 1
}
mount_cont
;;
(umount) umount "$cont_dir/rootfs";;
esac

62
makepkg-chroot.sh

@ -1,62 +0,0 @@
#!/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';;
3) 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 "$@"

44
makepkg-overlay

@ -0,0 +1,44 @@
#!/usr/bin/env bash
cleanup() {
umount "$cnt_dir/rootfs"
}
wrk_dir='/home/lxc'
pkg_url=$1
pkg_dest=$2
cnt="_makepkg.$$"
cnt_dir="$wrk_dir/containers/$cnt"
trap 'cleanup' INT TERM EXIT
lxf -r builder -i builder new "$cnt"
# Add the build script
cp "$wrk_dir/files/buildpackage" "$cnt_dir/rootfs/init"
chmod 755 "$cnt_dir/rootfs/init"
# Tell it where to fetch the package
echo "$pkg_url" > "$cnt_dir/rootfs/repo"
# Start the container
lxc-start -n "$cnt" -F; lxc_exit=$?
(( lxc_exit )) && exit "$lxc_exit"
# Put the artifacts where asked to
[[ "$pkg_dest" ]] && {
artifacts=( "$cnt_dir/rootfs/buildroot/"*.pkg.* )
for i in "${artifacts[@]}"; do
i_name="${i##*/}"
printf 'Found artifact: %s\n' "$i_name"
if [[ -f "$pkg_dest/$i_name" ]]; then
echo "$pkg_dest/$i_name already exists, not overwriting."
else
cp -vn "$i" "$pkg_dest"
fi
done
}

77
mount-chroot.sh

@ -1,77 +0,0 @@
#!/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 overlay -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 "$@"
Loading…
Cancel
Save