fixup! Add tix-upgrade(8).

This commit is contained in:
Jonas 'Sortie' Termansen 2023-07-16 17:10:40 +02:00
parent 401ec64e3a
commit 7f8cb8aecc
1 changed files with 29 additions and 19 deletions

View File

@ -19,8 +19,9 @@
set -e
cachedir=""
cancel=false
clean=false
collection=""
collection=/
download_only=false
fetch_options=
ports_only=false
@ -50,6 +51,7 @@ for argument do
-w) wait=-w ;;
--cachedir=*) cachedir=$parameter ;;
--cachedir) previous_option=cachedir ;;
--cancel) cancel=true ;;
--clean) clean=true ;;
--collection=*) collection=$parameter ;;
--collection) previous_option=collection ;;
@ -74,36 +76,47 @@ if test -n "$previous_option"; then
exit 1
fi
# TODO: Reject additional operands.
if [ -z "$collection" ]; then
collection="$sysroot"
if [ 0 -lt $# ]; then
echo "$0: Unexpected extra operand: $1" >&2
exit 1
fi
if [ -n "$collection" ]; then
collection=$(cd "$collection" && pwd)
fi
get_conf() {
sed -E -e 's/([a-zA-Z0-9_]+) *? *= */\U\1=/' \
-e 's/=yes$/=true/' -e 's/no$/=false/' "$3" | \
tix-vars -d "$2" - "$4"
}
collection=$(cd "$collection" && pwd)
if ! $upgrade_ports && ! $upgrade_system; then
# TODO: Ability to set default in /etc/upgrade.conf.
upgrade_ports=true
upgrade_system=true
if [ -e "$collection/etc/upgrade.conf" ]; then
upgrade_ports=$(get_conf -d true "$collection/etc/upgrade.conf" PORTS)
upgrade_system=$(get_conf -d true "$collection/etc/upgrade.conf" SYSTEM)
fi
fi
# Update only ports if this isn't a whole system installation.
# If this isn't a system installation, only upgrade the ports.
if [ ! -e "$collection/tix/manifest/system" ]; then
upgrade_system=false
fi
if [ -z "$cachedir" ]; then
cachedir="$collection/var/cache/tix"
cachedir="${collection%/}/var/cache/tix"
fi
if $clean; then
if $cancel || $clean; then
echo "Removing cache directory: $cachedir"
rm -rf -- "$cachedir"
fi
if $cancel; then
sysmerge -t "$collection" --cancel
exit
fi
mkdir -p -- "$cachedir"
mkdir -p -- "$cachedir/new"
@ -115,11 +128,10 @@ tix-fetch $fetch_options \
# If release.sig.sh or sha256sum changed, clean the cache directory of downloads
# that were currently in progress as they might not have the right checksums.
# TODO: This requires diff(1) in the base system! Avoid that. Get a cmp(1)!
if ! diff -- "$cachedir/release.sh.sig" \
"$cachedir/new/release.sh.sig" 1>/dev/null 2>/dev/null ||
! diff -- "$cachedir/sha256sum" \
"$cachedir/new/sha256sum" 1>/dev/null 2>/dev/null; then
if [ ! -e "$cachedir/release.sh.sig" ] ||
[ ! -e "$cachedir/sha256sum" ] ||
! (cd "$cachedir/new" && sha256sum release.sh.sig sha256sum) |
(cd "$cachedir" && sha256sum -cs); then
rm -rf -- "$cachedir/boot"
rm -rf -- "$cachedir/repository"
rm -rf -- "$cachedir/sysroot"
@ -139,7 +151,6 @@ mkdir -p "$cachedir/repository"
if $upgrade_system; then
# Fetch the base system initrds from the mirror.
# TODO: What about the system source code in /src?
# TODO: Get the overlay initrd if it exists.
tix-fetch $fetch_options \
--collection="$collection" \
--input-release-sig-file="$cachedir/release.sh.sig" \
@ -152,7 +163,6 @@ if $upgrade_ports; then
ports=$(LC_ALL=C ls -- "$collection/tix/tixinfo")
# TODO: Handle new mandatory / recommended ports.
# TODO: Handle renamed ports.
# TODO: This fails if the port does not exist upstream.
mkdir -p "$cachedir/repository"
for port in $ports; do
# The port has a hash if if it exists upstream.