#!/bin/bash
read -p "Enter a URL: " url
echo "Starting the IPFS daemon if not already running..."
ipfs stats bw 2>/dev/null 1>/dev/null || ipfs daemon 2>/dev/null 1>/dev/null & disown; sleep 5
urlsafe=$(echo "$url" | sed "s/:\|\/\|?\|=\|&\|(\|)\|,\|+\|'\|*\|%\|#/-/g") # what about ! and $ ?
echo "$url" > "$urlsafe.txt"
lynx -source "$url" > "$urlsafe.htm"
date +%s > "$urlsafe.htm_mtime"
ipfs add -rHQ . > "../$urlsafe.cid"; mv -n "../$urlsafe.cid" .
echo "Copied here:"
cat "$urlsafe.cid" | sed "s/^/ipfs:\/\//g"; ipfs dht provide $(cat "$urlsafe.cid")
