Skip to content

Commit 3fb21f7

Browse files
committed
setup-util-bash: support patches, use mirrors
`ftp.gnu.org` isn't intended for crowd-sourced binary downloads, instead they recommended using `ftpmirror.gnu.org`, which is way faster this also add support for compiling bash with patches I imagine the patch stuff should also apply for gawk, and gsed too - but that will be for later
1 parent da80b37 commit 3fb21f7

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

commands/is-bash-version-outdated

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ function is_bash_version_outdated_test() (
2323
bash_version_latest_available="$(
2424
fetch 'https://ftp.gnu.org/gnu/bash/?C=M;O=D' | echo-regexp -o --regexp='href="bash-([0-9.]+?)[.]tar[.]gz"' --replace='$1'
2525
)"
26+
# to fetch all bash versions:
27+
# fetch 'https://ftp.gnu.org/gnu/bash/?C=M;O=D' | echo-regexp -go --regexp='href="bash-([0-9.]+?)[.]tar[.]gz"' --replace='$1'
2628
eval-tester --name='latest known bash version is latest available' --stdout="$bash_version_latest_available" -- \
2729
printf '%s' "$BASH_VERSION_LATEST"
2830
)

commands/setup-util-bash

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,42 @@ function setup_util_bash() (
4949
source "$(type -P setup-util)"
5050

5151
# @todo support uninstall
52+
53+
# https://www.gnu.org/prep/ftp.html'
54+
function __get_bash_patches {
55+
local patches_url="$1"
56+
fetch "$patches_url" | echo-regexp -gno --regexp='href="(bash[^"]+)' --replace='$1' | grep --invert-match --regexp='\.sig$' | sort # sort here, as dependning on the mirror, a different sort order will be returned, and they must be sorted by ascending name
57+
}
5258
function do_install {
59+
# dependencies
5360
setup-util-devel --quiet
5461
setup-util --quiet --cli='yacc' APT='byacc' BREW='byacc'
5562
source "$DOROTHY/sources/environment.sh"
63+
# patches
64+
local version
65+
# don't look to ./configure as that is only minor version, and we want the patch version, which should be in the path
66+
# version="$(echo-regexp -o --regexp='BASHVERS=(.+)' --replace='$1' <./configure)" || return
67+
version="$(pwd | echo-regexp -o --regexp='/bash-([^/]+)/' --replace='$1' || :)"
68+
# if it isn't in the path, then it we aren't doing a versioned download, and just getting the latest, so use that
69+
if [[ -z $version ]]; then
70+
version="$BASH_VERSION_LATEST"
71+
fi
72+
# if the version has a patch, we don't need to patch
73+
if [[ $version == *.*.* ]]; then
74+
__print_style --stderr --bold='Bash version ' --code="$version" --bold=' is already patched.'
75+
else
76+
local patches_url patches=() patch patch_url patch_content
77+
patches_url="https://ftpmirror.gnu.org/gnu/bash/bash-${version}-patches/"
78+
__split --target={patches} --no-zero-length --invoke=try -- \
79+
__get_bash_patches "$patches_url" || return
80+
for patch in "${patches[@]}"; do
81+
patch_url="${patches_url}${patch}"
82+
# __print_style --stderr --bold='Patching ' --code="$patch" --bold=' from ' --path="$patch_url"
83+
down --url="$patch_url" --file="$patch" || return
84+
patch --input="$patch" -p0 # p0 is necessary for linux builds
85+
done
86+
fi
87+
# compile
5688
./configure CFLAGS="-DSSH_SOURCE_BASHRC ${CFLAGS-}" CPPFLAGS="-w -Wno-error=all ${CPPFLAGS-}" LDFLAGS="-s ${LDFLAGS-}"
5789
make
5890
}
@@ -61,7 +93,7 @@ function setup_util_bash() (
6193
--cli="bash-$version"
6294
--order='download'
6395
"$@"
64-
DOWNLOAD="https://ftp.gnu.org/gnu/bash/bash-${version}.tar.gz"
96+
DOWNLOAD="https://ftpmirror.gnu.org/gnu/bash/bash-${version}.tar.gz"
6597
DOWNLOAD_ARCHIVE_FORMAT='tar'
6698
DOWNLOAD_ARCHIVE_GLOB='bash-*/*'
6799
DOWNLOAD_BUILD_INSTALL='do_install'
@@ -182,7 +214,7 @@ function setup_util_bash() (
182214
)
183215
else
184216
options+=(
185-
DOWNLOAD="https://ftp.gnu.org/gnu/bash/bash-${BASH_VERSION_LATEST}.tar.gz"
217+
DOWNLOAD="https://ftpmirror.gnu.org/gnu/bash/bash-${BASH_VERSION_LATEST}.tar.gz"
186218
DOWNLOAD_ARCHIVE_FORMAT='tar'
187219
DOWNLOAD_ARCHIVE_GLOB='bash-*/*'
188220
DOWNLOAD_TARGET_PATH="$XDG_PREFIX/bin/bash"

commands/setup-util-gawk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function setup_util_gawk() (
6161
}
6262
options+=(
6363
# https://ftp.gnu.org/gnu/gawk/?C=M;O=D
64-
DOWNLOAD="https://ftp.gnu.org/gnu/gawk/gawk-5.3.1.tar.xz"
64+
DOWNLOAD="https://ftpmirror.gnu.org/gnu/gawk/gawk-5.3.1.tar.xz"
6565
DOWNLOAD_ARCHIVE_FORMAT='tar'
6666
DOWNLOAD_ARCHIVE_GLOB='gawk-*/*'
6767
DOWNLOAD_TARGET_PATH="$XDG_PREFIX/bin/gawk"

commands/setup-util-gsed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function setup_util_gsed() (
8686
options+=(
8787
--cli=sed
8888
# https://ftp.gnu.org/gnu/sed/?C=M;O=D
89-
DOWNLOAD="https://ftp.gnu.org/gnu/sed/sed-4.9.tar.xz"
89+
DOWNLOAD="https://ftpmirror.gnu.org/gnu/sed/sed-4.9.tar.xz"
9090
DOWNLOAD_ARCHIVE_FORMAT='tar'
9191
DOWNLOAD_ARCHIVE_GLOB='sed-*/*'
9292
DOWNLOAD_TARGET_PATH="$XDG_PREFIX/bin/sed"

0 commit comments

Comments
 (0)