#!/bin/sh

set -eu

command=$1
shift

# We assume the arduino-ide package has been installed before
# this package is installed!
opinsys_dir='/opt/arduino-ide/libraries/radiohead'

case "$command" in
    configure)
        upstream_dir=$1

        mkdir -p /opt/arduino-ide/libraries
        ln -fns "$upstream_dir" "$opinsys_dir"

        #Fix broken property file
       cat <<'EOF' > "${upstream_dir}/library.properties"
name=RadioHead Library
version=1.4.1
author=Mike McCauley <https://groups.google.com/forum/#!forum/radiohead-arduino>, SparkFun Electronics <techsupport@sparkfun.com>
maintainer=SparkFun Electronics <sparkfun.com>
sentence=This is the RadioHead Packet Radio library for embedded microprocessors.
paragraph=It provides a complete object-oriented library for sending and receiving packetized messages via a variety of common data radios and other transports on a range of embedded microprocessors.Drivers provide low level access to a range of different packet radios and other packetized message transports. Managers provide high level message sending and receiving facilities for a range of different requirements.
category=Communication
url=https://github.com/sparkfun/SparkFun_RadioHead_Arduino_Library
architectures=*
EOF
        ;;
    unconfigure)
        rm -f "$opinsys_dir"
        ;;
    unpack)
        upstream_pack=$1
        upstream_dir=$2
        tar -x -f "$upstream_pack" -C "$upstream_dir" --strip-components=1
        ;;
    *)
        ;;
esac
