Added update-alternatives fix for all packages that rely on it.

новый файл:    01-alternatives.sh
	новый файл:    darkline-postinst.install
	изменено:      PKGBUILD
This commit is contained in:
2025-08-21 21:47:16 +03:00
parent e3a622c05c
commit 6c48edaed3
2 changed files with 136 additions and 0 deletions

126
01-alternatives.sh Normal file
View File

@@ -0,0 +1,126 @@
#!/data/data/com.termux/files/usr/bin/bash
# shellcheck shell=bash
export TERMUX_PREFIX="/data/data/com.termux/files/usr"
export TERMUX_PACKAGE_MANAGER="pacman"
export TERMUX_PACKAGE_ARCH="aarch64"
TERMUX__USER_ID___N="TERMUX__USER_ID"
TERMUX__USER_ID="${!TERMUX__USER_ID___N:-}"
function log() { echo "[*]" "$@"; }
function log_error() { echo "[*]" "$@" 1>&2; }
run_package_postinst_maintainer_scripts() {
local return_value
local package_name
local package_version
local package_dir
local package_dir_basename
local script_path
local script_basename
if [ ${TERMUX_PACKAGE_MANAGER} = "pacman" ]; then
# - https://wiki.archlinux.org/title/PKGBUILD#install
# - https://gitlab.archlinux.org/pacman/pacman/-/blob/v6.1.0/lib/libalpm/add.c#L638-L647
if [ -d "${TERMUX_PREFIX}/var/lib/pacman/local" ]; then
# Package install files exist at `/var/lib/pacman/local/package-version/install`
for script_path in "${TERMUX_PREFIX}/var/lib/pacman/local/"*/install; do
package_dir="${script_path::-8}"
package_dir_basename="${package_dir##*/}"
# Extract package `version` in the format `epoch:pkgver-pkgrel`
# from the package_dir_basename in the format `package-version`.
# Do not use external programs to parse as that would require
# adding it as a dependency for second-stage.
# - https://wiki.archlinux.org/title/PKGBUILD#Version
# Set to anything after last dash "-"
local package_version_pkgrel="${package_dir_basename##*-}"
# Set to anything before and including last dash "-"
local package_name_and_version_pkgver="${package_dir_basename%"$package_version_pkgrel"}"
# Trim trailing dash "-"
package_name_and_version_pkgver="${package_name_and_version_pkgver%?}"
# Set to anything after last dash "-"
local package_version_pkgver="${package_name_and_version_pkgver##*-}"
# Combine pkgver and pkgrel
package_version="$package_version_pkgver-$package_version_pkgrel"
if [[ ! "$package_version" =~ ^([0-9]+:)?[^-]+-[^-]+$ ]]; then
log_error "The package_version '$package_version' extracted from package_dir_basename '$package_dir_basename' is not valid"
return 1
fi
if grep -q update-alternatives "$script_path"; then
log "Running '$package_dir_basename' package post_install"
(
# As per `pacman` install docs:
# > Each function is run chrooted inside the pacman install directory. See this thread.
# The `RootDir` is chrooted into and then the
# current working directory is changed to `/`.
# - https://bbs.archlinux.org/viewtopic.php?pid=913891
# - https://man.archlinux.org/man/pacman.conf.5.en#OPTIONS
# - https://gitlab.archlinux.org/pacman/pacman/-/blob/v6.1.0/src/pacman/conf.c#L855
# - https://gitlab.archlinux.org/pacman/pacman/-/blob/v6.1.0/lib/libalpm/alpm.c#L47
# - https://gitlab.archlinux.org/pacman/pacman/-/blob/v6.1.0/lib/libalpm/alpm.h#L1663-L1676
# - https://gitlab.archlinux.org/pacman/pacman/-/blob/v6.1.0/lib/libalpm/util.c#L657-L668
# - https://man7.org/linux/man-pages/man2/chroot.2.html
# But since Android apps cannot run chroot
# without root access, chroot is disabled by
# Termux pacman package and only current working
# directory is changed to the Android rootfs `/`.
# Note that Termux rootfs is under private app
# data directory `/data/data/<package_name>,`
# which may cause problems for packages which try
# to use Android rootfs paths instead of Termux
# rootfs paths.
# - https://github.com/termux/termux-packages/blob/953b9f2aac0dc94f3b99b2df6af898e0a95d5460/packages/pacman/util.c.patch
cd "/" || exit $?
# Source the package `install` file and execute
# `post_install` function if defined.
# Unset function if already defined in the env
unset -f post_install || exit $?
# shellcheck disable=SC1090
source "$script_path"
return_value=$?
if [ $return_value -ne 0 ]; then
log_error "Failed to source '$package_dir_basename' package install install"
exit $return_value
fi
if [[ "$(type -t post_install 2>/dev/null)" == "function" ]]; then
# cd again in case install file sourced changed the directory.
cd "/" || exit $?
# Execute the post_install function and exit
# with failure if it fails as that implies
# that bootstrap setup failed.
# The package version is the first argument.
# Check `PKGBUILD#install` docs for more info.
post_install "$package_version"
return_value=$?
if [ $return_value -ne 0 ]; then
log_error "Failed to run '$package_dir_basename' package post_install"
exit $return_value
fi
fi
) || return $?
fi
done
fi
fi
return 0
}
if [ ! -f "/data/data/com.termux/files/usr/etc/.darkcustom/uafix.lock" ]; then
echo "fixing broken packages after update-alternatives mayhem..."
touch /data/data/com.termux/files/usr/etc/.darkcustom/uafix.lock
run_package_postinst_maintainer_scripts
else
echo "update-alternatives fix already installed, doing nothing."
fi

10
darkline-postinst.install Normal file
View File

@@ -0,0 +1,10 @@
post_install() {
echo "Running all afterthought fixes..."
for f in /data/data/com.termux/usr/etc/.darkcustom/fixes/*.sh; do
bash "$f"
done
}
post_upgrade() {
post_install
}