#!/bin/sh set -e source $XDG_CONFIG_HOME/sabnzbd/config version="0.1" function usage () { echo "Usage : $0 [options] Options: --category Sets the category -h,--help Display this message -v,--version Display script version" } # Parse arguments declare -a args while [[ $# -gt 0 ]]; do opt="$1" case $opt in -h|--help) usage; exit 0 ;; -v|--version) echo "$0 -- Version $version"; exit 0 ;; --category) category=$2; shift 2 ;; -* ) echo -e "\n Option does not exist : $opt\n" usage; exit 1 ;; *) args+=("$opt"); shift ;; esac done if [[ -n $category ]]; then extra_data="-F cat=$category" fi for f in ${args[@]}; do curl -s -F apikey="$API_KEY" -F mode="addfile" -F name=@"$f" $extra_data $URL/sabnzbd/api &> /dev/null if [[ $? -eq 0 ]]; then echo "Uploaded '$f'" rm $f else echo "Failed to upload '$f'" fi done