vodkas

Simple file sharing server
Log | Files | Refs

vv.sh (1398B)


      1 #!/bin/bash
      2 
      3 HOST=https://vetle.vodka
      4 CMD="$1"
      5 
      6 function help () {
      7     echo "$0 commands:"
      8     echo "  a: share a file as admin (password prompt)"
      9     echo "    vv a <filename> [shotKey] [numdls]"
     10     echo "  s: share a file"
     11     echo "    vv s <filename> [shotKey] [numdls]"
     12     echo "  f: fetch a file"
     13     echo "    vv f <shotKey>"
     14 }
     15 
     16 function argrequired () {
     17     if [ -z $2 ]; then
     18         echo "Argument '$1' is missing"
     19         exit 1
     20     fi
     21 }
     22 
     23 case "$CMD" in 
     24     # Admin - Prompt for admin password, then run share
     25     a)
     26         printf "Admin key: "
     27         read -s adminKey
     28         echo
     29         ;&
     30     s)
     31         argrequired filename $2
     32         shotKey=$3
     33         numdls=$4
     34         curlArgs="-H 'Content-Type: multipart/form-data' -F file=@$2"
     35         if [ -n "$numdls" ]; then
     36             curlArgs="$curlArgs -F 'numdls=$numdls'"
     37         fi
     38         if [ -n "$adminKey" ]; then
     39             curlArgs="$curlArgs -H 'Admin-Key: $adminKey'"
     40         fi
     41         echo curl "$curlArgs" $HOST/$shotKey | bash
     42         ;;
     43     # Fetch - Get data
     44     f)
     45         argrequired shotKey $2
     46         curl $HOST/$2
     47         ;;
     48     # Link, pretty much a simple URL shortener
     49     l)
     50         argrequired shotKey $2
     51         argrequired link $3
     52         contents="<html><meta http-equiv='refresh' content='0; url=$3'></html>"
     53         curl --form-string text="$contents" $HOST/$2
     54         ;;
     55     *)
     56         help
     57 esac