Initial commit

First container (for gitea)
This commit is contained in:
2026-01-23 21:02:54 +02:00
commit 5c42d9f22a
12 changed files with 386 additions and 0 deletions
+180
View File
@@ -0,0 +1,180 @@
#! /bin/bash
set -euo pipefail
die() {
echo "$@" >&2
exit 1
}
declare -A repos
addrepo() {
if [[ -d $1 ]]; then
[[ -e "${1}"/profiles/repo_name ]] || die "Not a valid repo: ${1}"
repos+=( [$(cat "${1}"/profiles/repo_name)]="$(realpath "${1}")" )
else
repos+=( ["${1}"]="$(portageq get_repo_path / "${1}")" )
fi
}
makeconf=make.conf
unstable=
clear=
done=
profile=
steve=
OPTIND=1
while getopts :ehusc:r:p:m: OPT; do
case $OPT in
h)
echo Usage: "$0" '[-c] [-r repo] [-r repo...] [dirname [emerge-args...]]'
echo ' -c yes: clear dirname first'
echo ' -e: exit after cleaning'
echo ' -u: build unstable'
echo ' -s: use steve'
echo ' -r repo: add repo to list; can be a repo name or a path'
echo ' -p profile: profile tro eselect (default: read from stdin)'
echo ' -m make.conf: path to make.conf (default: make.conf in current directory)'
exit 0
;;
c)
if [[ ${OPTARG} = yes ]]; then
clear=1
else
die "-c requires confirmation"
fi;;
e) done=1;;
u) unstable='~';;
s) steve=-j;;
r) addrepo "${OPTARG}";;
p) profile="${OPTARG}";;
m) makeconf="${OPTARG}";;
*)
echo "Unknown argument -$OPTARG; try $0 -h" 2> /dev/null
exit 1;;
esac
done
[[ -v repos[gentoo] ]] || addrepo gentoo
imageroot=${!OPTIND:-base}
imagename="$(basename "${imageroot}")"
shift "${OPTIND}" || :
if [[ -n $clear ]]; then
rm -rf "${imageroot}"
rm -f bin/"${imagename}"-{emerge,eselect,bwrap}
fi
if [[ -n ${done} ]]; then
[[ -z ${clear} ]] && die 'Warning: -e (exit after clean) used without -c (clean); exiting'
exit
fi
mkdir -p "${imageroot}"/etc/portage/repos.conf
mkdir -p "${imageroot}"/var/db/repos
mkdir -p "${imageroot}"/var/tmp
[[ -e ${makeconf} ]] && cp "${makeconf}" "${imageroot}"/etc/portage/make.conf
# addrepoconfs [root]
addrepoconfs() {
repoconf="${imageroot}"/etc/portage/repos.conf/gentoo.conf
cat <<-EOF > "${repoconf}"
[DEFAULT]
main-repo = gentoo
sync-allow-hardlinks = no
EOF
for i in "${!repos[@]}"; do
cat <<-EOF >> "${repoconf}"
[$i]
location = ${1}/var/db/repos/$i
EOF
[[ $i = gentoo ]] || echo "priority = 100" >> "${repoconf}"
if [[ -z $1 ]]; then
ln -s "${repos[$i]}" "${imageroot}"/var/db/repos/"$i" || [[ -z $clear ]]
fi
done
}
addrepoconfs ''
unset PORTDIR
unset PORTDIR_OVERLAY
ROOT="$(realpath "${imageroot}")"
export ROOT
eselect profile list
if [[ ! -L "${imageroot}"/etc/portage/make.profile ]]; then
if [[ -z ${profile} ]]; then
read -r -p "select " profile
fi
[[ -z ${profile} ]] && exit 1
eselect profile set "${profile}"
fi
export PORTAGE_CONFIGROOT="${ROOT}"
addrepoconfs "${ROOT}"
abi="$(portageq envvar ABI)"
libdir=LIBDIR_${abi}
libdir=$(portageq envvar "${libdir}")
libdir=${libdir:=lib}
mkdir -p "${imageroot}"/usr/lib "${imageroot}"/usr/bin "${imageroot}"/usr/"${libdir}"
ln -s usr/lib "${imageroot}"/lib || [[ -z $clear ]]
ln -s usr/bin "${imageroot}"/bin || [[ -z $clear ]]
ln -s usr/bin "${imageroot}"/sbin || [[ -z $clear ]]
ln -s bin "${imageroot}"/usr/sbin || [[ -z $clear ]]
ln -sf usr/"${libdir}" "${imageroot}/${libdir}"
[[ -n ${unstable} ]] && echo "ACCEPT_KEYWORDS=~${abi}" >> "${imageroot}"/etc/portage/make.conf
[[ -n ${steve} ]] && cat <<-EOF >> "${imageroot}"/etc/portage/make.conf
MAKEFLAGS="--jobserver-auth=fifo:/dev/steve"
MAKEOPTS="-j"
NINJAOPTS=""
EOF
# Use '' to prevent expanding here
# shellcheck disable=SC2016
echo 'FEATURES="${FEATURES} buildpkg"' >> "${imageroot}"/etc/portage/make.conf
mkdir -p cache
elibc=$(portageq envvar ELIBC)
PKGDIR=cache/packages${unstable:--}${abi}-${elibc}
mkdir -p "${PKGDIR}"
PKGDIR="$(realpath "${PKGDIR}")"
export PKGDIR
PORTAGE_TMPDIR="${ROOT}"/var/tmp
export PORTAGE_TMPDIR
mkdir -p bin
cat <<-EOF > bin/"${imagename}"-emerge
#! /bin/bash
ROOT="${ROOT}"
PORTAGE_CONFIGROOT="${ROOT}"
PORTAGE_TMPDIR="${PORTAGE_TMPDIR}"
PKGDIR="${PKGDIR}"
export ROOT PORTAGE_CONFIGROOT PORTAGE_TMPDIR PKGDIR
exec emerge "\$@"
EOF
chmod +x bin/"${imagename}"-emerge
cat <<-EOF > bin/"${imagename}"-eselect
#! /bin/bash
ROOT="${ROOT}"
export ROOT
exec eselect "\$@"
EOF
chmod +x bin/"${imagename}"-eselect
cat <<EOF > bin/"${imagename}"-bwrap
#! /bin/bash
exec bwrap --bind "${ROOT}" / --proc /proc --dev /dev --perms 01777 --tmpfs /dev/shm --perms 01777 --tmpfs /tmp \\
--clearenv --unshare-ipc --unshare-uts --unshare-pid --unshare-cgroup --die-with-parent --as-pid-1 "\${@:-/bin/sh}"
EOF
chmod +x bin/"${imagename}"-bwrap
emerge -1vuDUk ${steve} "$@" @system
+43
View File
@@ -0,0 +1,43 @@
#! /bin/bash
# does not install properly on busybox profile.
set -euo pipefail
imagedir="${1}"
imagename="$(basename "${imagedir}")"
shift
usename="${imagedir}"/etc/portage/package.use
[[ -d ${usename} ]] && usename="${usename}"/php.conf
cat <<-EOF >> "${usename}"
*/* cxx
*/* -pam
acct-user/git -git gitea
www-apps/gitea sqlite
sys-apps/util-linux -su
dev-vcs/git -perl
sys-apps/shadow su
EOF
bin/"${imagename}"-emerge -vk "$@" gitea dev-vcs/git-lfs
bin/"${imagename}"-emerge -1vuDUk "$@" @world
bin/"${imagename}"-emerge -1c --with-bdeps=n "$@"
#cat <<-EOF > "${imagedir}"/init
##! /bin/sh
#systemd-tmpfiles --create
#exec su git -c /usr/bin/gitea web
#EOF
#chmod +x "${imagedir}"/init
#mkdir -p "${imagedir}"/etc/giteac/custom/conf/
#cat <<-EOF > "${imagedir}"/etc/giteac/custom/conf/app.ini
#[service]
#DISABLE_REGISTRATION = true
#
#[openid]
#ENABLE_OPENID_SIGNIN = false
#ENABLE_OPENID_SIGNUP = false
#EOF