by wsmith
7 deployments · 7 still active · last rev. 4 months ago

Compatible with: Debian 9
# define UDFs
#<UDF name="TOKEN" label="token to use for selfdestruct" >
#<UDF name="TIME_TO_LIVE" label="time before selfdestruct" >

# install requirements
apt-get update
apt-get install -y python-pip nginx
pip install linode-api

# set up nginx to serve the uploaded file
rm /etc/nginx/sites-enabled/default
cat > /etc/nginx/sites-enabled/linupload << EOF
server {
    listen 80;
    root /usr/share/nginx/html;

    location / {
        try_files $uri 404.html;

systemctl restart nginx

# set up a python script to self destruct
cat > /root/ << EOF
This script is run on startup, and knows enough to delete this linode after
a fixed amount of time.  All information necessary to do this is provided
on the linode creation in a StackScript.
from linode import LinodeClient, Linode
import time

token = '$TOKEN'
linode_id = '$LINODE_ID'
self_destruct_in = $TIME_TO_LIVE

client = LinodeClient(token)
linode = Linode(clinet, linode_id)

time.sleep(60 * self_destruct_in) # minutes, not seconds


python /root/ &