# Maintainer (arch): Felix Yan <felixonmars@archlinux.org>
# Maintainer: 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>

pkgname=debootstrap
pkgver=1.0.134
pkgrel=1
pkgrel+=.parabola2
pkgdesc="Bootstrap a basic Trisquel system, without Debian support"
arch=(any)
license=(GPL)
url="https://tracker.debian.org/pkg/debootstrap"
depends=(wget binutils)
makedepends=(git)
source=("git+https://salsa.debian.org/installer-team/debootstrap.git#tag=${pkgver}"
        arch-detect.patch
        debootstrap.8)
optdepends=('gnupg: check release signatures'
            'pureos-archive-keyring: check PureOS release signatures'
            'trisquel-keyring: check Trisquel release signatures')
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 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
}

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

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