Skip to content

Instantly share code, notes, and snippets.

@TheSkorm
Last active October 7, 2021 13:55
Show Gist options
  • Save TheSkorm/cb9171e92d0db850363f to your computer and use it in GitHub Desktop.
Save TheSkorm/cb9171e92d0db850363f to your computer and use it in GitHub Desktop.
ec2 download torrent
#!/bin/bash
#don't actually use this - it's silly
#sns needs to be setup
#ec2 role must have access to read tags, write to s3 and publish to sns
#start isntance with
#aws ec2 run-instances --image-id ami-fd9cecc7 --count 1 --instance-type t2.micro --key-name deb --security-group-ids sg-c948cbac --subnet-id subnet-ff9b3a9a --user-data "`base64 ~/download.sh`" --instance-initiated-shutdown-behavior terminate --associate-public-ip-address --iam-profile pirate
#set the download url with once you have the instanceid
#aws ec2 create-tags --resources i-54388388 --tags Key=URL,Value="http://cdimage.debian.org/debian-cd/8.0.0/amd64/bt-cd/debian-8.0.0-amd64-netinst.iso.torrent"
export BUCKET=mwheeler-pirate
export TOPIC="arn:aws:sns:ap-southeast-2:082208999166:Pirate"
INSTANCE_ID=`wget -qO- http://169.254.169.254/latest/meta-data/instance-id`
REGION=ap-southeast-2
sleep 30
aws ec2 describe-tags --region $REGION --filter "Name=resource-id,Values=$INSTANCE_ID" --output=text | sed -r 's/TAGS\t(.*)\t.*\t.*\t(.*)/\1="\2"/' > /etc/ec2-tags
. /etc/ec2-tags
mkdir /root/download
yum -y install --enablerepo=epel transmission-daemon transmission
sysctl net.core.rmem_max=4194304
sysctl net.core.wmem_max=1048576
echo "#!/bin/bash
export BUCKET=$BUCKET
export TOPIC=$TOPIC
export REGION=$REGION
killall -9 transmission-cli
export FILE=\"\`ls /root/download/\`\"
cd /root/download/
zip -r \"\$FILE.zip\" .
aws s3 cp \"\$FILE.zip\" s3://$BUCKET/
export FILELINK=\`/root/sign.py -b $BUCKET -k \"\$FILE.zip\" -s 259200\`
aws configure set region \$REGION
aws sns publish --topic-arn \$TOPIC --message \"Download ready at \$FILELINK\"
shutdown -h now
" > /root/done.sh
chmod +x /root/done.sh
echo "#!/usr/bin/python
import boto
import argparse
parser = argparse.ArgumentParser(description='Generate an S3 signed URL')
parser.add_argument('-b', '--bucket', help='bucket name')
parser.add_argument('-k', '--key', help='prefix/key')
parser.add_argument('-s', '--seconds', type=int, help='time in seconds until the URL will expire')
args = parser.parse_args()
s3 = boto.connect_s3()
bucket = s3.get_bucket(args.bucket)
key = bucket.get_key(args.key)
if bucket.get_key(args.key):
print key.generate_url(args.seconds)
else:
print 's3://' + args.bucket + '/' + args.key + ' does not exist'
" > /root/sign.py
chmod +x /root/sign.py
mkdir -p /root/.config/transmission/
echo "{
\"peer-limit-global\": 1000,
\"peer-limit-per-torrent\": 1000,
\"ratio-limit\": 0,
\"ratio-limit-enabled\": true,
\"peer-port\": 2108
}" > /root/.config/transmission/settings.json
echo "shutdown -h now" | at now + 12 hours
transmission-cli -f /root/done.sh -w /root/download/ -u 0.1 -ep "$URL"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment