Skip to content

Commit 45d8e20

Browse files
committed
Test changes
1 parent 7560963 commit 45d8e20

9 files changed

+168
-158
lines changed

build-package.sh

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ source "$TERMUX_SCRIPTDIR/scripts/utils/docker/docker.sh"; docker__create_docker
3030
# Source the `termux_package` library.
3131
source "$TERMUX_SCRIPTDIR/scripts/utils/termux/package/termux_package.sh"
3232

33+
# Source the `termux_alternatives` library.
34+
source "$TERMUX_SCRIPTDIR/scripts/utils/termux/alternatives/termux_alternatives.sh"
35+
3336
export SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH:-$(git -c log.showSignature=false log -1 --pretty=%ct 2>/dev/null || date "+%s")}
3437

3538
if [ "$(uname -o)" = "Android" ] || [ -e "/system/bin/app_process" ]; then
@@ -331,6 +334,10 @@ termux_step_post_make_install() {
331334
# shellcheck source=scripts/build/termux_step_install_pacman_hooks.sh
332335
source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_install_pacman_hooks.sh"
333336

337+
# Install switcher files that will provide alternatives for pacman package
338+
# shellcheck source=scripts/build/termux_step_install_switcher_files.sh
339+
source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_install_switcher_files.sh"
340+
334341
# Add service scripts from array TERMUX_PKG_SERVICE_SCRIPT, if it is set
335342
# shellcheck source=scripts/build/termux_step_install_service_scripts.sh
336343
source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_install_service_scripts.sh"
@@ -396,8 +403,8 @@ source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_create_pacman_package.sh"
396403

397404
# Process 'update-alternatives' entries from `.alternatives` files.
398405
# Not to be overridden by package scripts.
399-
# shellcheck source=scripts/build/termux_step_setup_alternatives.sh
400-
source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_setup_alternatives.sh"
406+
# shellcheck source=scripts/build/termux_step_update_alternatives.sh
407+
source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_update_alternatives.sh"
401408

402409
# Finish the build. Not to be overridden by package scripts.
403410
# shellcheck source=scripts/build/termux_step_finish_build.sh
@@ -751,7 +758,10 @@ for ((i=0; i<${#PACKAGE_LIST[@]}; i++)); do
751758
termux_run_base_and_multilib_build_step termux_step_make_install
752759
cd "$TERMUX_PKG_BUILDDIR"
753760
termux_step_post_make_install
754-
termux_step_install_pacman_hooks
761+
if [ "$TERMUX_PACKAGE_FORMAT" = "pacman" ]; then
762+
termux_step_install_pacman_hooks
763+
termux_step_install_switcher_files
764+
fi
755765
termux_step_install_service_scripts
756766
termux_step_install_license
757767
cd "$TERMUX_PKG_MASSAGEDIR"

packages/pacman/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ TERMUX_PKG_REVISION=5
77
TERMUX_PKG_SRCURL=(https://gitlab.archlinux.org/pacman/pacman/-/releases/v${TERMUX_PKG_VERSION}/downloads/pacman-${TERMUX_PKG_VERSION}.tar.xz
88
https://github.com/termux-pacman/pacman-switch/archive/refs/heads/main.zip)
99
TERMUX_PKG_SHA256=(61cbd445d1381b4b184bc7c4e2791f07a79f0f2807b7c600399d0d08e8cd28cf
10-
707669cd9700916254890ce0bf0bd2a0c93e53610bf3540b06dd0e99110178f9)
10+
1a2886d106a3895060f38d51fb9682635d6f03b06697b485adbd37e715fc7d03)
1111
TERMUX_PKG_DEPENDS="bash, curl, gpgme, libandroid-glob, libarchive, libcurl, openssl, termux-licenses, termux-keyring"
1212
TERMUX_PKG_BUILD_DEPENDS="doxygen, asciidoc, nettle"
1313
TERMUX_PKG_GROUPS="base-devel"

scripts/build/termux_step_create_debian_package.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ termux_step_create_debian_package() {
5353
termux_step_create_debscripts
5454
# Process `update-alternatives` entries from `.alternatives` files
5555
# These need to be merged into the `.postinst` and `.prerm` files, so after those are created.
56-
termux_step_setup_alternatives
56+
termux_step_update_alternatives
5757

5858
# Create control.tar.xz
5959
tar --sort=name \

scripts/build/termux_step_create_pacman_package.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,6 @@ termux_step_create_pacman_package() {
122122

123123
# Write installation hooks.
124124
termux_step_create_debscripts
125-
# Process `update-alternatives` entries from `.alternatives` files
126-
# These need to be merged into the `.postinst` and `.prerm` files, so after those are created.
127-
termux_step_setup_alternatives
128125
termux_step_create_pacman_install_hook
129126

130127
# ensure all elements of the package have the same mtime

scripts/build/termux_step_install_pacman_hooks.sh

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
termux_step_install_pacman_hooks() {
2-
[[ "$TERMUX_PACKAGE_FORMAT" != "pacman" ]] && return
3-
4-
local sed="sed -e s|@TERMUX_PREFIX@|${TERMUX_PREFIX}|g -e s|@TERMUX_PREFIX_TARGET@|${TERMUX_PREFIX:1}|g -e s|@TERMUX_ARCH@|${TERMUX_ARCH}|g"
2+
local sed="sed -e s|@TERMUX_PREFIX@|${TERMUX_PREFIX_CLASSICAL}|g -e s|@TERMUX_PREFIX_TARGET@|${TERMUX_PREFIX_CLASSICAL:1}|g -e s|@TERMUX_ARCH@|${TERMUX_ARCH}|g"
53

64
# Installing hooks
75
local hooks
@@ -10,7 +8,7 @@ termux_step_install_pacman_hooks() {
108
mkdir -p ${TERMUX_PREFIX}/share/libalpm/hooks
119
local hook
1210
for hook in ${hooks}; do
13-
${sed} "${hook}" > "${TERMUX_PREFIX}/share/libalpm/hooks/$(sed 's|.alpm.hook$|.hook|' <<< "${hook##*/}")"
11+
${sed} "${hook}" > "${TERMUX_PREFIX_CLASSICAL}/share/libalpm/hooks/$(sed 's|.alpm.hook$|.hook|' <<< "${hook##*/}")"
1412
done
1513
fi
1614

@@ -21,7 +19,7 @@ termux_step_install_pacman_hooks() {
2119
mkdir -p ${TERMUX_PREFIX}/share/libalpm/scripts
2220
local script script_alpm
2321
for script in ${scripts}; do
24-
script_alpm="${TERMUX_PREFIX}/share/libalpm/scripts/$(sed 's|.alpm.script$||' <<< "${script##*/}")"
22+
script_alpm="${TERMUX_PREFIX_CLASSICAL}/share/libalpm/scripts/$(sed 's|.alpm.script$||' <<< "${script##*/}")"
2523
${sed} "${script}" > "${script_alpm}"
2624
chmod +x "${script_alpm}"
2725
done
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
termux_step_install_switcher_files() {
2+
local i
3+
for i in "${TERMUX_PKG_BUILDER_DIR}"/*.alternatives; do
4+
local -a NAME=()
5+
local -A DEPENDENTS=() LINK=() ALTERNATIVE=() PRIORITY=()
6+
termux_alternatives__parse_alternatives_file "${i}"
7+
8+
mkdir -p "${TERMUX_PREFIX_CLASSICAL}/share/pacman-switch"
9+
{
10+
local name
11+
for name in "${NAME[@]}"; do
12+
echo "switcher_group_${name}() {"
13+
echo " priority=${PRIORITY[$name]}"
14+
echo " points=(${LINK[$name]}:${ALTERNATIVE[$name]}${DEPENDENTS[$name]})"
15+
echo "}"
16+
done
17+
} > "${TERMUX_PREFIX_CLASSICAL}/share/pacman-switch/$(basename "${i//.alternatives/.sw}")"
18+
done
19+
}

scripts/build/termux_step_setup_alternatives.sh

Lines changed: 0 additions & 145 deletions
This file was deleted.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# shellcheck shell=bash
2+
3+
termux_step_update_alternatives() {
4+
printf '%s\n' "INFO: Processing 'update-alternatives' entries:" 1>&2
5+
for alternatives_file in "${TERMUX_PKG_BUILDER_DIR}"/*.alternatives; do
6+
[[ -f "$alternatives_file" ]] || continue
7+
local -a NAME=()
8+
local -A DEPENDENTS=() LINK=() ALTERNATIVE=() PRIORITY=()
9+
termux_alternatives__parse_alternatives_file "$alternatives_file"
10+
11+
# Handle postinst script
12+
[[ -f postinst ]] && mv postinst{,.orig}
13+
14+
local name
15+
16+
{ # Splice in the alternatives
17+
# Use the original shebang if there's a 'postinst.orig'
18+
[[ -f postinst.orig ]] && head -n1 postinst.orig || echo "#!${TERMUX_PREFIX}/bin/sh"
19+
# Boilerplate header comment and checks
20+
echo "# Automatically added by termux_step_update_alternatives"
21+
echo "if [ \"\$1\" = 'configure' ] || [ \"\$1\" = 'abort-upgrade' ] || [ \"\$1\" = 'abort-deconfigure' ] || [ \"\$1\" = 'abort-remove' ]; then"
22+
echo " if [ -x \"${TERMUX_PREFIX}/bin/update-alternatives\" ]; then"
23+
# 'update-alternatives' command for each group
24+
for name in "${NAME[@]}"; do
25+
# Main alternative group
26+
printf '%b' \
27+
" # ${name}\n" \
28+
" update-alternatives" $' \\\n' \
29+
" --install \"${TERMUX_PREFIX}/${LINK[$name]}\" \"${name}\" \"${TERMUX_PREFIX}/${ALTERNATIVE[$name]}\" ${PRIORITY[$name]}"
30+
# If we have dependents, add those as well
31+
if [[ -n "${DEPENDENTS[$name]}" ]]; then
32+
# We need to add a ' \<lf>' to the --install line,
33+
# and remove the last ' \<lf>' from the dependents.
34+
printf ' \\\n%s' "${DEPENDENTS[$name]%$' \\\n'}"
35+
fi
36+
echo ""
37+
done
38+
# Close up boilerplate and add end comment
39+
echo " fi"
40+
echo "fi"
41+
echo "# End automatically added section"
42+
} > postinst
43+
if [[ -f postinst.orig ]]; then
44+
tail -n+2 postinst.orig >> postinst
45+
rm postinst.orig
46+
fi
47+
48+
# Handle prerm script
49+
[[ -f prerm ]] && mv prerm{,.orig}
50+
51+
{ # Splice in the alternatives
52+
# Use the original shebang if there's a 'prerm.orig'
53+
[[ -f prerm.orig ]] && head -n1 prerm.orig || echo "#!${TERMUX_PREFIX}/bin/sh"
54+
# Boilerplate header comment and checks
55+
echo "# Automatically added by termux_step_update_alternatives"
56+
echo "if [ \"\$1\" = 'remove' ] || [ \"\$1\" != 'upgrade' ]; then"
57+
echo " if [ -x \"${TERMUX_PREFIX}/bin/update-alternatives\" ]; then"
58+
# Remove each group
59+
for name in "${NAME[@]}"; do
60+
# Log message for this alternative group
61+
printf 'INFO: %s\n' "${name} -> ${ALTERNATIVE[$name]} (${PRIORITY[$name]})" 1>&2
62+
# Removal line
63+
printf '%s\n' " update-alternatives --remove \"${name}\" \"${TERMUX_PREFIX}/${ALTERNATIVE[$name]}\""
64+
done
65+
# Close up boilerplate and add end comment
66+
echo " fi"
67+
echo "fi"
68+
echo "# End automatically added section"
69+
} > prerm
70+
if [[ -f prerm.orig ]]; then
71+
tail -n+2 prerm.orig >> prerm
72+
rm prerm.orig
73+
fi
74+
done
75+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# shellcheck shell=bash
2+
3+
# Title: termux_alternatives
4+
# Description: A library for working with Termux package Alternatives.
5+
6+
7+
8+
##
9+
# Parse datas from the alternatives file and put the datas into the variables.
10+
# .
11+
# .
12+
# **Parameters:**
13+
# `path_to_alternatives_file` - The path to the package's `.alternatives` file.
14+
# .
15+
# **Returns:**
16+
# returns their contents in the associative arrays:
17+
# ${LINK[@]} ${[ALTERNATIVE[@]} ${DEPENDENTS[@]} ${PRIORITY[@]}
18+
# .
19+
# .
20+
# termux_alternatives__parse_alternatives_file <path_to_alternatives_file>
21+
##
22+
termux_alternatives__parse_alternatives_file() {
23+
local line key value
24+
local dependents=0
25+
while IFS=$'\n' read -r line; do
26+
27+
key="${line%%:*}" # Part before the first ':'
28+
value="${line#*:[[:blank:]]*}" # Part after the first `:`, leading whitespace stripped
29+
30+
case "$key" in
31+
'Name') NAME+=("$value") dependents=0 ;;
32+
'Link') LINK[${NAME[-1]}]="$value" dependents=0 ;;
33+
'Alternative') ALTERNATIVE[${NAME[-1]}]="$value" dependents=0 ;;
34+
'Priority') PRIORITY[${NAME[-1]}]="$value" dependents=0 ;;
35+
'Dependents') dependents=1; continue;;
36+
esac
37+
38+
if (( dependents )); then
39+
read -r dep_link dep_name dep_alternative <<< "$line"
40+
if [ "${TERMUX_PACKAGE_FORMAT}" = "pacman" ]; then
41+
# Data format for pacman-switch
42+
DEPENDENTS[${NAME[-1]}]+=" ${dep_link}:${dep_alternative}"
43+
else
44+
# Data format for update-alternatives
45+
DEPENDENTS[${NAME[-1]}]+=" --slave \"${TERMUX_PREFIX_CLASSICAL}/${dep_link}\" \"${dep_name}\" \"${TERMUX_PREFIX_CLASSICAL}/${dep_alternative}\""$' \\\n'
46+
fi
47+
fi
48+
49+
done < <(sed -e 's|\s*#.*$||g' "$1") # Strip out any comments
50+
51+
for key in "${NAME[@]}"; do
52+
# Not every entry will have dependents in its group
53+
# but we need to initialize the keys regardless
54+
: "${DEPENDENTS[$key]:=}"
55+
done
56+
}

0 commit comments

Comments
 (0)