Found an old script that can make video intro with arbitrary text(?)
[einar-bin] / imgurgame.bash
1 #!/bin/bash
2 # Because why not? curl must be installed
3
4 readonly BROWSER="google-chrome"
5
6 # Create a random imgur url that may or may not be valid
7 imgururl() {
8 # 1/3 chance for length of 5, 6 or 7 length string
9 STRLN=$((5 + RANDOM % 3))
10 local ID
11 # don't nag about useless cat, this is more readable
12 # shellcheck disable=2002
13 ID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w ${STRLN} | head -n 1)
14 echo "http://i.imgur.com/${ID}.jpg"
15 }
16
17 # Test if we found a valid URL
18 testimgur() {
19 local URL=${1}
20 local RESULT
21 RESULT=$(curl -s -o /dev/null -I -w "%{http_code}" "${URL}")
22 if [[ ${RESULT} == "200" ]]; then
23 echo true
24 else
25 echo false
26 fi
27 }
28
29 main() {
30 local FAIL=0
31 while true; do
32 local URL
33 URL=$(imgururl)
34 if [[ $(testimgur "${URL}") == "true" ]]; then
35 echo "Found ${URL} after ${FAIL} failed tries"
36 ${BROWSER} "${URL}" > /dev/null 2>&1
37 local FAIL=0
38 else
39 ((FAIL++))
40 fi
41 done
42 }
43
44 main