fetch-file-with-link 986 B

1234567891011121314151617181920
  1. #!/bin/sh
  2. while getopts ":c:l:o:h" option; do case "${option}" in
  3. h) printf "Usage (note that c,l and o flags are obligatory):\\n\
  4. -c [filename]\t path to cookie file (.txt file) \\n -l [filename]\t link \
  5. to the file on sharepoint (full url)\\n\
  6. -o [path]\t path to output directory\\n\\n\
  7. -h\t\t show this help message\\n" && exit 1 ;;
  8. c) cookiefile=${OPTARG};;
  9. l) linktofile=${OPTARG};;
  10. o) outputpath=${OPTARG};;
  11. *) printf "Invalid option: -%s\\n" "$OPTARG" && exit 1 ;;
  12. esac done
  13. [ ! -f "$cookiefile" ] && echo "Error: file '$cookiefile' not found" && exit 1
  14. [ ! -d "$outputpath" ] && echo "Error: path '$outputpath' not found" && exit 1
  15. [ -z "$linktofile" ] && echo "Error: no link provided" && exit 1
  16. # note: '--no-if-modified-since' was suggested by wget on running with out it
  17. wget -nH --cut-dirs=1 --quiet -P "$outputpath" --cookies=on --load-cookies "$cookiefile" --keep-session-cookies --no-check-certificate --no-if-modified-since -m "$linktofile"