Skip to content

Instantly share code, notes, and snippets.

@fmagin
Last active August 29, 2015 14:10
Show Gist options
  • Save fmagin/94c06189753cc6e1a1fc to your computer and use it in GitHub Desktop.
Save fmagin/94c06189753cc6e1a1fc to your computer and use it in GitHub Desktop.
You give the script the four letter identifier after sprunge.us/ and an optional filename( if noone is given it defaults to the letter identifier), and it downloads it. Utilizes AES decryption with static key for imrpoved privacy for personal files
#!/bin/bash
decrypt="openssl enc -aes-256-cbc -base64 -d -k $key"
url="sprunge.us/$1"
file="$(curl $url | $decrypt)"
if [ "${file:0:9}" == "Filename:" ]; then
echo Filename found
firstline=$(echo "$file" | head -1)
filename=${firstline:9}
content=$(echo "$file" | tail -n +2)
echo "$content" > $filename
echo "Saved to $filename"
else
if [ -z $2 ]; then
filename=$1
else
filename=$2
fi
echo $file > $filename
echo "Saved to $filename"
fi
@DanielFGray
Copy link

more quotes, less subprocesses

untested, but should work

#!/usr/bin/env bash

key='your key here'
decrypt="openssl enc -aes-256-cbc -base64 -d -k $key"
url="sprunge.us/$1"

mapfile file < <(curl -s "$url" | "$decrypt")

firstline="${file[0]}"
if [[ "${firstline:0:9}" == "Filename:" ]]; then
    echo 'Filename found'
    filename="${firstline:9}"
    printf '%s\n' "${file[@]:1}" > "$filename"
    echo "Saved to $filename"
else
    if [[ -z "$2" ]]; then
        filename="$1"
    else
        filename="$2"
    fi
    printf '%s\n' "${file[@]}" > "$filename"
    echo "Saved to $filename"
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment