Skip to content

Commit 7493c3a

Browse files
committed
Test changes
1 parent a04f45d commit 7493c3a

10 files changed

+183
-170
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: 6 additions & 8 deletions
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+
786056cd99fb2517c30e13db1834e7d16ed4650bfeb428e39b7acfd85d4abce9)
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"
@@ -38,12 +38,10 @@ termux_step_post_make_install() {
3838
mkdir -p $TERMUX_PREFIX/etc/pacman.d
3939
install -m644 $TERMUX_PKG_BUILDER_DIR/serverlist $TERMUX_PREFIX/etc/pacman.d/serverlist
4040
install -m755 $TERMUX_PKG_SRCDIR/pacman-switch-main/pacman-switch.sh $TERMUX_PREFIX/bin/pacman-switch
41-
}
4241

43-
termux_step_post_massage() {
44-
mkdir -p ./var/lib/pacman/sync
45-
mkdir -p ./var/lib/pacman/local
46-
mkdir -p ./var/cache/pacman/pkg
47-
mkdir -p ./share/pacman-switch
48-
mkdir -p ./var/lib/pacman/switch
42+
for dir in var/lib/pacman/{sync,local,switch} var/cache/pacman/pkg share/pacman-switch; do
43+
dir="${TERMUX_PREFIX}/${dir}"
44+
mkdir -p ${dir}
45+
touch ${dir}/.placeholder
46+
done
4947
}

packages/pacman/run-pacman-switch.alpm.script

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@ sws=()
66
export _PS_RUN_IN_ALPM_HOOKS=true
77

88
while read -r i; do
9-
sws+=("$(basename "${i//.sw/}")")
9+
sw="$(basename "${i//.sw/}")"
10+
if [[ -n "${sw}" && "${sw}" != "*" ]]; then
11+
sws+=("${sw}")
12+
fi
1013
done
1114

12-
if [[ "${1}" = "update" || "${1}" = "disable" ]]; then
15+
if [[ -n "${sws}" && ("${1}" = "update" || "${1}" = "disable") ]]; then
1316
sws=($(pacman-switch -Qs ${sws[@]}))
14-
if [ -z "${sws}" ]; then
15-
exit 0
16-
fi
17+
fi
18+
19+
if [ -z "${sws}" ]; then
20+
exit 0
1721
fi
1822

1923
case "${1}" in

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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
termux_step_install_switcher_files() {
2+
local i
3+
for i in "${TERMUX_PKG_BUILDER_DIR}"/*.alternatives; do
4+
[[ -f "${i}" ]] || continue
5+
local -a NAME=()
6+
local -A DEPENDENTS=() LINK=() ALTERNATIVE=() PRIORITY=()
7+
termux_alternatives__parse_alternatives_file "${i}"
8+
9+
mkdir -p "${TERMUX_PREFIX_CLASSICAL}/share/pacman-switch"
10+
{
11+
local name
12+
for name in "${NAME[@]}"; do
13+
echo "switcher_group_${name}() {"
14+
echo " priority=${PRIORITY[$name]}"
15+
echo " associations=(${LINK[$name]}:${ALTERNATIVE[$name]}${DEPENDENTS[$name]})"
16+
echo "}"
17+
done
18+
} > "${TERMUX_PREFIX_CLASSICAL}/share/pacman-switch/$(basename "${i//.alternatives/.sw}")"
19+
done
20+
}

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+
}

0 commit comments

Comments
 (0)