# Template file for 'debootstrap'
pkgname=debootstrap
version=1.0.123
# Liberation: _pureos* variables added for pureos distfiles
_pureospkgver=1.0.108
_pureospkgrel=pureos2
revision=2
# Liberation: We're building from source. So changed fetch into this.
build_style=gnu-makefile
depends="binutils gnupg gzip tar wget xz"
# Liberation: Changed according to Parabola to indicate inclusion of Free distros
# and ommision of Debian
short_desc="Bootstrap a basic gNewSense and Trisquel system, without Debian support"
maintainer="Leah Neukirchen <leah@vuxu.org>"
license="MIT"
homepage="http://packages.qa.debian.org/d/debootstrap.html"
# Liberation: Changed files to build from source
distfiles="https://github.com/felixonmars/${pkgname}/archive/${version}.tar.gz
 https://repo.puri.sm/pureos/pool/main/d/${pkgname}/${pkgname}_${_pureospkgver}${_pureospkgrel}.tar.gz"
checksum="ccc6cf2eb5e5481d88e1cebd5430a86ffc686be019f7f4dc66cfbb717b107d56
 c0d8c1d7bf7f612c654c475c7e997711fc0a925ddebc0b8c063d4386a25a9cd5"

case "$XBPS_TARGET_MACHINE" in
	armv5*l*) _debarch=armel;;
	arm*l*) _debarch=armhf;;
	aarch64*) _debarch=arm64;;
	x86_64*) _debarch=amd64;;
	i686*) _debarch=i386;;
	ppc64le*) _debarch=ppc64el;;
	ppc64*) _debarch=ppc64;;
	ppc*) _debarch=powerpc;;
	*) broken="please add your architecture";;
esac

# Liberation
# Some commands has been taken and modified from:
# https://git.parabola.nu/abslibre.git/tree/libre/debootstrap/PKGBUILD
post_patch() {
	# Invalid argument fix
	sed -i 's/chown/#chown/g' Makefile

	# Below is mostly from Parabola project with minor changes...

	sed -i 's/sbin/bin/g' Makefile

	# gNewSense/Trisquel defaults
	sed -i 's|export PATH|export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"|' debootstrap

	# arch-detect.patch from Parabola was omitted

	# Remove Debian files
	rm -v debootstrap.8

	# Add rebranded man
	install -m644 ${FILESDIR}/debootstrap.8 .

	# Remove (non-FSDG compliant) distributions's scripts
	for SCRIPT in scripts/* ; do
		case $SCRIPT in
		scripts/debian-common)
			;;
		*)
			rm -v $SCRIPT
			;;
		esac
	done

	# Add gNewSense script
	install -m644 ${FILESDIR}/gnewsense scripts

	# Add PureOS script
	install -m644 ${XBPS_BUILDDIR}/debootstrap/scripts/amber scripts/pureos

	# Add Trisquel script
	install -m644 ${FILESDIR}/trisquel scripts

	# Enter to scripts dir
	cd scripts

	# Create gNewSense symlinks
	ln -s gnewsense ucclia
	ln -s gnewsense parkes

	# Create PureOS symlinks
	ln -s pureos amber
	ln -s pureos green
	ln -s pureos landing
	ln -s pureos purple

	# Create Trisquel symlinks
	ln -s trisquel awen
	ln -s trisquel belenos
	ln -s trisquel brigantia
	ln -s trisquel dagda
	ln -s trisquel dwyn
	ln -s trisquel etiona
	ln -s trisquel flidas
	ln -s trisquel robur
	ln -s trisquel slaine
	ln -s trisquel taranis
	ln -s trisquel toutatis
}

# Liberation: Removed do_install

# Liberation
# Some commands has been taken and modified from:
# https://git.parabola.nu/abslibre.git/tree/libre/debootstrap/PKGBUILD
post_install() {
	install -Dm644 ${FILESDIR}/debootstrap.8 "${DESTDIR}"/usr/share/man/man8/debootstrap.8

	# Some commands from previous do_install...
	vlicense debian/copyright LICENSE
	echo ${_debarch} >${DESTDIR}/usr/share/debootstrap/arch
}
