#!/usr/bin/env bash # Nautilus script for creating one or more shared links # Requires wl-clipboard and notify-send ssh_server="bryanroessler.com" ssh_files_path="/var/www/repos.bryanroessler.com/files" www_files_path="https://repos.bryanroessler.com/files" if [[ "$#" -lt 1 ]]; then echo "You must provide at least one argument" exit 1 fi hash wl-copy &>/dev/null || { echo "Please install wl-copy"; exit 1; } hash rsync &>/dev/null || { echo "Please install rsync"; exit 1; } if [[ -v NAUTILUS_SCRIPT_SELECTED_URIS ]]; then readarray -t files <<< "$NAUTILUS_SCRIPT_SELECTED_URIS" for f in "${files[@]}"; do f="${f#file://}" f="${f//\%20/ }" fixed_files+=("$f") done else fixed_files=("$@") fi links_array=() for f in "${fixed_files[@]}"; do [[ "$f" == "" ]] && continue fname="${f##*/}" random64=$(tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w 64 | head -n 1) nohup rsync -a "$f" "${ssh_server}:${ssh_files_path}/${random64}/" & links_array+=("$www_files_path/${random64}/${fname// /%20}") done if [[ "${#links_array[@]}" == 1 ]]; then printf '%s' "${links_array[@]}" | wl-copy else printf '%s\n' "${links_array[@]}" | wl-copy fi hash notify-send &>/dev/null && notify-send -t 3000 -i face-smile "share-link" "File(s) uploaded and link copied to clipboard" exit 0