Skip to content

Instantly share code, notes, and snippets.

@fstanis
Created June 29, 2025 10:13
Show Gist options
  • Save fstanis/f7569b3efecb7de9f48d1314bae51867 to your computer and use it in GitHub Desktop.
Save fstanis/f7569b3efecb7de9f48d1314bae51867 to your computer and use it in GitHub Desktop.
A script to periodically check for new files in taildrop and move them.
#!/bin/bash
# A script to periodically check for new files in taildrop and move them.
#
# Usage:
# ./tailscale_getfiles.sh start
# ./tailscale_getfiles.sh stop
readonly TAILSCALE_DIR="$HOME/tailscale"
readonly STATE_DIR="$TAILSCALE_DIR/state"
readonly OUT_DIR="$HOME/tailscale-files"
readonly SOCKET="$TAILSCALE_DIR/tailscaled.sock"
readonly TAILSCALE_EXEC="$TAILSCALE_DIR/tailscale"
readonly PIDFILE="$TAILSCALE_DIR/tailscale-getfiles.pid"
readonly SCRIPT="$(realpath "$0")"
mkdir -p "$OUT_DIR"
case "$1" in
start)
start-stop-daemon \
--start \
--background \
--pidfile "$PIDFILE" \
--make-pidfile \
--exec "$SCRIPT"
;;
stop)
start-stop-daemon \
--stop \
--pidfile "$PIDFILE"
;;
*)
while true; do
trap "" SIGTERM
if find "$STATE_DIR/files" -type f | read; then
"$TAILSCALE_EXEC" --socket "$SOCKET" file get "$OUT_DIR"
fi
trap - SIGTERM
sleep 5
done
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment