-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Implementation of working alternatives on pacman #26482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,9 +3,11 @@ TERMUX_PKG_DESCRIPTION="A library-based package manager with dependency support" | |
| TERMUX_PKG_LICENSE="GPL-2.0" | ||
| TERMUX_PKG_MAINTAINER="@Maxython <[email protected]>" | ||
| TERMUX_PKG_VERSION=7.0.0 | ||
| TERMUX_PKG_REVISION=4 | ||
| TERMUX_PKG_SRCURL=https://gitlab.archlinux.org/pacman/pacman/-/releases/v${TERMUX_PKG_VERSION}/downloads/pacman-${TERMUX_PKG_VERSION}.tar.xz | ||
| TERMUX_PKG_SHA256=61cbd445d1381b4b184bc7c4e2791f07a79f0f2807b7c600399d0d08e8cd28cf | ||
| TERMUX_PKG_REVISION=5 | ||
| TERMUX_PKG_SRCURL=(https://gitlab.archlinux.org/pacman/pacman/-/releases/v${TERMUX_PKG_VERSION}/downloads/pacman-${TERMUX_PKG_VERSION}.tar.xz | ||
| https://github.com/termux-pacman/pacman-switch/archive/refs/heads/main.zip) | ||
| TERMUX_PKG_SHA256=(61cbd445d1381b4b184bc7c4e2791f07a79f0f2807b7c600399d0d08e8cd28cf | ||
| 786056cd99fb2517c30e13db1834e7d16ed4650bfeb428e39b7acfd85d4abce9) | ||
| TERMUX_PKG_DEPENDS="bash, curl, gpgme, libandroid-glob, libarchive, libcurl, openssl, termux-licenses, termux-keyring" | ||
| TERMUX_PKG_BUILD_DEPENDS="doxygen, asciidoc, nettle" | ||
| TERMUX_PKG_GROUPS="base-devel" | ||
|
|
@@ -25,6 +27,7 @@ termux_step_pre_configure() { | |
| rm -f ./scripts/libmakepkg/executable/fakeroot.sh.in | ||
|
|
||
| sed -i "s/@TERMUX_ARCH@/${TERMUX_ARCH}/" ./etc/{pacman,makepkg}.conf.in | ||
| sed -i "s|_ps_prefix=.*|_ps_prefix=\"${TERMUX_PREFIX}\"|" ./pacman-switch-main/pacman-switch.sh | ||
| } | ||
|
|
||
| termux_step_post_configure() { | ||
|
|
@@ -34,12 +37,11 @@ termux_step_post_configure() { | |
| termux_step_post_make_install() { | ||
| mkdir -p $TERMUX_PREFIX/etc/pacman.d | ||
| install -m644 $TERMUX_PKG_BUILDER_DIR/serverlist $TERMUX_PREFIX/etc/pacman.d/serverlist | ||
| } | ||
| install -m755 $TERMUX_PKG_SRCDIR/pacman-switch-main/pacman-switch.sh $TERMUX_PREFIX/bin/pacman-switch | ||
|
|
||
| termux_step_create_debscripts() { | ||
| echo "#!$TERMUX_PREFIX/bin/bash" > postinst | ||
| echo "mkdir -p $TERMUX_PREFIX/var/lib/pacman/sync" >> postinst | ||
| echo "mkdir -p $TERMUX_PREFIX/var/lib/pacman/local" >> postinst | ||
| echo "mkdir -p $TERMUX_PREFIX/var/cache/pacman/pkg" >> postinst | ||
| chmod 755 postinst | ||
| for dir in var/lib/pacman/{sync,local,switch} var/cache/pacman/pkg share/pacman-switch; do | ||
| dir="${TERMUX_PREFIX}/${dir}" | ||
| mkdir -p ${dir} | ||
| touch ${dir}/.placeholder | ||
| done | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| [Trigger] | ||
| Type = Path | ||
| Operation = Remove | ||
| Target = @TERMUX_PREFIX_TARGET@/share/pacman-switch/*.sw | ||
|
|
||
| [Action] | ||
| Description = Automatic disabling switchers... | ||
| When = PreTransaction | ||
| Exec = @TERMUX_PREFIX@/share/libalpm/scripts/run-pacman-switch disable | ||
| NeedsTargets |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| [Trigger] | ||
| Type = Path | ||
| Operation = Install | ||
| Target = @TERMUX_PREFIX_TARGET@/share/pacman-switch/*.sw | ||
|
|
||
| [Action] | ||
| Description = Automatic enabling switchers... | ||
| When = PostTransaction | ||
| Exec = @TERMUX_PREFIX@/share/libalpm/scripts/run-pacman-switch enable | ||
| NeedsTargets |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| [Trigger] | ||
| Type = Path | ||
| Operation = Upgrade | ||
| Target = @TERMUX_PREFIX_TARGET@/share/pacman-switch/*.sw | ||
|
|
||
| [Action] | ||
| Description = Automatic updating switchers... | ||
| When = PostTransaction | ||
| Exec = @TERMUX_PREFIX@/share/libalpm/scripts/run-pacman-switch update | ||
| NeedsTargets |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #!@TERMUX_PREFIX@/bin/bash | ||
|
|
||
| set -e | ||
|
|
||
| sws=() | ||
| export _PS_RUN_IN_ALPM_HOOKS=true | ||
|
|
||
| while read -r i; do | ||
| sw="$(basename "${i//.sw/}")" | ||
| if [[ -n "${sw}" && "${sw}" != "*" ]]; then | ||
| sws+=("${sw}") | ||
| fi | ||
| done | ||
|
|
||
| if [[ -n "${sws}" && ("${1}" = "update" || "${1}" = "disable") ]]; then | ||
| sws=($(pacman-switch -Qs ${sws[@]})) | ||
| fi | ||
|
|
||
| if [ -z "${sws}" ]; then | ||
| exit 0 | ||
| fi | ||
|
|
||
| case "${1}" in | ||
| "enable") pacman-switch -Ea ${sws[@]};; | ||
| "update") pacman-switch -Su ${sws[@]};; | ||
| "disable") pacman-switch -Da ${sws[@]};; | ||
| esac |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| termux_step_install_switcher_files() { | ||
| local i | ||
| for i in "${TERMUX_PKG_BUILDER_DIR}"/*.alternatives; do | ||
| [[ -f "${i}" ]] || continue | ||
| local -a NAME=() | ||
| local -A DEPENDENTS=() LINK=() ALTERNATIVE=() PRIORITY=() | ||
| termux_alternatives__parse_alternatives_file "${i}" | ||
|
|
||
| mkdir -p "${TERMUX_PREFIX_CLASSICAL}/share/pacman-switch" | ||
| { | ||
| local name | ||
| for name in "${NAME[@]}"; do | ||
| echo "switcher_group_${name}() {" | ||
| echo " priority=${PRIORITY[$name]}" | ||
| echo " associations=(${LINK[$name]}:${ALTERNATIVE[$name]}${DEPENDENTS[$name]})" | ||
| echo "}" | ||
| done | ||
| } > "${TERMUX_PREFIX_CLASSICAL}/share/pacman-switch/$(basename "${i//.alternatives/.sw}")" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's wrong with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I did this to make it easier for |
||
| done | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,57 +1,24 @@ | ||
| # shellcheck shell=bash | ||
|
|
||
| # The Debian `.alternatives` format is a simple ad-hoc plain text format | ||
| # to declaratively define groups for `update-alternatives`. | ||
| # This function parses files of this format and returns their contents | ||
| # in the associative arrays: ${LINK[@]} ${[ALTERNATIVE@]} ${DEPENDENTS[@]} ${PRIORITY[@]} | ||
| termux_parse_alternatives() { | ||
| local line key value | ||
| local dependents=0 | ||
| while IFS=$'\n' read -r line; do | ||
|
|
||
| key="${line%%:*}" # Part before the first ':' | ||
| value="${line#*:[[:blank:]]*}" # Part after the first `:`, leading whitespace stripped | ||
|
|
||
| case "$key" in | ||
| 'Name') NAME+=("$value") dependents=0 ;; | ||
| 'Link') LINK[${NAME[-1]}]="$value" dependents=0 ;; | ||
| 'Alternative') ALTERNATIVE[${NAME[-1]}]="$value" dependents=0 ;; | ||
| 'Priority') PRIORITY[${NAME[-1]}]="$value" dependents=0 ;; | ||
| 'Dependents') dependents=1; continue;; | ||
| esac | ||
|
|
||
| if (( dependents )); then | ||
| read -r dep_link dep_name dep_alternative <<< "$line" | ||
| DEPENDENTS[${NAME[-1]}]+=" --slave \"${TERMUX_PREFIX}/${dep_link}\" \"${dep_name}\" \"${TERMUX_PREFIX}/${dep_alternative}\""$' \\\n' | ||
| fi | ||
|
|
||
| done < <(sed -e 's|\s*#.*$||g' "$1") # Strip out any comments | ||
| } | ||
|
|
||
| termux_step_update_alternatives() { | ||
| printf '%s\n' "INFO: Processing 'update-alternatives' entries:" 1>&2 | ||
| for alternatives_file in "${TERMUX_PKG_BUILDER_DIR}"/*.alternatives; do | ||
| [[ -f "$alternatives_file" ]] || continue | ||
| local -a NAME=() | ||
| local -A DEPENDENTS=() LINK=() ALTERNATIVE=() PRIORITY=() | ||
| termux_parse_alternatives "$alternatives_file" | ||
| termux_alternatives__parse_alternatives_file "$alternatives_file" | ||
|
|
||
| # Handle postinst script | ||
| [[ -f postinst ]] && mv postinst{,.orig} | ||
|
|
||
| local name | ||
| for name in "${NAME[@]}"; do | ||
| # Not every entry will have dependents in its group | ||
| # but we need to initialize the keys regardless | ||
| : "${DEPENDENTS[$name]:=}" | ||
| done | ||
|
Comment on lines
-43
to
-47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moving this into the function is a good call since it's a concern of the function and shouldn't need to be handled at the callsite. |
||
|
|
||
| { # Splice in the alternatives | ||
| # Use the original shebang if there's a 'postinst.orig' | ||
| [[ -f postinst.orig ]] && head -n1 postinst.orig || echo "#!${TERMUX_PREFIX}/bin/sh" | ||
| # Boilerplate header comment and checks | ||
| echo "# Automatically added by termux_step_update_alternatives" | ||
| echo "if [ \"\$1\" = 'configure' ] || [ \"\$1\" = 'abort-upgrade' ] || [ \"\$1\" = 'abort-deconfigure' ] || [ \"\$1\" = 'abort-remove' ] || [ \"${TERMUX_PACKAGE_FORMAT}\" = 'pacman' ]; then" | ||
| echo "if [ \"\$1\" = 'configure' ] || [ \"\$1\" = 'abort-upgrade' ] || [ \"\$1\" = 'abort-deconfigure' ] || [ \"\$1\" = 'abort-remove' ]; then" | ||
| echo " if [ -x \"${TERMUX_PREFIX}/bin/update-alternatives\" ]; then" | ||
| # 'update-alternatives' command for each group | ||
| for name in "${NAME[@]}"; do | ||
|
|
@@ -86,7 +53,7 @@ termux_step_update_alternatives() { | |
| [[ -f prerm.orig ]] && head -n1 prerm.orig || echo "#!${TERMUX_PREFIX}/bin/sh" | ||
| # Boilerplate header comment and checks | ||
| echo "# Automatically added by termux_step_update_alternatives" | ||
| echo "if [ \"\$1\" = 'remove' ] || [ \"\$1\" != 'upgrade' ] || [ \"${TERMUX_PACKAGE_FORMAT}\" = 'pacman' ]; then" | ||
| echo "if [ \"\$1\" = 'remove' ] || [ \"\$1\" != 'upgrade' ]; then" | ||
| echo " if [ -x \"${TERMUX_PREFIX}/bin/update-alternatives\" ]; then" | ||
| # Remove each group | ||
| for name in "${NAME[@]}"; do | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| # shellcheck shell=bash | ||
|
|
||
| # Title: termux_alternatives | ||
| # Description: A library for working with Termux package Alternatives. | ||
|
|
||
|
|
||
|
|
||
| ## | ||
| # Parse datas from the alternatives file and put the datas into the variables. | ||
| # . | ||
| # . | ||
| # **Parameters:** | ||
| # `path_to_alternatives_file` - The path to the package's `.alternatives` file. | ||
| # . | ||
| # **Returns:** | ||
| # returns their contents in the associative arrays: | ||
| # ${LINK[@]} ${[ALTERNATIVE[@]} ${DEPENDENTS[@]} ${PRIORITY[@]} | ||
| # . | ||
| # . | ||
| # termux_alternatives__parse_alternatives_file <path_to_alternatives_file> | ||
| ## | ||
|
Comment on lines
+8
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the rewritten function comment is overly verbose and loses some of the original information. I'm also not sure why this got moved to a new function (pseudo-)namespace. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I needed to move the function to utils so that it could be used not only in Regarding the function naming and its comments/description, this is a standard for scripts in utils (at least in |
||
| termux_alternatives__parse_alternatives_file() { | ||
| local line key value | ||
| local dependents=0 | ||
| while IFS=$'\n' read -r line; do | ||
|
|
||
| key="${line%%:*}" # Part before the first ':' | ||
| value="${line#*:[[:blank:]]*}" # Part after the first `:`, leading whitespace stripped | ||
|
|
||
| case "$key" in | ||
| 'Name') NAME+=("$value") dependents=0 ;; | ||
| 'Link') LINK[${NAME[-1]}]="$value" dependents=0 ;; | ||
| 'Alternative') ALTERNATIVE[${NAME[-1]}]="$value" dependents=0 ;; | ||
| 'Priority') PRIORITY[${NAME[-1]}]="$value" dependents=0 ;; | ||
| 'Dependents') dependents=1; continue;; | ||
| esac | ||
|
|
||
| if (( dependents )); then | ||
| read -r dep_link dep_name dep_alternative <<< "$line" | ||
| if [ "${TERMUX_PACKAGE_FORMAT}" = "pacman" ]; then | ||
| # Data format for pacman-switch | ||
| DEPENDENTS[${NAME[-1]}]+=" ${dep_link}:${dep_alternative}" | ||
| else | ||
| # Data format for update-alternatives | ||
| DEPENDENTS[${NAME[-1]}]+=" --slave \"${TERMUX_PREFIX_CLASSICAL}/${dep_link}\" \"${dep_name}\" \"${TERMUX_PREFIX_CLASSICAL}/${dep_alternative}\""$' \\\n' | ||
| fi | ||
| fi | ||
|
|
||
| done < <(sed -e 's|\s*#.*$||g' "$1") # Strip out any comments | ||
|
|
||
| for key in "${NAME[@]}"; do | ||
| # Not every entry will have dependents in its group | ||
| # but we need to initialize the keys regardless | ||
| : "${DEPENDENTS[$key]:=}" | ||
| done | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing you made this
refs/heads/mainfor testing.In a final version of this that should be pinned to a specific commit or release tag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you got it right. When
pacman-switchis fully ready, I'll make a pinned release.