# Contributor: Ɓukasz Jendrysik <scadu@yandex.com>
# Contributor: TBK <alpine@jjtc.eu>
# Maintainer: Elizabeth Myers <elizabeth@adelielinux.org>
pkgname=bash
pkgver=4.4.23
_patchlevel=${pkgver##*.}
_myver=${pkgver%.*}
_patchbase=$(printf '%s' "$_myver" | tr -d .)
pkgrel=1
pkgdesc="The GNU Bourne Again shell"
url="https://www.gnu.org/software/bash/bash.html"
arch="all"
license="GPL-3.0+"
makedepends_build="byacc flex"
makedepends_host="ncurses-dev"
depends=""
install="$pkgname.post-upgrade $pkgname.pre-deinstall"
subpackages="$pkgname-dev $pkgname-doc $pkgname-lang
	$pkgname-binsh:binsh:noarch"
source="https://ftp.gnu.org/gnu/bash/bash-${_myver}.tar.gz
	bash-noinfo.patch
	bash44-sensible-defaults.patch
	bashrc
	"
# generate url's to patches. note: no forks allowed!
_i=1
_pad="00"
while [ $_i -le $_patchlevel ]; do
	[ $_i -ge 10 ] && _pad="0"
	[ $_i -ge 100 ] && _pad=
	source="$source https://ftp.gnu.org/gnu/bash/bash-$_myver-patches/bash$_patchbase-$_pad$_i"
	_i=$(( $_i + 1))
done

# secfixes:
#   4.4.12-r1:
#     - CVE-2016-0634

builddir="$srcdir"/$pkgname-$_myver

prepare() {
	# NOTE: This section is for applying the vendor patches, which are required to fix
	# security holes.  `default_prepare` does *not* apply vendor patches in the format
	# shipped with bash.  We also need to make sure vendor patches are applied before
	# our own.
	# If you disagree, please request an experimental rebuild with bash as /bin/sh,
	# before removing this section.
	for p in $source; do
		case $p in
		*/bash[0-9][0-9]-[0-9]*)
			msg "$p (vendor)"
			patch -p0 -i "$srcdir"/${p##*/} || return 1
			;;
		esac
	done

	default_prepare
	update_config_sub
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--bindir=/bin \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--with-curses \
		--without-bash-malloc
	# parallel build workarounds
	make y.tab.c && make builtins/libbuiltins.a && make
}

check() {
	make check
}

package() {
	make DESTDIR=${pkgdir} install
	install -D -m755 "$srcdir"/bashrc "$pkgdir"/etc/bash/bashrc
}

binsh() {
	pkgdesc="Use bash as /bin/sh"
	depends="bash"
	provides="/bin/sh"
	provider_priority=10
	mkdir -p "$subpkgdir"/bin
	ln -s /bin/bash "$subpkgdir"/bin/sh
}

sha512sums="73de3b425faaac55e45456b0f6f6d8077b5dfa7bb76e0d1894a19361b4a2b6bd4fbbe182117ddbfe9b07b4d898fba03537c261badc9533dd3c0da891764c7f29  bash-4.4.tar.gz
9d8845491d0fe335bdd8e9a2bd98bda54bfed2ae3c35b2196c6d5a38bdf96c4d97572ba7d6b19ab605ef4e8f001f64cf3312f87dedebb9e37a95ad2c44e33cdb  bash-noinfo.patch
388433e9ab25948747adfa7c2b98021799d5d396e8771d09b5b079054380af3f299f78abef144fe93908f6eff252658137c95ebba9418fe385f0cecbb5795f24  bash44-sensible-defaults.patch
de08a409023973352437a90101cec23eb3b282d0e7e2f5dc14f2da9f9ba4307d681a302ab86517761a1c5adbd79222e409d6f9d129c7f70af5a71f69a23b6b6a  bashrc
fa7a1b277eb3bad6ae7d2c7a2887cbf2c0eb75b7fee8ed03ec1e9d45879a2fb4b8c7cb16d6b029987493b01a461214bd9a24454a6837e7cfe180b1bc56f61caa  bash44-001
526f986057810f89080e283ff95b3a8fd24d37e4ad2f18c39f36d3a2d57956a6441d16220082157735e3c5ccf770d5016e761aa5f309129898e39277d576e6b5  bash44-002
e61db89bdd1a7ae15013fe258046a343c9ea41e5a1c6d2c810947500a617fce7536b8d51194e14bb42499fe0de6d70cc9b2c81da0afdcb5a2278459f4f76d748  bash44-003
7570cf15518f79230cfe91b3e58c795c16c7fb6ba6418d967355b36fb7982e7919a9eaaef9177fb605c7fb7d7efb8a8335e725c1bacffff69a098433f5adc9c7  bash44-004
7546a6c90c8e8508567dde713722291477ca87c1116905b46432514a4fc632840a855b84f102591914cd4c44d5bf2eb7400866e26366fc94525fb401ea844a8f  bash44-005
5edcd76cf97bfe289f71924ba279ff48a1167eb3cc36f811cbcc23732746f5c821d1d39d4b137b7d99d57809a4b7270a54f4a41176fcfde0708bf92ddc68b77f  bash44-006
386c019debee414697abc648d9a77894e842bb0b7a2a71709e8b3398582f25065e68963405fa22fb77439c6b431ee94a2ecbb16734c2436af3dfb4d1b5f06fcf  bash44-007
d9a8924f1c9263deab89153bb688a87f211913ebd72c8077e607db6fdddc7e5af05042dd22a9a2df593e518ea74b54ca79d20afc796e47d871827a2556e233d0  bash44-008
3b01c080cf4a54658679b36c282a69a9ac48b900b19ceb42dbaf084abd395d50e5ff14db90a7fdf0c9856dad150897dca561160686c931634765782447fc076e  bash44-009
54ff556b62fd88381e7a495db50957b016474973b3a566661c65b649a40960f2d3355221b3a71fb292128aad92a45d73d9816d63833bc416b4d15acdef391b98  bash44-010
6b5b068b74978fc691749ccff5e094c768047f702430e97114f5bf342f078696f7d7616d0642d4061b062e9112dfe00a1c2309c65de4147e0e98fb52c593d844  bash44-011
4661c4c132f2ea7c9a70368301041c482d5820d8389334a7e3ae44c36fc16c171b20db2f194b7663c84d6c3dcef81aa90f050a48e205218fc7bd3395d09c6a51  bash44-012
eac0a9abf59b65a59a0028d2f3c0a7dc8a0b3c04e2d2db642b69aa7c13a2dfa190f3c63f7d8a7c9400f01701e9ef84212ce668c4c44d0ccfd02cd1f8e723d831  bash44-013
11e16896aa66a1eafb12cdcea00515132789690e914c8894caefd8c80ed98c8e732428348ddbfb53495164ce4044596f5cdbc03e146dce364fc497f362a1859b  bash44-014
94d6fed30d4a376c29f8986d15f1b3fd65a04ee0f3d1844d010f3e51a2f9f875cd294a68fb6f0e1ffa481fb09f02055b21f2f298ebd9d88eb2f76d6c1f15de34  bash44-015
5acc704df3fe63b5b8055ba7bc14ae70cc23d15aefee8db6991e6c11cc8b0e10fcc67d516bc2d2fde84be26ed5c88dbf266fa164756218b60eccc2bfb4eed7d9  bash44-016
c1d50aee953427ba0b95e48c10d2324e7413f3354ff65b9c3c1dfd14eedec55e619fcd12353e7b99b6e280f510e04d1c971b309c1a4efb97d48ddb30d69f14ac  bash44-017
008ff44dbf916414d691c29cee29e7f636bbe79170463d76ef16ca63ecdc24a84ff4476078c28fb8788d9b1fb0572612a7e8cb30fceb55ad650f293db8361ad1  bash44-018
59984e221a7a6dbf72bf893b1b7c4a63fea34d6af1208a19f0e9e6cd59a09e4cf51890cb2d31c1502e2a2f644f584417bb59cf02c308d3250d2a98d41b63e893  bash44-019
e200fddd717fa33d2c56eb6713031d34891e5ebcd489a65a43ccfebf9728c1609b758ca3dffb1eed4abd3c62c6d7163ce88d8a1bb73b6d07bee99e0409365978  bash44-020
43a82d06a17bc30c2579a0944cb68f60bd9e3cddb9fff4a760fbf1f2f5104a99bb69c400cf63231b242c03a4684701455e603d96c9b588f2c69da02570042fec  bash44-021
385a0d1bbdff0dffec2a08021a84a5ac3695e44e1a90b0080b82737fc4a9ea924ee59b47fd5e288b69a540f4c976bf9da0db08ee2d20e170c868f802f75785fb  bash44-022
442efa78d365a728555ade77cc2f8501aed09f37ae10e1ac647d35299829b63caefbc5c30436d622bfef9300e9d929d7f4fafe85a59df15089881bc987fa12fd  bash44-023"