Skip to content

Instantly share code, notes, and snippets.

@bradfeehan
Created June 11, 2014 05:24
Show Gist options
  • Save bradfeehan/2f0ccc3840d578c61b89 to your computer and use it in GitHub Desktop.
Save bradfeehan/2f0ccc3840d578c61b89 to your computer and use it in GitHub Desktop.
getflix
#!/bin/bash
#
# A command-line utility to enable/disable Getflix
#
# Usage: getflix on
# getflix off
ARGC=$#
# The resolver configuration file for Getflix
RESOLVER_FILE="/etc/resolver/getflix.com.au"
# Explains how to use the command
function usage() {
echo "Control Getflix from the command-line"
echo
echo "Usage:"
echo "getflix on Enable Getflix DNS for appropriate domains"
echo "getflix off Disable Getflix DNS resolution"
echo "getflix [check] Checks the current status of Getflix DNS"
echo "getflix [status] Shows the current status of Getflix DNS"
echo "getflix --help This help message"
}
# Echoes a whitespace-delimited list of domain names to use
function list_domains() {
cat <<DOMAINS
getflix.com.au
netflix.com
nflximg.com
hulu.com
a248.e.akamai.net
akamaihd.net
uplynk.com
edgefcs.net
theplatform.com
brightcove.com
mgo.com
vudu.com
vvond.net
amazon.com
flixster.com
cinemanow.com
roxionow.com
hbogo.com
hbogo.com
pdl.uhybrid.lv3.hbogo.com.c.footprint.net
pbs.org
wwe.com
sho.com
showtimeanytime.com
shovod.edgesuite.net
dishworld.com
movenetworks.com
movetv.com
shrbt.com
go.com
cbs.com
tbs.com
southparkstudios.com
espn.com
crackle.com
mtv.com
mtvnservices.com
vh1.com
fxnetworks.com
nbcolympics.com
golfchannel.com
nbcsports.com
unicornmedia.com
rhapsody.com
pandora.com
songza.com
slacker.com
bbc.co.uk
bbcfmhds.vo.llnwd.net
itv.com
channel4.com
channel5.com
five.tv
fcod.llnwd.net
skyanywhere.com
sky.com
nowtv.com
skychnl.net
eurosportplayer.co.uk
eurosport.com
livestream.com
beinsports.net
beinsportsplay.tv
fplive.net
performgroup.com
starsports.com
roku.com
wdtvlive.com
boxee.tv
sony.tv
sonyentertainmentnetwork.com
maxmind.com
DOMAINS
}
# Retrieves the configuration file to use
function configuration() {
list_domains | while read domain; do
echo "domain $domain"
echo "nameserver 54.252.183.4"
done
}
# Shows the current status of Getflix
#
# Echoes "on" if enabled, or "off" if disabled.
function status() {
if [[ -f "$RESOLVER_FILE" ]]; then
echo "on"
else
echo "off"
fi
}
# Shows the current status of Getflix, as reported by Getflix
#
# Echoes "on" if enabled, or "off" if disabled.
function real_status() {
local check="https://check.getflix.com.au/?format=json"
local result="$(sleep 1; curl "$check" 2> /dev/null)"
if [[ "$result" = '{"dns":true}' ]]; then
echo "on"
else
echo "off"
fi
}
# Ensures the status is "on", printing a message if not
function assert_enabled() {
if [[ "$(real_status)" != "on" ]]; then
echo "Getflix DNS is still disabled!"
exit 2
fi
}
# Ensures the status is "off", printing a message if not
function assert_disabled() {
if [[ "$(real_status)" != "off" ]]; then
echo "Getflix DNS is still enabled!"
exit 2
fi
}
# The main function of the script
function main() {
local current_status="$(status)"
# Handle "status" command
if [[ $ARGC = 0 || $1 = "status" ]]; then
echo "Getflix is currently $current_status"
if [[ "$current_status" = "on" ]]; then
exit 0
else
exit 1
fi
fi
if [[ $ARGC = 1 ]]; then
if [[ "$current_status" = "$1" ]]; then
echo "Getflix is already $1!"
exit 0
fi
# Handle "check" command
if [[ $1 = "check" ]]; then
echo "Getflix is currently $current_status"
echo "Getflix check returned '$(real_status)'"
exit 0
fi
# Handle "on" command
if [[ $1 = "on" ]]; then
configuration | sudo tee "$RESOLVER_FILE" > /dev/null
assert_enabled
exit 0
fi
# Handle "off" command
if [[ $1 = "off" ]]; then
sudo rm "$RESOLVER_FILE"
assert_disabled
exit 0
fi
fi
}
main $@
usage
exit 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment