31 lines
941 B
Bash
Executable file
31 lines
941 B
Bash
Executable file
#!/usr/bin/env sh
|
|
|
|
# TODO: progress bar!
|
|
|
|
# TODO: progress bar!
|
|
|
|
HOST="ld"
|
|
|
|
f="${1}"
|
|
fname="${2:-$(basename "${f}")}"
|
|
subdir="${3:-uploads}"
|
|
internal_dir="/home/daniel/services/data/files/${subdir}"
|
|
url="https://lyte.dev/${subdir}/${fname}"
|
|
|
|
[ "${f}" = "" ] && echo "No file provided. Exiting." >&2 && exit 2
|
|
[ ! -f "${f}" ] && echo "File '$f' does not exist. Exiting." >&2 && exit 1
|
|
|
|
if [ "$(curl -s -o /dev/null -w "%{http_code}" "${url}")" -eq 200 ]; then
|
|
echo "ERROR: A file already exists at ${url}"
|
|
exit 3
|
|
fi
|
|
|
|
ssh ld mkdir -p "${internal_dir}"
|
|
rsync --progress --no-owner --no-group --no-perms --stats --ignore-existing "${f}" "${HOST}:${internal_dir}/${fname}" | tee "${HOME}/.upload.log"
|
|
code="$?"
|
|
ssh ld chmod a+r "${internal_dir}/${fname}"
|
|
echo "Uploaded to: ${url}"
|
|
|
|
if [ "$code" -ne 0 ]; then
|
|
printf "ERROR: The file failed to upload - perhaps rsync failed for some reason?\n See \"%s/.upload.log\" for details\n" "$HOME"
|
|
fi
|