Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
238 lines (192 sloc) 4.82 KB
#!/bin/bash
# SaltLAN toolset
# Written by @Pips801
#
# Usage:
# #~: ./saltlan
# start
# stop
# cache
# restart
# size <target>
# list
# delete <appid>
# lookup <appid>
# logs <cache>
# dhcp
# count
# list
# search
# <ip>
# <hostname>
# <MAC addr>
#
#container names
STEAMCACHE="steam.cache.saltlan.org"
ORIGINCACHE="origin.cache.saltlan.org"
BLIZZARDCACHE="blizzard.cache.saltlan.org"
UPLAYCACHE="uplay.cache.saltlan.org"
#interfaces
WAN_INTERFACE="eno1"
LAN_INTERFACE="eno2"
STEAMCACHE_INTERFACE="eno2:2"
BLIZZARDCACHE_INTERFACE="eno2:3"
ORIGINCACHE_INTERFACE="eno2:4"
UPLAYCACHE_INTERFACE="eno2:5"
#IP
STEAMCACHE_IP="10.0.0.2"
BLIZZARDCACHE_IP="10.0.0.3"
ORIGINCACHE_IP="10.0.0.4"
UPLAYCACHE_IP="10.0.0.5"
#Namespace
HOSTNAME_SPACE="saltlan.org"
if [[ $1 == "cache" ]]
then
if [[ $2 == "size" ]] # saltlan cache size
then
if [[ -n "$3" ]] #saltlan cache size <target> (if isset <target>)
then
docker exec $3.cache.saltlan.org du -sh /data/cache | sed "s/\/data\/cache//"
else #no target
echo "[Error] No cache selected."
echo "Cache options: steam, blizzard, origin, uplay"
exit 1
fi
elif [[ $2 == "list" ]] # saltlan cache list
then
docker exec steam.cache.saltlan.org ls -1 /data/cache/depot/
elif [[ $2 == "delete" ]] # saltlan cache delete
then
if [[ -n "$3" ]] # saltlan cache <appid>
then
docker exec steam.cache.saltlan.org rm -r /data/cache/depot/$3/
echo "Deleted $3"
else # no target
echo "[Error] appid not set."
exit 1
fi
elif [[ $2 == "lookup" ]]
then
if [[ -n "$3" ]]
then
curl -Ls https://steamdb.info/depot/$3 | grep "\<h1" | sed 's/.*header-title\">//;s/<\/h1.*//' | sed 's/<[^>]*>//g' | sed 's/Depot » //g'
else
echo "[Error] appid not set."
exit 1
fi
elif [[ $2 == "restart" ]]
then
if [[ -n "$3" ]]
then
docker restart $3.cache.saltlan.org > /dev/null
echo "Restarted."
else
echo "[Error] No cache selected."
fi
fi
elif [[ $1 = "logs" ]]
then
if [[ -n "$2" ]]
then
if [[ $2 == "dns" ]]
then
echo "[Info] Press Ctrl-c to exit."
tail -F /etc/dnsmasq.log | grep "\[A"
elif [[ $2 == "dhcp" ]]
then
echo "[Info] Press Ctrl-c to exit."
tail -F /etc/dnsmasq.log | grep "dnsmasq-dhcp"
else
echo "[Info] Press Ctrl-c to exit."
docker exec $2.cache.saltlan.org tail -F /data/logs/access.log
fi
else
echo "[Error] No cache selected."
echo "Cache options: steam, blizzard, origin, uplay"
fi
elif [[ $1 = "dhcp" ]]
then
if [[ $2 == "count" ]]
then
sed -n '$=' /var/lib/misc/dnsmasq.leases
elif [[ $2 == "list" ]]
then
cat '/var/lib/misc/dnsmasq.leases'
elif [[ $2 == "search" ]]
then
if [[ -n "$3" ]]
then
cat "/var/lib/misc/dnsmasq.leases" | grep $3
else
echo "[Error] no search param."
fi
fi
elif [[ $1 == "start" ]]
then
clear
figlet SaltLAN | lolcat -a -d 7
echo "Starting $STEAMCACHE..."
docker start $STEAMCACHE > /dev/null
echo "Starting $BLIZZARDCACHE..."
docker start $BLIZZARDCACHE > /dev/null
echo "Starting $ORIGINCACHE..."
docker start $ORIGINCACHE > /dev/null
echo "$starting $UPLAYCACHE..."
docker start $UPLAYCACHE > /dev/null
echo "Starting Grafana..."
service grafana-server restart
tmux new -d -s grafana "grafana-server | lolcat -p 100 -F 0.005"
echo "Starting InfluxDB..."
service influxd stop
tmux new -d -s influx "influxd | lolcat -p 100 -F 0.005"
echo "Starting Telegraf..."
service telegraf stop
tmux new -d -s telegraf "telegraf | lolcat -p 100 -F 0.005"
echo "Reloading dnsmasq..."
service dnsmasq restart
echo "Done."
elif [[ $1 == "stop" ]]
then
clear
figlet SaltLAN | lolcat -a -d 7
echo "Stopping $STEAMCACHE..."
docker stop $STEAMCACHE
echo "Stopping $ORIGINCACHE..."
docker stop $ORIGINCACHE
echo "Stopping $BLIZZARDCACHE..."
docker stop $BLIZZARDCACHE
echo "Stopping $UPLAYCACHE..."
docker stop $UPLAYCACHE
tmux kill-session -t telegraf
tmux kill-session -t influx
tmux kill-session -t grafana
elif [[ $1 == "help" ]]
then
figlet "SaltLAN"
echo "
SaltLAN toolset
Written by @Pips801
Usage:
#~: ./saltlan
start
stop
cache
restart <cache>
size <cache>
list
delete <appid>
lookup <appid>
logs
dns
dhcp
<cache>
dhcp
count
list
search
<ip>
<hostname>
<MAC addr>"
else
echo "[Error] No option selected."
fi