dotfiles

personal configuration files and scripts
git clone https://tongong.net/git/dotfiles.git
Log | Files | Refs | README

share (2387B)


      1 #!/usr/bin/env sh
      2 
      3 # upload files to online storage and get a link to share with your friends
      4 
      5 # services
      6 # -> transfer.sh     10000 MB
      7 # -  file.io           100 MB
      8 # -  0x0.st            530 MB
      9 # -  oshi.at          5000 MB  (some server downtimes)
     10 # -  filepush.co        32 MB
     11 # -  keep.sh           500 MB
     12 # -  transfersh.com  10000 MB
     13 
     14 function cryptcmd {
     15     if [ -n "$pss" ]; then
     16         gpg --symmetric --cipher-algo AES256 --passphrase "$pss" --batch -o- | curlercmdoshi
     17     else
     18         curlercmdoshi
     19     fi
     20 }
     21 
     22 
     23 function getpasswd {
     24     pswd=$(echo -e "generate password\nenter password\nno password" | fzf --layout=reverse --height=10%)
     25     case "$pswd" in
     26         "generate password")
     27             pss=$(head /dev/urandom | tr -dc a-z0-9 | head -c 30)
     28             echo "Password is: $pss"
     29             file_name="$file_name.gpg"
     30             ;;
     31         "enter password")
     32             echo -n "Enter password: "
     33             read pss
     34             file_name="$file_name.gpg"
     35             ;;
     36         "no password")
     37             ;;
     38         *)
     39             exit 1;
     40             ;;
     41     esac
     42 }
     43 
     44 
     45 function curlercmdoshi {
     46     links=$(curl -v --upload-file "-" "http://oshi.at/$file_name/14400")
     47     echo "$links" | awk ' /CDN/ {print $1}'
     48     echo "$links" | awk ' /Admin/ {print "admin: " $1}'
     49     [ -n "$pss" ] && pss="  password: $pss"
     50     (echo "$links" | awk ' /Admin/ {printf "%s", $1}'; echo "  $file_name$pss") >> ~/.share-history
     51 }
     52 
     53 function curlercmdtransfer {
     54     links=$(curl -D - --upload-file - "http://transfer.sh/$file_name")
     55     echo "$links" | tail -n1
     56     echo "$links" | awk ' /X-Url-Delete/ {print "delete: " $2}'
     57     [ -n "$pss" ] && pss="  password: $pss"
     58     (echo "$links" | awk ' /X-Url-Delete/ {printf "%s", $2}'; echo "  $file_name$pss") \
     59         | sed -e 's///g' >> ~/.share-history
     60 }
     61 
     62 
     63 # access admin/delete panel for older files
     64 if [ "$1" = history ]; then
     65     "$EDITOR" ~/.share-history
     66 else
     67     if [ $# -eq 0 ]; then
     68         echo -e "No arguments specified.\nUsage:\n  share <file|directory>\n  ... | share <file_name>">&2
     69         exit 1
     70     fi
     71     if tty -s; then
     72         file="$1"
     73         file_name=$(basename "$file")
     74         if [ ! -e "$file" ]; then
     75             echo "$file: No such file or directory">&2
     76             exit 1
     77         fi
     78         getpasswd
     79         cat "$file" | cryptcmd
     80     else file_name=$1
     81         getpasswd
     82         cryptcmd
     83     fi
     84 fi