#!/bin/bash

################################################################################
#      This file is part of LibreELEC - https://libreelec.tv
#      Copyright (C) 2009-2016 Lukas Rusak (lrusak@libreelec.tv)
#
#  LibreELEC is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 2 of the License, or
#  (at your option) any later version.
#
#  LibreELEC is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with LibreELEC.  If not, see <http://www.gnu.org/licenses/>.
################################################################################

if [ -z "$PROJECT" -a -z "$ARCH" ]; then
  echo "Usage: PROJECT=<project> ARCH=<arch> $0"
  exit 0
fi

help() {
  echo "Usage: PROJECT=<project> ARCH=<arch> $0 [-a|--all]"
  echo "Options:"
  echo "  -a, --all: download all packages including addons"
}

case $1 in
  -a|--all)
  ALL_PACKAGES="true"
  ;;
  -h|--help)
  help
  exit 0
esac

for package in $(find packages/ -name package.mk); do
  if [ -n "$(echo $package | grep addons)" -a -z "$ALL_PACKAGES" ]; then
    continue
  fi
  ./scripts/get $(basename `dirname $package`)
done
