# Maintainer: Sergej Pupykin <pupykin.s@gmail.com>
# Contributor:Techlive Zheng <techlivezheng at gmail dot com>

pkgname=phpvirtualbox
pkgver=7.2_1
_pkgver=${pkgver/_/-}
_pkgver=${_pkgver/rc/-rc}
pkgrel=1
pkgdesc="PHP/AJAX web interface for VirtualBox"
arch=(any)
url="https://github.com/phpvirtualbox/phpvirtualbox"
license=('GPL')
depends=('php')
backup=("etc/webapps/phpvirtualbox/config.php")
source=("https://github.com/phpvirtualbox/phpvirtualbox/archive/${_pkgver}.tar.gz")
sha256sums=('8025ed6b6af7ab4f32b0ac548fee94621469d5f5bc89d6a8a553a3989ada5ca9')

package() {
  cd "$srcdir"/${pkgname}-${_pkgver}

  mkdir -p "$pkgdir"/etc/webapps/phpvirtualbox
  install -D -m644 config.php-example "$pkgdir"/etc/webapps/phpvirtualbox/config.php

  # Apache configuration
  cat > "$pkgdir"/etc/webapps/phpvirtualbox/apache.example.conf <<EOF
  Alias /phpvirtualbox "/usr/share/webapps/phpvirtualbox"
  <Directory "/usr/share/webapps/phpvirtualbox">
    Options FollowSymlinks
    AllowOverride All
    Require all granted
  </Directory>
EOF

  find . -type f -exec install -D -m644 {,"$pkgdir"/usr/share/webapps/${pkgname}/}{} \;
  ln -s /etc/webapps/phpvirtualbox/config.php "$pkgdir"/usr/share/webapps/phpvirtualbox/config.php
}
