Lazystream
Jump to navigation
Jump to search
IPTV setup for lazyman streams
Crontab setup for auto creation of m3u and xml files
- /etc/cron.d/lazystream
# Download yesterdays playlist 0 7 * * * root /usr/local/sbin/lazystream generate playlist --sport nhl --date `date -d "-1 day" "+\%Y\%m\%d"` /var/www/html/nhl_yesterday >> /var/log/lazystream.log 2>&1 # Download today playlist 45 * * * * root /usr/local/sbin/lazystream generate playlist --sport nhl /var/www/html/nhl >> /dev/null 2>&1
Lazyman IP update
This was adapted from the pfsense script as I am using Unbound natively on Ubuntu.
#!/bin/sh
# For the latest update please visit https://www.reddit.com/r/LazyMan/comments/7diu8l/pfsense_lazyman_dns_auto_update_script/
# This script has been created for pfSense users who use DNS Resolver.
# This script is to be used in combination with Lazyman apps
# It monitors a Lazyman server to see if it's IP has changed
# It is NOT currently compatible with the DNS forwarder, although with some changes may work
name="Lazyman DNS Auto Update Script for pfSense"
version=0.9
author="NoOne"
conf="/etc/unbound/unbound.conf.d/host_entries.conf"
site="freesports.ddns.net"
host1="mf.svc.nhl.com"
host2="playback.svcs.mlb.com"
host3="mlb-ws-mf.media.mlb.com"
update_dns() {
echo ""
echo $name "Version" $version "by" $author
echo "Script initiated `date`"
conf_check
server_status
}
server_status() {
ping -c1 $site > /dev/null
if [ $? -eq 0 ]
then
echo $site is up, continuing script
DNSIP=$(ping -c 1 "$site" | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b" | head -1) #checks defined LM host to see the current IP
echo "Lazyman server currently resolves to" $DNSIP
echo ""
check_host1
update_host1
check_host2
update_host2
check_host3
update_host3
restart_unbound
echo "Script ended `date`"
exit 0
else
echo $site is currently down, no updates will be performed
exit 1
fi
}
check_host1() {
HOSTIP1=$(grep -E $host1 $conf | head -1 | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b") #checks $conf first entry to see the current Lazyman IP
HOSTIP2=$(grep -E $host1 $conf | head -2 | tail -1 | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b") #same as previous check but for second entry
if [ -z "$HOSTIP1" ]; then
echo "First entry for $host1 is missing an IP."
UPDATE=true
elif [ "$HOSTIP1" != "$DNSIP" ]; then
echo "First entry for $host1 is set to" $HOSTIP1
UPDATE=true
fi
if [ -z "$HOSTIP2" ]; then
echo "Second entry for $host1 is missing an IP."
UPDATE=true
elif [ "$HOSTIP2" != "$DNSIP" ]; then
echo "Second entry for $host1 is set to" $HOSTIP2
UPDATE=true
fi
if [ "$HOSTIP1" = "$DNSIP" ] && [ "$HOSTIP2" = "$DNSIP" ]; then #do IPs match?
echo "Both entries for $host1 are up to date."
UPDATE=false
fi
}
check_host2() {
HOSTIP1=$(grep -E $host2 $conf | head -1 | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b") #checks $conf first entry to see the current Lazyman IP
HOSTIP2=$(grep -E $host2 $conf | head -2 | tail -1 | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b") #same as previous check but for second entry
if [ -z "$HOSTIP1" ]; then
echo "First entry for $host2 is missing an IP."
UPDATE=true
elif [ "$HOSTIP1" != "$DNSIP" ]; then
echo "First entry for $host2 is set to" $HOSTIP1
UPDATE=true
fi
if [ -z "$HOSTIP2" ]; then
echo "Second entry for $host2 is missing an IP."
UPDATE=true
elif [ "$HOSTIP2" != "$DNSIP" ]; then
echo "Second entry for $host2 is set to" $HOSTIP2
UPDATE=true
fi
if [ "$HOSTIP1" = "$DNSIP" ] && [ "$HOSTIP2" = "$DNSIP" ]; then #do IPs match?
echo "Both entries for $host2 are up to date."
UPDATE=false
fi
}
check_host3() {
HOSTIP1=$(grep -E $host3 $conf | head -1 | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b") #checks $conf first entry to see the current Lazyman IP
HOSTIP2=$(grep -E $host3 $conf | head -2 | tail -1 | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b") #same as previous check but for second entry
if [ -z "$HOSTIP1" ]; then
echo "First entry for $host3 is missing an IP."
UPDATE=true
elif [ "$HOSTIP1" != "$DNSIP" ]; then
echo "First entry for $host3 is set to" $HOSTIP1
UPDATE=true
fi
if [ -z "$HOSTIP2" ]; then
echo "Second entry for $host3 is missing an IP."
UPDATE=true
elif [ "$HOSTIP2" != "$DNSIP" ]; then
echo "Second entry for $host3 is set to" $HOSTIP2
UPDATE=true
fi
if [ "$HOSTIP1" = "$DNSIP" ] && [ "$HOSTIP2" = "$DNSIP" ]; then #do IPs match?
echo "Both entries for $host3 are up to date."
UPDATE=false
fi
}
update_host1() {
if [ "$UPDATE" = "true" ]; then
echo "Update required for $host1"
sed -i "/$host1/d" $conf #removes host1 entry from $conf
echo "Setting host" $host1 "to resolve to" $DNSIP
echo "local-data-ptr: "\"$DNSIP "$host1"\" >> $conf #adds first update to $conf
echo "local-data: "\"$host1. A $DNSIP\" >> $conf #adds second update to $conf
RESTART=true
else
echo "No changes will be made to $host1"
RESTART=false
fi
}
update_host2() {
if [ "$UPDATE" = "true" ]; then
echo "Update required for $host2"
sed -i "/$host2/d" $conf #removes host2 entry from $conf
echo "Setting host" $host2 "to resolve to" $DNSIP
echo "local-data-ptr: "\"$DNSIP "$host2"\" >> $conf #adds first update to $conf
echo "local-data: "\"$host2. A $DNSIP\" >> $conf #adds second update to $conf
RESTART=true
else
echo "No changes will be made to $host2"
RESTART=false
fi
}
update_host3() {
if [ "$UPDATE" = "true" ]; then
echo "Update required for $host3"
sed -i "/$host3/d" $conf #removes host3 entry from $conf
echo "Setting host" $host3 "to resolve to" $DNSIP
echo "local-data-ptr: "\"$DNSIP "$host3"\" >> $conf #adds first update to $conf
echo "local-data: "\"$host3. A $DNSIP\" >> $conf #adds second update to $conf
RESTART=true
else
echo "No changes will be made to $host3"
RESTART=false
fi
}
restart_unbound() {
if [ "$RESTART" = true ] #using flag and if statement means it won't restart after each host is checked.
then
#/usr/local/sbin/pfSsh.php playback svc restart unbound #restarts unbound service
service unbound restart
echo ""
else
echo "Unbound Service Restart Not Required"
echo ""
fi
}
conf_check() {
echo "Checking to see if config file exists..."
if [ -f $conf ] #checks to see if $conf file exists
then
echo "Config file $conf found."
else #conf file doesn't exist
echo "$conf not found."
echo "Creating $conf ..."
touch $conf #creates empty $conf file
fi
}
if [ -z $TERM ]; then
rm /var/log/lazyman.log #deletes old log
update_dns 2>&1 >> /var/log/lazyman.log #logs output
else #does not log output when called from terminal
update_dns
fi