Solved FreeBSD upgrade from 13.1 to 15.0-p9 helper script where shared object "libsys.so.7" not found

Code:
#!/rescue/sh

set -e

WORKDIR=/var/db/freebsd-update
TARGET=/lib/libsys.so.7
BACKUPDIR=/root/freebsd-upgrade-backup
LIBCXXDIR=/usr/include/c++/v1
TMP=/tmp/libsys.so.7.$$

cmd() {
    if [ -x "/rescue/$1" ]; then
        echo "/rescue/$1"
    else
        echo "$1"
    fi
}

GUNZIP=$(cmd gunzip)
CHOWN=$(cmd chown)
CHMOD=$(cmd chmod)
LS=$(cmd ls)
MKDIR=$(cmd mkdir)
MV=$(cmd mv)
RM=$(cmd rm)

cd "$WORKDIR"

found=
foundidx=

for idx in install.*/INDEX-NEW; do
    [ -f "$idx" ] || continue

    while IFS= read -r line; do
        case "$line" in
            *libsys.so.7*)
                found="$line"
                foundidx="$idx"
                break
                ;;
        esac
    done < "$idx"

    [ -n "$found" ] && break
done

if [ -z "$found" ]; then
    echo "ERROR: could not find libsys.so.7 in any install.*/INDEX-NEW file"
    exit 1
fi

echo "INDEX=$foundidx"
echo "LINE=$found"

rest="$found"
hash=

while [ -n "$rest" ]; do
    field=${rest%%|*}

    if [ -f "$WORKDIR/files/${field}.gz" ]; then
        hash="$field"
        break
    fi

    case "$rest" in
        *\|*) rest=${rest#*|} ;;
        *) rest= ;;
    esac
done

if [ -z "$hash" ]; then
    echo "ERROR: found libsys.so.7 line, but could not identify a matching files/<hash>.gz"
    exit 1
fi

if [ ! -f "$WORKDIR/files/${hash}.gz" ]; then
    echo "ERROR: missing update payload: $WORKDIR/files/${hash}.gz"
    exit 1
fi

echo "HASH=$hash"

$GUNZIP -c "$WORKDIR/files/${hash}.gz" > "$TMP"

if [ ! -s "$TMP" ]; then
    echo "ERROR: extracted libsys.so.7 is empty"
    $RM -f "$TMP"
    exit 1
fi

$CHOWN root:wheel "$TMP"
$CHMOD 0444 "$TMP"
$MV "$TMP" "$TARGET"

echo "Restored:"
$LS -l "$TARGET"

$MKDIR -p "$BACKUPDIR/libcxx-header-files"

for name in __tuple __string; do
    path="$LIBCXXDIR/$name"

    if [ -f "$path" ]; then
        backup="$BACKUPDIR/libcxx-header-files/$name.old-file"
        if [ -e "$backup" ]; then
            backup="$BACKUPDIR/libcxx-header-files/$name.old-file.$$"
        fi

        echo "Moving stale libc++ header file $path to $backup"
        $MV "$path" "$backup"
    fi

    $MKDIR -p "$path"
done

echo "libc++ header paths:"
$LS -ld "$LIBCXXDIR/__tuple" "$LIBCXXDIR/__string"

echo "Done. Now test by running: /bin/sh"
echo "If that works, run: freebsd-update install"
 
Back
Top