Skip to content

Instantly share code, notes, and snippets.

@spacelatte
Last active October 26, 2023 21:49
Show Gist options
  • Save spacelatte/78fcbd8fcba3943b65c6ebd50c55b215 to your computer and use it in GitHub Desktop.
Save spacelatte/78fcbd8fcba3943b65c6ebd50c55b215 to your computer and use it in GitHub Desktop.
#bash #build #install #auto #script #compile #source
#!/usr/bin/env bash
set -eo pipefail
# 5.0.18
# 5.1.16
# 5.2.15
VERSION="${1:-5.2.15}"
SOURCE="https://ftp.gnu.org/gnu/bash/bash-${VERSION}.tar.gz"
CURRDIR="$(pwd)"
TEMPDIR="$(mktemp -d)"
#trap 'rm -rf "${TEMPDIR}"; ' EXIT #ERR
curl -#L "${SOURCE}" \
| tar --strip=1 -xzC "${TEMPDIR}"
BUILDDIR="${TEMPDIR}/build.dir"
PREFIX="${HOME}/.local/opt/bash-${VERSION}"
mkdir -p "${BUILDDIR}" "${PREFIX}"
(
cd "${BUILDDIR}"
env -i ../configure --help > "${CURRDIR}/bash-${VERSION}.cfg.txt"
env -i ../configure CC=cc CFLAGS=-Os LDFLAGS=-v \
--prefix="${PREFIX}" \
--disable-profiling \
--without-gnu-ld \
--without-gnu-malloc \
--without-bash-malloc \
--with-afs \
--with-curses \
--with-included-gettext \
--with-installed-readline \
--enable-alias \
--enable-alt-array-implementation \
--enable-arith-for-command \
--enable-array-variables \
--enable-bang-history \
--enable-brace-expansion \
--enable-casemod-attributes \
--enable-casemod-expansions \
--enable-command-timing \
--enable-cond-command \
--enable-cond-regexp \
--enable-coprocesses \
--enable-debugger \
--enable-dev-fd-stat-broken \
--enable-directory-stack \
--enable-direxpand-default \
--enable-disabled-builtins \
--enable-dparen-arithmetic \
--enable-extended-glob \
--enable-extended-glob-default \
--enable-function-import \
--enable-glob-asciiranges-default \
--enable-help-builtin \
--enable-history \
--enable-job-control \
--enable-mem-scramble \
--enable-multibyte \
--enable-net-redirections \
--enable-process-substitution \
--enable-progcomp \
--enable-prompt-string-decoding \
--enable-readline \
--enable-restricted \
--enable-select \
--enable-single-help-strings \
--enable-threads=posix \
--enable-translatable-strings \
--enable-usg-echo-default \
--enable-xpg-echo-default \
--disable-separate-helpfiles \
--disable-static-link \
--disable-strict-posix-default \
;
#--enable-minimal-config
)
case $(uname) in
Darwin)
NCPU=$(sysctl -n hw.ncpu || echo 1)
;;
Linux)
NCPU=$(nproc || echo 1)
;;
*)
NCPU=0
;;
esac
NCPU=1
env -i make -C "${BUILDDIR}" -j "${NCPU}" clean install
echo "Installed to '${PREFIX}'..."
cp -vf "${BUILDDIR}/bash" "bash"
if [ -L "${PREFIX}/etc" ]; then
rm "${PREFIX}/etc"
fi
if [ ! -e "${PREFIX}/etc" ]; then
ln -vsf /etc/ "${PREFIX}/etc"
fi
exit $?
@berk-can
Copy link

What's that about

@spacelatte
Copy link
Author

What's that about

statically builds bash (currently v5.0) to use it as a shell:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment