share-link 1.3 KB

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