#!/bin/bash

######################################################################
#
# Test Bash script for creating sample station csv file
#
# Author: Bernard Miville
#
# Created: 23 February 2017
#
######################################################################

# Fonts for help

NORM=$(tput sgr0)
BOLD=$(tput bold)
REV=$(tput smso)
RED=$(tput setaf 1)

# Functions

usage(){
# Help
	echo "${BOLD}${RED}Usage:${NORM} $0 [<options>]"
	echo
	echo "${BOLD}${RED}Options:"
	echo "${NORM}-h,--help              Show this message, then exit."
    echo "${NORM}-s,--station filename  Produce a station list and save to a csv file (filename, including path as needed), then exit."
    exit 0
}

csv(){
# Create a list of stations
    echo "INFO: "$(date  +%Y"-"%m"-"%d" "%H":"%M":"%S)" - Station csv file creation started: $1"
	echo 'Name,ID,Type,Lat,Lon,Country' > $1
    echo '"Afiamalu AWS","76021","Type A",-13.9084,-171.7820,"WS"' >> $1
    echo '"Alafua AWS","76216","Type B",-13.8593,-171.7935,"WS"' >> $1
    echo '"Nafanua AWS","76225","Type A",-13.8580,-171.7622,"WS"' >> $1
    echo '"Nuu AWS","76215","Type B",-13.8345,-171.8345,"WS"' >> $1
    echo "INFO: "$(date  +%Y"-"%m"-"%d" "%H":"%M":"%S)" - Station csv file creation completed: $1"
    exit 0
}

# Check options

if ! OPTS=$(getopt -o hc: -l help,station: -- "$@"); then
    exit 1
fi

eval set -- "$OPTS"

while true; do
    case $1 in
        -h|--help) usage; shift ;;
        -c|--csv) csv $2; shift 2 ;;
        *)
            echo "Unknown option: $1"
            exit 1
        ;;
    esac
done

# Run main code below here

# Nothing
