From: Samir Benmendil Date: Sun, 24 Nov 2019 14:46:46 +0000 (+0000) Subject: bin: finally add addnzb script X-Git-Url: https://git.rmz.io/dotfiles.git/commitdiff_plain/56f75bf983cc8b70ccde224e50241c45a84a63b8 bin: finally add addnzb script --- diff --git a/bin/addnzb b/bin/addnzb new file mode 100755 index 0000000..fdd5ca7 --- /dev/null +++ b/bin/addnzb @@ -0,0 +1,47 @@ +#!/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 + rm $f + else + echo "Failed to upload '$f'" + fi +done