app=wpa-supplicant
sapp="$( echo $app | sed 's@-@_@')"
version=2.9
build=1sml
homepage="https://w1.fi/"
download="https://w1.fi/releases/wpa_supplicant-2.9.tar.gz"
desc="WPA/WPA2/IEEE 802.1X Supplicant"
requires="readline openssl libnl dbus"

build() {
  mkandenterbuilddir
  rm -rf $sapp-$version

  tar xf $srcdir/$sapp-$version.tar.?z*
  cd $sapp-$version
  fixbuilddirpermissions

  applypatch $srcdir/dbus.patch
  applypatch $srcdir/eloop.patch
  applypatch $srcdir/CVE-2019-16275.patch

  cd wpa_supplicant ; cp $srcdir/config .config

  make LIBDIR=/lib BINDIR=/bin all eapol_test
  make install LIBDIR=/lib BINDIR=/bin DESTDIR=$pkg

  mkdir -p $pkg/share/dbus-1/{system.d,system-services}
  cp dbus/fi.w1.wpa_supplicant1.service $pkg/share/dbus-1/system-services/
  cp dbus/dbus-wpa_supplicant.conf $pkg/share/dbus-1/system.d/

  mkdir -p $pkg/share/man/man{5,8}
  cp doc/docbook/wpa_supplicant.conf.5 $pkg/share/man/man5/
  cp doc/docbook/{wpa_cli.8,wpa_passphrase.8,wpa_supplicant.8} $pkg/share/man/man8/

  install -Dm 0600 $srcdir/wpa_supplicant.conf $pkg/etc/wpa_supplicant.conf.new
  install -m 0755 $srcdir/wpa_connect_action.sh $pkg/etc/wpa_connect_action.sh
  mkdir -p $pkg/var/run/wpa_supplicant

  preprunitservice wpa-supplicant down

  mkfinalpkg
}

sha512sums="
37a33f22cab9d27084fbef29856eaea0f692ff339c5b38bd32402dccf293cb849afd4a870cd3b5ca78179f0102f4011ce2f3444a53dc41dc75a5863b0a2226c8  wpa_supplicant-2.9.tar.gz
63710cfb0992f2c346a9807d8c97cbeaed032fa376a0e93a2e56f7742ce515e9c4dfadbdb1af03ba272281f639aab832f0178f67634c222a5d99e1d462aa9e38  CVE-2019-16275.patch
dac56bc505a51167042ebe548f0e81a20a5578f753af9bb7ec3335a542d799c6e8739681ef7c8f7747a9bc954f8aa6f1a147250eacba17fd7fff80c4e53638ed  dbus.patch
2be055dd1f7da5a3d8e79c2f2c0220ddd31df309452da18f290144d2112d6dbde0fc633bb2ad02c386a39d7785323acaf5f70e5969995a1e8303a094eb5fe232  eloop.patch
"
