-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathradio
executable file
·42 lines (38 loc) · 1.32 KB
/
radio
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env bash
#######################################################################
# Made by : Ewoud Dronkert
# Licence : GNU GPL v3
# Platform : Mac OS X
# Requires : Bash, ssh, ssh-key access to remote
# on remote: piradio script, mpd, mpc
# Location : ~/bin/
# Name : radio
# Version : 1.0.1
# Date : 2014-12-02
# Purpose : Execute local radio command on remote host
# Check if host is up using dig, if available
# Parameters : any parameter for remote piradio command
# Exit 0 : success
# 1 : ssh not found
# 2 : host down
#######################################################################
REMOTEHOST=${MPD_HOST:-'black'} # use MPD_HOST if set, or default
REMOTEUSER=pi # ssh user name on remote
REMOTEPORT=22000 # ssh port on remote
SSHBIN=/usr/bin/ssh
if [ ! -x $SSHBIN ]; then
echo "Can't execute $SSHBIN" >&2
exit 1
fi
DIGBIN=/usr/bin/dig
if [ -x $DIGBIN ]; then
DNSSERVER=192.168.178.1 # DNS service of DSL modem
DNSSUFFIX=.fritz.box # LAN suffix used by DSL modem
REMOTEADDR=$($DIGBIN @$DNSSERVER $REMOTEHOST$DNSSUFFIX A +short)
if [ -z "$REMOTEADDR" ]; then
echo "Host $REMOTEHOST unreachable." >&2
exit 2
fi
fi
$SSHBIN -x -p $REMOTEPORT $REMOTEUSER@$REMOTEHOST piradio "$*"
exit 0