# Maintainer: Quantopian Inc. <dev@quantopian.com>

# Quantopian, Inc. licenses this file to you under the Apache License, Version
# 2.0 (the "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
# 
#   http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

pkgname=penguindome-client
pkgver=1.0.0
pkgrel=0
pkgdesc="PenguinDome Mobile Device Management Client"
arch=('x86_64')
url="https://www.github.com/quantopian/PenguinDome"
depends=('python'
         'python-certifi'
         'python-chardet'
         'python-crypto'
         'python-daemon'
         'python-dateutil'
         'python-distro',
         'python-fasteners'
         'python-idna'
         'python-netifaces'
         'python-pexpect'
         'python-psutil'
         'python-yaml'
         'python-requests'
         # 'python-stopit' also needed, but doesn't exist
         'python-urllib3'
         'python-logbook-quantopian'
         'coreutils'
         'cryptsetup'
	 'dmidecode'
         'gnupg'
         'iptables'
         'lvm2'
	 'systemd'
         'tar'
         'wireless_tools'
         'util-linux')
source=("http://example.com/penguindome/v1/download_release")
sha256sums=(SKIP)
install=penguindome-client.install

package() {
  cd ${srcdir}

  real_install_dir="/opt/penguindome"
  install_dir="$pkgdir/$real_install_dir"

  install -d ${install_dir}
  install -d ${install_dir}/client/commands
  cp -r . ${install_dir}

  chmod -R 700 "$install_dir/client/keyring"

  site=$(python -c "import site;print(site.getsitepackages()[0])")

  for dir in ${site}; do
    install -d "$pkgdir/$dir"
    echo ${real_install_dir} > "$pkgdir/$dir/penguindome.pth"
  done

  install -d ${install_dir}/bin
  for file in client/*.py; do
    tail=${file##*/}
    if [ $tail = "initialize.py" ]; then
      continue
    fi
    chmod 754 $install_dir/$file
    ln -sf ../$file "$install_dir/bin/${tail%.py}"
  done

  install -Dm644 client/penguindome-client.service "$pkgdir/etc/systemd/system/penguindome-client.service"
  install -Dm644 client/penguindome-client.timer "$pkgdir/etc/systemd/system/penguindome-client.timer"
}
