Last active 1627586600

A script to launch a DO droplet with a script to download a file via http, transcode it using video2hls, upload the results to b2:ads-share/hls, then delete itself

Revision bd1176313a5de8f58470563570c017c89661f55d

hlstranscode.sh Raw
1#!/bin/bash
2# hlstranscode "$URL"
3
4cat >/tmp/cloud.conf <<EOFF
5#!/bin/bash
6apt-get update -qq
7apt-get install ffmpeg -y -qq
8curl https://rclone.org/install.sh | bash 2>/dev/null >/dev/null
9
10export ID=\$(curl http://169.254.169.254/metadata/v1/id 2>/dev/null)
11export URL=\$(curl http://169.254.169.254/metadata/v1/hostname 2>/dev/null | sed 's/-/=/g' | base32 -d)
12
13mkdir -p /root/.config/rclone /root/inp
14cat > /root/.config/rclone/rclone.conf <<EOF
15$(cat ~/.config/rclone/rclone.conf)
16EOF
17
18cd /root/inp
19curl "\$URL" -O 2>/dev/null
20export SUM=\$(sha1sum * | awk '{print \$1}')
21cd /root
22
23git clone https://github.com/vincentbernat/video2hls /root/video2hls 2>/dev/null
24/root/video2hls/video2hls --output /root/out/\$SUM /root/inp/*
25ffmpeg -i /root/inp/* /root/out/\$SUM/index.vtt 2>/dev/null
26rclone copy /root/out/ b2:ads-share/hls/ --transfers=40
27
28echo \$SUM
29echo "ALLDONE (ctrl-c)"
30curl -X DELETE -H "Authorization: Bearer $(grep access-token "/Users/alyssa/Library/Application Support/doctl/config.yaml" | awk '{print $2}')" https://api.digitalocean.com/v2/droplets/\$ID
31EOFF
32cat /tmp/cloud.conf
33read IP <<< $(set -x; doctl compute droplet create $(base32 -w0 <<<"$1" | sed 's/=/-/g') --region sgp1 --size s-16vcpu-64gb --image ubuntu-20-04-x64 --ssh-keys 28633873,28633866,29533274,29451733,29347920,30747235 --user-data-file /tmp/cloud.conf --wait --no-header --format PublicIPv4)
34rm /tmp/cloud.conf
35until (ssh -o StrictHostKeyChecking=no root@$IP tail -f /var/log/cloud-init-output.log); do
36 sleep 1
37done