# Maintainer (arch): Felix Yan <felixonmars@archlinux.org>
# Contributor: Omar Vega Ramos <ovruni@gnu.org.pe>
# Contributor: Andreas Grapentin <andreas@grapentin.org>
# Contributor: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
# Contributor: André Silva <emulatorman@hyperbola.info>
# Maintainer: Parabola Hackers <dev@lists.parabola.nu>

pkgname=debootstrap
pkgver=1.0.143
pkgrel=3
pkgrel+=.parabola1
pkgdesc="Bootstrap basic PureOS or Trisquel systems, without nonfree distros support"
arch=(any)
license=(GPL)
url="https://tracker.debian.org/pkg/debootstrap"

# The debootstrap manual uses http:// addressese, probably to enable
# various transparent proxies to cache packages and make the process
# more efficient, so it is a good idea to keep that.
#
# However if gnupg, pureos-archive-keyring and trisquel-keyring are
# not installed, no signatures will be checked, and probably not
# everybody knows that, even if it is shown after the installation.
#
# If signatures aren't checked it gives the ability to execute
# arbitrary code to anybody who can manage to do a man in the middle
# attack.
#
# So for security reasons we require gnupg, pureos-archive-keyring and
# trisquel-keyring instead of having them as optional like in
# distributions based on Debian like PureOS and Trisquel. The Guix
# debootstrap package also enforces signature verifications.
#
depends=(
    'binutils'
    'dpkg'
    'gnupg'
    'pureos-archive-keyring'
    'trisquel-keyring'
    # Required by the PureOS and Trisquel scripts.
    'tzdata'
    'wget'
    # Required by at least Trisquel 11 (aramo).
    'zstd')
makedepends=(git)
source=("git+https://salsa.debian.org/installer-team/debootstrap.git#tag=${pkgver}"
        arch-detect.patch
        debootstrap.8)
sha512sums=('SKIP'
            'SKIP'
            'SKIP')
prepare() {
  cd debootstrap

  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

  # Detect Architecture
  patch -p1 -i ../arch-detect.patch

  # Remove Debian files
  rm -v debootstrap.8

  # Add rebranded man
  install -m644 ../debootstrap.8 .

  # Remove (non-FSDG compliant) distributions's scripts
  for SCRIPT in scripts/* ; do
    case $SCRIPT in
    scripts/amber)         # PureOS 9.0
      ;;
    scripts/debian-common) # Required by debuerreotype
      ;;
    scripts/robur)         # Trisquel 2.0
      ;;
    *)
      rm -v $SCRIPT
      ;;
    esac
  done

  # Enter to scripts dir
  cd scripts

  # Create PureOS symlinks
  ln -s amber byzantium   # PureOS 10.0
  ln -s amber crimson     # PureOS 11.0
  ln -s amber dawn        # PureOS version after Crimson
  ln -s amber landing     # Based on Debian testing

  # Create Trisquel symlinks
  ln -s robur dwyn      # Trisquel 3.0
  ln -s robur awen      # Trisquel 3.5
  ln -s robur taranis   # Trisquel 4.0
  ln -s robur slaine    # Trisquel 4.5
  ln -s robur dagda     # Trisquel 5.0
  ln -s robur brigantia # Trisquel 5.5
  ln -s robur toutatis  # Trisquel 6.0
  ln -s robur belenos   # Trisquel 7.0
  ln -s robur flidas    # Trisquel 8.0
  ln -s robur etiona    # Trisquel 9.0
  ln -s robur nabia     # Trisquel 10.0
  ln -s robur aramo     # Trisquel 11.0
  ln -s robur ecne      # Trisquel 12.0
}

package() {
  cd debootstrap
  make DESTDIR="$pkgdir" install

  install -Dm644 debootstrap.8 "$pkgdir"/usr/share/man/man8/debootstrap.8
}
