https://github.com/mikelindner/bill.shorten
After talking with a friend about building a secure site to shorten links I came up with this thing I called “Bill Shorten”
It’s pretty simple if you use AWS command line, and it’s as secure as your AWS account, so all the best there 😅.
The basic parts, other than the script and associated files, is an S3 static hosting bucket and a static list of “random” numbers, words or whatever you like for your final short link. This way no code is needed to generate short links, and more importantly to prevent double usage. In the event of double usage however, the new location simply overwrites the old.
The script pops the top value off that list and creates a sub-bucket with it’s own index page, a clone of all the other index pages in the bucket, with the redirect URL pointing to a different end location, your link you wanted to shorten.
#!/bin/bash
# get link and details
echo -n "Please enter URL: " && read urlink
echo -n "Enter Title: " && read destitle
# now get the list of available short links
aws s3 cp --quiet s3://mikes.link/randoms /tmp
# pop the top short link into linknumber
linknumber=$(head -1 /tmp/randoms)
sed '1d' /tmp/randoms > /tmp/randoms2
mv /tmp/randoms2 /tmp/randoms
# create index page
echo "
<!doctype html>
<html lang=\"en\">
<head>
<meta charset=\"utf-8\">
<title>$destitle</title>
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">
<link rel=\"stylesheet\" href=\"../mikes.link.css\">
<meta property="og:image" content="../star.png" />
<script type = \"text/javascript\">
window.location = \"$urlink\";
</script>
<head>
<body>
<img src=\"star.png\" alt=\"star\"/>
<br><br><br>
<p><a href=\"https://mikelindner.com.au\">by mikelindner.com.au</a></p>
</body>
</html>
" > /tmp/index.html
# upload index page
aws s3 cp --quiet /tmp/index.html s3://mikes.link/$linknumber/
# put the list of available links back up
aws s3 cp --quiet /tmp/randoms s3://mikes.link/
# clean up
rm /tmp/index.html
rm /tmp/randoms
echo "https://mikes.link/$linknumber"