summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbill-auger <mr.j.spam.me@gmail.com>2023-12-14 12:32:47 -0500
committerbill-auger <mr.j.spam.me@gmail.com>2023-12-14 14:56:05 -0500
commitf8dd0bc2295ac5315581039d597dfd0738ddafca (patch)
tree016ce8e84da68ad5d3940b478cdd67f758d1902b
parent13c74d3002c8ae9fe81a95fb7a28dc92b3b2e6db (diff)
[chcleanup.in]: wip
-rw-r--r--src/chroot-tools/chcleanup.in111
1 files changed, 80 insertions, 31 deletions
diff --git a/src/chroot-tools/chcleanup.in b/src/chroot-tools/chcleanup.in
index da0853a..0b4f800 100644
--- a/src/chroot-tools/chcleanup.in
+++ b/src/chroot-tools/chcleanup.in
@@ -58,6 +58,8 @@ DRYRUN=${DRYRUN:-false}
if [[ ! -f /.arch-chroot ]] && ! ${DRYRUN}; then
error "(chcleanup): Must be run inside of a chroot"
exit 1
+elif [[ ! -f /etc/pacman.conf ]]; then
+ error "(chcleanup): Chroot is lacking /etc/pacman.conf."
fi
@@ -67,25 +69,60 @@ fi
# This is intentionally hard-coded.
source /etc/libretools.d/chroot.conf # sets $CHROOTEXTRAPKG
-
-CHROOTPKG=( $( pacman -Sgq base-devel) )
-CHROOTPKG+=() # DEBUG: normally empty - mandatory core package-set additions
-WHITELIST_PKGS=() # DEBUG: normally empty - allowed outdated packages, possibly insane
-PHANTOM_PKGS=() # DEBUG: normally empty - fake dependencies, possibly insane
-PHANTOM_PKGS=( ${PHANTOM_PKGS[*]/#/--assume-installed=} )
+#BASEDEVEL_PKGS=( $(pacman -Sgq base-devel) ) # base-devel is now a meta-package
+CHROOTPKG=( base base-devel )
+# BASE_PKG=$( (( IS_NONSYSTEMD )) && echo nonsystemd/base || echo libre/base ) # WIP
+# BASE_PKGS=( $( LANG=C pacman -Si ${BASE_PKG} | grep Depends | cut -d ':' -f 2 ) )
+# DEVEL_PKGS=( $( LANG=C pacman -Si base-devel | grep Depends | cut -d ':' -f 2 ) )
+# CHROOTPKG=( ${BASE_PKGS[*]/*-keyring} ${DEVEL_PKGS[*]/*-keyring} )
+#SYSTEMD_PKGS=(systemd-libudev systemd-udev) # WIP
+# NONSYSTEMD_PKGS=(your-initfreedom eudev libelogind) # WIP
+NONSYSTEMD_PKGS=(elogind libelogind) # WIP
+#NONSYSTEMD_PKGS=() # WIP
+EXCLUDE_PKGS=( '.*-keyring' ) # may be regexes
+CHROOTPKG+=() # normally empty - mandatory core package-set additions
+WHITELIST_PKGS=() # normally empty - allowed packages, possibly insane/outdated
+PHANTOM_PKGS=() # normally empty - fake dependencies, possibly insane
+
+readonly CARCH="$(source /etc/makepkg.conf ; printf '%s' "${CARCH}")"
+#IS_NONSYSTEMD=$( grep '^\s*\[nonsystemd\]\s*$' /etc/pacman.conf &> /dev/null ; echo $((! $?)) ; ) # WIP
+readonly IS_NONSYSTEMD=$( grep -E '^VARIANT_ID="+[^-"]*-openrc"+$' /etc/os-release &> /dev/null ; echo $((! $?)) ; ) # WIP
# If we're running makepkg
if [[ -f ./PKGBUILD ]]; then
+ sed_rx="s/^\\s+(|make|check)depends(|_${CARCH}) = "
+
if [[ ! -f ./.SRCINFO || ./PKGBUILD -nt ./.SRCINFO ]]; then
sudo -u "#$(stat -c %u -- ./PKGBUILD)" sh -c 'makepkg --printsrcinfo > .SRCINFO'
+ # nonsystemd hack
+ if (( IS_NONSYSTEMD )); then
+ declare -A nonsystemd_pkgs
+ nonsystemd_pkgs[systemd]=elogind
+ nonsystemd_pkgs[systemd-libs]=libelogind
+ nonsystemd_pkgs[systemd-udev]=udev
+ nonsystemd_pkgs[systemd-libudev]=libudev
+ for systemd_pkg in ${!nonsystemd_pkgs[@]}; do
+ nonsystemd_pkg=${nonsystemd_pkgs[$systemd_pkg]}
+ sed -i -E "${sed_rx}${systemd_pkg}$/\1depends\2 = ${nonsystemd_pkg}/" .SRCINFO
+ done
+ fi
fi
- CARCH="$(source /etc/makepkg.conf; printf '%s' "$CARCH")"
- mapfile -t DEPENDS < <(sed -nE -e "s/^\\s+(|make|check)depends(|_${CARCH}) = //p" -e '/^\s*pkgname/q' < .SRCINFO)
+# mapfile -t DEPENDS < <(sed -nE -e "s/^\\s+(|make|check)depends(|_${CARCH}) = //p" -e '/^\s*pkgname/q' < .SRCINFO)
+ sed_rx+='//p ; /^\s*pkgname/q'
+ mapfile -t DEPENDS < <(sed --silent -E "${sed_rx}" < .SRCINFO)
else
DEPENDS=()
fi
-readonly CHROOTPKG WHITELIST_PKGS PHANTOM_PKGS DEPENDS
+readonly CHROOTPKG=( $(repo=$((( IS_NONSYSTEMD )) && echo nonsystemd || echo libre)
+ sed "s|^base$|${repo}/&|" <<<${CHROOTPKG[*]} ) ) # WIP
+readonly NONSYSTEMD_PKGS
+readonly EXCLUDE_PKGS
+readonly EXCLUDE_RX="^($(sed 's/ /|/g' <<<${EXCLUDE_PKGS[*]}))$"
+#readonly WHITELIST_PKGS+=( $( (( IS_NONSYSTEMD )) && echo ${NONSYSTEMD_PKGS[*]} || echo ${SYSTEMD_PKGS[*]} ) ) # WIP
+readonly WHITELIST_PKGS+=( $( (( IS_NONSYSTEMD )) && echo ${NONSYSTEMD_PKGS[*]} || : ) ) # WIP
+readonly PHANTOM_PKGS=( ${PHANTOM_PKGS[*]/#/--assume-installed=} )
+readonly DEPENDS
## Main Entry ##
@@ -95,8 +132,10 @@ msg "Cleaning chroot..."
# Sync the local repo with pacman (a crude form of `pacman -Sy`)
cp /repo/repo.db /var/lib/pacman/sync/repo.db
-# Setup the temporary directory
+# Setup a temporary directory and configure pacman for scratch DB
TEMPDIR="$(mktemp --tmpdir -d "${0##*/}.XXXXXXXXXX")"
+pacman_cmd=(pacman --dbpath="$TEMPDIR/db" --hookdir="$TEMPDIR/hooks")
+# PACMAN_CMD=(pacman --dbpath="$TEMPDIR/db" --hookdir="$TEMPDIR/hooks") # TODO: upcase PACMAN_CMD
ERROR_PKGS_FILE="$TEMPDIR/err_pkgs.txt"
WHITELIST_PKGS_FILE="$TEMPDIR/pkglist.txt"
trap "rm -rf -- ${TEMPDIR@Q}" EXIT
@@ -104,12 +143,13 @@ trap "rm -rf -- ${TEMPDIR@Q}" EXIT
# Set up a scratch pacman DB
mkdir -- "$TEMPDIR/db" "$TEMPDIR/db/local" "$TEMPDIR/hooks"
cp -a -t "${TEMPDIR}/db" -- /var/lib/pacman/sync
-{ echo /usr/share/libalpm/hooks; pacman-conf HookDir; } | while read -r dir; do
- for hook in "$dir"/*.hook; do
+for hooks_dir in /usr/share/libalpm/hooks "$(pacman-conf HookDir)"; do
+ [[ -d "$hooks_dir" ]] || continue
+
+ for hook in "$hooks_dir"/*.hook; do
ln -sfT -- /dev/null "$TEMPDIR/hooks/${hook##*/}"
done
done
-pacman_cmd=(pacman --dbpath="$TEMPDIR/db" --hookdir="$TEMPDIR/hooks")
# We do our best to pre-load the scratch DB with CHROOTPKG and
# CHROOTEXTRAPKG packages. This is purely an optimization step.
# The safety of this optimization assumes that none of CHROOTPKG,
@@ -132,20 +172,29 @@ done
# Collect the minimal set of packages, which are necessary,
# in order to build the PKGBUILD recipe
-# (base+base-devel, user-packages, PKGBUILD dependencies,
+# (base-devel, user-packages, PKGBUILD dependencies,
# and the entire resolved dependency chain).
# This is done by installing those into a temporary pacman DB;
# then querying the DB for it's complete package list.
+pacman_opts=(-S --dbonly --noscriptlet --needed --noconfirm)
msg2 "Collecting the minimal set of packages needed ..."
-if ! "${pacman_cmd[@]}" -S --dbonly --noscriptlet --needed --noconfirm ${PHANTOM_PKGS} \
- -- ${CHROOTPKG[*]} ${CHROOTEXTRAPKG[*]} ${DEPENDS[*]} \
- <&- >& "$ERROR_PKGS_FILE"
-then
- error "Could not create a full list of packages, exiting."
- plain "Ensure that the chroot is up-to-date."
- plain "Otherwise, this is likely caused by an unsatisfied dependency."
- sed 's/^/ > /' < "$ERROR_PKGS_FILE" >&2
- exit 1
+if (( ${#CHROOTPKG[*]} ))
+then for var in CHROOTPKG CHROOTEXTRAPKG DEPENDS
+ do declare -n pkgsref="$var"
+# prose " * collecting '$var' packages: ${pkgsref[*]}" # TODO: column -t maybe better?
+ indent <<<" * collecting '$var' packages: ${pkgsref[*]}"
+ done
+ if ! "${pacman_cmd[@]}" ${pacman_opts[*]} ${PHANTOM_PKGS[*]} \
+ -- ${CHROOTPKG[*]} ${CHROOTEXTRAPKG[*]} ${DEPENDS[*]} \
+ <&- >& "$ERROR_PKGS_FILE"
+ then error "Could not create a complete list of packages - exiting."
+ plain "Ensure that the chroot is up-to-date."
+ plain "Otherwise, this is likely caused by an unsatisfied dependency."
+ sed 's/^/ > /' < "$ERROR_PKGS_FILE" >&2
+ exit 1
+ fi
+else error "Could not create a list of packages - CHROOTPKG is empty - exiting."
+ exit 1
fi
# Generate the list of packages which should be installed.
@@ -164,8 +213,8 @@ fi
# so it is best to require explicit initiation of a build in this insane configuration
# (via the `libremakepkg` '-I' option), and to exit otherwise, warning the user to upgrade.
# If the '-I' option was detected (!SANE), the stale packages are added to the whitelist.
-"${pacman_cmd[@]}" -Qq > "$WHITELIST_PKGS_FILE"
-echo "${WHITELIST_PKGS[@]}" >> "$WHITELIST_PKGS_FILE"
+"${pacman_cmd[@]}" -Qq | grep -vE "${EXCLUDE_RX}" > "$WHITELIST_PKGS_FILE"
+echo "${WHITELIST_PKGS[@]}" >> "$WHITELIST_PKGS_FILE"
if (( ${#stale_pkgs[*]} > 0 )); then
insane_msg_1="Some (%d) essential packages are out-of-sync with the database."
insane_msg_2="Consider upgrading the chroot system before building packages."
@@ -181,8 +230,8 @@ if (( ${#stale_pkgs[*]} > 0 )); then
fi
# Diff installed packages against a clean chroot then remove leftovers
-packages=($(comm -23 <(pacman -Qq | sort -u) \
- <(sort -u "$WHITELIST_PKGS_FILE")))
+packages=( $(comm -23 <(pacman -Qq | sort -u) \
+ <(sort -u "$WHITELIST_PKGS_FILE") ) )
if [[ ${#packages[@]} = 0 ]]; then
msg2 "No packages to remove"
else
@@ -192,12 +241,12 @@ else
echo "${packages[*]}"
else
# Only remove leftovers, -Rcs removes too much
- pacman --noconfirm ${PHANTOM_PKGS} -R --nosave "${packages[@]}"
+ pacman --noconfirm ${PHANTOM_PKGS[*]} -R --nosave "${packages[@]}"
fi
fi
-packages=($(comm -13 <(pacman -Qq | sort -u) \
- <(sort -u "$WHITELIST_PKGS_FILE")))
+packages=( $(comm -13 <(pacman -Qq | sort -u) \
+ <(sort -u "$WHITELIST_PKGS_FILE") ) )
if [[ ${#packages[@]} = 0 ]]; then
msg2 "No packages to add"
else
@@ -206,7 +255,7 @@ else
if ${DRYRUN}; then
echo "${packages[*]}"
else
- pacman --noconfirm ${PHANTOM_PKGS} -S "${packages[@]}"
+ pacman --noconfirm ${PHANTOM_PKGS[*]} -S "${packages[@]}"
fi
fi