Last active
August 12, 2024 15:20
-
-
Save simonesestito/aa7bd9a498d135b1f9a16fa839b6d26d to your computer and use it in GitHub Desktop.
Simple script to send a file in LAN via HTTP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -- | |
set -euo pipefail | |
PORT=8000 | |
if [ "$#" -ne 1 ]; then | |
echo "Usage: $0 <file_to_send>" | |
exit 1 | |
fi | |
# Extract only the filename | |
file_to_send=$(basename "$1") | |
# Create a temporary directory | |
tmpdir=$(mktemp -d) | |
# Clean up the temporary directory on exit | |
trap 'rm -rf "$tmpdir"' EXIT | |
# Copy the files to the temporary directory | |
cp "$1" "$tmpdir" | |
# Show the QR with the URL | |
my_lan_ip=$(ip a | grep inet | grep wlan | grep -Eo 'inet [0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | cut -d' ' -f2) | |
echo "http://$my_lan_ip:$PORT/$file_to_send" | qrencode -o - -t UTF8 | |
# Make a Python server in that directory | |
python3 -m http.server -d "$tmpdir" -b "$my_lan_ip" $PORT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment