share-link 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env bash
  2. # Nautilus script for creating one or more shared links
  3. # Requires wl-clipboard and notify-send
  4. ssh_server="bryanroessler.com"
  5. ssh_files_path="/var/www/repos.bryanroessler.com/files"
  6. www_files_path="https://repos.bryanroessler.com/files"
  7. if [[ "$#" -lt 1 ]]; then
  8. echo "You must provide at least one argument"
  9. exit 1
  10. fi
  11. hash wl-copy &>/dev/null || echo "Please install wl-copy (usually in the wl-clipboard package)"
  12. if [[ -v NAUTILUS_SCRIPT_SELECTED_URIS ]]; then
  13. readarray -t files <<< "$NAUTILUS_SCRIPT_SELECTED_URIS"
  14. files=("${files[@]#file://}")
  15. files=("${files[@]//\%20/ }")
  16. else
  17. files=("$@")
  18. fi
  19. for file in "${files[@]}"; do
  20. [[ "$file" == "" ]] && continue
  21. echo here
  22. fname="${file##*/}"
  23. random64=$(tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w 64 | head -n 1)
  24. echo "rsync -a ${file} ${ssh_server}:${ssh_files_path}/${random64}/"
  25. nohup rsync -a "${file}" "${ssh_server}:${ssh_files_path}/${random64}/" &
  26. links_array+=("$www_files_path/${random64}/${fname// /%20}")
  27. done
  28. if [[ "${#links_array[@]}" == 1 ]]; then
  29. printf '%s' "${links_array[@]}" | wl-copy
  30. else
  31. printf '%s\n' "${links_array[@]}" | wl-copy
  32. fi
  33. hash notify-send &>/dev/null &&
  34. notify-send -t 3000 -i face-smile "share-link" "File(s) uploaded and link copied to clipboard"
  35. exit 0