110 lines
2.7 KiB
Bash
Executable File
110 lines
2.7 KiB
Bash
Executable File
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
REPO_URL="git@git.ayau.me:mira/gentoo-pill.git"
|
|
WORK_DIR="$(pwd)"
|
|
REPO="${WORK_DIR}/repo"
|
|
CTX="${WORK_DIR}/ctx"
|
|
|
|
IMAGE="docker.io/gentoo/stage3:amd64-desktop-openrc"
|
|
PROFILE="default/linux/amd64/23.0/desktop"
|
|
CFLAGS="-O2 -pipe -march=x86-64-v3"
|
|
|
|
if [[ ! -d "$REPO/.git" ]]; then
|
|
git clone "$REPO_URL" "$REPO"
|
|
else
|
|
git -C "$REPO" pull --rebase
|
|
fi
|
|
|
|
echo "Aggregating configuration..."
|
|
rm -rf "$CTX" && mkdir -p "$CTX"/var/lib/portage
|
|
|
|
# config types to merge
|
|
CONFIGS=(package.use package.accept_keywords package.license package.mask package.unmask package.env repos.conf)
|
|
|
|
for type in "${CONFIGS[@]}"; do
|
|
dest="$CTX/etc/portage/$type"
|
|
mkdir -p "$dest"
|
|
|
|
inject() {
|
|
local src=$1 prefix=$2
|
|
[[ ! -e "$src" ]] && return
|
|
|
|
if [[ -d "$src" ]]; then
|
|
for f in "$src"/*; do
|
|
[[ -f "$f" ]] && cp "$f" "$dest/${prefix}-$(basename "$f")"
|
|
done
|
|
else
|
|
cp "$src" "$dest/${prefix}-$(basename "$src")"
|
|
fi
|
|
}
|
|
|
|
inject "$REPO/common/$type" "00-common"
|
|
|
|
for host_dir in "$REPO/hosts"/*; do
|
|
[[ -d "$host_dir" ]] || continue
|
|
hostname=$(basename "$host_dir")
|
|
inject "$host_dir/$type" "50-${hostname}"
|
|
done
|
|
done
|
|
|
|
# generate world union
|
|
cat "$REPO"/hosts/*/world 2>/dev/null | sort -u | sed '/^#/d;/^$/d' > "$CTX/var/lib/portage/world"
|
|
echo "Packages to build: $(wc -l < "$CTX/var/lib/portage/world")"
|
|
|
|
# make.conf
|
|
mkdir -p "$CTX/etc/portage"
|
|
cp "$REPO/binhost/make.conf" "$CTX/etc/portage/make.conf"
|
|
{
|
|
# we don't want build to fail bcs of EULA check..
|
|
echo 'ACCEPT_LICENSE="*"'
|
|
echo "CFLAGS=\"$CFLAGS\""
|
|
echo "CXXFLAGS=\"$CFLAGS\""
|
|
} >> "$CTX/etc/portage/make.conf"
|
|
|
|
echo "Starting Builder..."
|
|
|
|
VOLUMES=(
|
|
-v portage_db:/var/db/repos/gentoo
|
|
-v distfiles:/var/cache/distfiles
|
|
-v binpkgs:/var/cache/binpkgs
|
|
-v "$CTX/etc/portage/make.conf:/etc/portage/make.conf"
|
|
-v "$CTX/var/lib/portage/world:/var/lib/portage/world"
|
|
)
|
|
|
|
# add config dirs to volumes
|
|
for type in "${CONFIGS[@]}"; do
|
|
VOLUMES+=(-v "$CTX/etc/portage/$type:/etc/portage/$type")
|
|
done
|
|
|
|
# start cooking
|
|
podman run --rm -i \
|
|
--name "gentoo_builder" \
|
|
--cap-add=SYS_PTRACE \
|
|
"${VOLUMES[@]}" \
|
|
--tmpfs /var/tmp/portage:rw,size=48G,mode=1777 \
|
|
"$IMAGE" /bin/bash <<EOF
|
|
set -e
|
|
source /etc/profile
|
|
|
|
echo "> Syncing tree..."
|
|
emerge-webrsync -q
|
|
|
|
echo "> Instlaling git"
|
|
emerge -1av dev-vcs/git
|
|
|
|
echo "> Syncing overlays"
|
|
emaint sync -a
|
|
|
|
echo "> Setting Profile..."
|
|
eselect profile set "$PROFILE"
|
|
|
|
echo "> Building World..."
|
|
emerge --verbose --buildpkg --update --deep --newuse --changed-use --with-bdeps=y --keep-going @world
|
|
|
|
echo "> Cleaning up..."
|
|
emerge --depclean
|
|
emaint binhost --fix
|
|
EOF
|
|
|