Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- SERVICE_NAMES=(
- 'nguri TimeCapsule' # For AFP
- 'nguri SMB' # For SMB
- 'nguri TimeCapsule' # For AFP Icon
- 'nguri SMB' # For SMB Icon
- 'Brother MFC-9120CN' # Printer
- 'Brother MFC-9120CN' # Print spooler
- 'Brother MFC-9120CN' # PDL Data stream
- )
- SERVICE_TYPES=(
- _afpovertcp._tcp
- _smb._tcp
- _device-info._tcp
- _device-info._tcp
- _ipp._tcp
- _printer._tcp
- _pdl-datastream._tcp
- )
- SERVICE_PORTS=(
- 548
- 445
- 1
- 1
- 631
- 515
- 9100
- )
- SERVICE_IPS=(
- 192.168.1.1
- 192.168.1.1
- 192.168.1.1
- 192.168.1.1
- 192.168.1.2
- 192.168.1.2
- 192.168.1.2
- )
- # FIX: Use one valid string format across all three service text definitions
- SERVICE_TEXTS=(
- ''
- ''
- model=TimeCapsule8,119
- model=Xserve
- 'txtvers=1 qtotal=1 pdl=application//vnd.hp-PCL,application//vnd.brother-hbp rp=duerqxesz5090 ty="Brother MFC-9120CN" product="(Brother MFC-9120CN)" adminurl=http://BRN001BA9243652.local./ priority=50 usb_MFG=Brother usb_MDL=MFC-9120CN Color=T Copies=T Duplex=F PaperCustom=T Binary=T Transparent=T TBCP=F'
- 'txtvers=1 qtotal=1 pdl=application/vnd.hp-PCL,application/vnd.brother-hbp rp=duerqxesz5090 ty="Brother MFC-9120CN" product="(Brother MFC-9120CN)" adminurl=http://BRN001BA9243652.local./ priority=75 usb_MFG=Brother usb_MDL=MFC-9120CN Color=T Copies=T Duplex=F PaperCustom=T Binary=T Transparent=T TBCP=F'
- 'txtvers=1 qtotal=1 pdl=application/vnd.hp-PCL,application/vnd.brother-hbp ty="Brother MFC-9120CN" product="(Brother MFC-9120CN)" adminurl=http://BRN001BA9243652.local./ priority=25 usb_MFG=Brother usb_MDL=MFC-9120CN Color=T Copies=T Duplex=F PaperCustom=T Binary=T Transparent=F TBCP=T'
- )
- declare -a PIDS
- SLEEP_INTERVAL=10
- while [ true ]; do
- ifconfig ppp0 &>/dev/null
- if [ "$?" -eq "0" ]; then
- # We are connected to ppp0
- for ((n=0; n < ${#SERVICE_NAMES[@]}; n++)); do
- # Is dns-sd already running for a particular service?
- kill -0 "${PIDS[$n]}" &>/dev/null
- DNSSD_RUNNING=$?
- # Start if not running...
- if [ "$DNSSD_RUNNING" -ne "0" ]; then
- echo "Starting DNS SD Proxy for service ${SERVICE_TYPES[$n]} on server ${SERVICE_NAMES[$n]}"
- #FIX: by using a temporar variable we can debug the exact command that will be used including all quotes
- CMD="dns-sd -P \"${SERVICE_NAMES[$n]}\" ${SERVICE_TYPES[$n]} local ${SERVICE_PORTS[$n]} \"${SERVICE_NAMES[$n]}.local\" \"${SERVICE_IPS[$n]}\" ${SERVICE_TEXTS[$n]} &>/dev/null &"
- echo "DEBUG: $CMD"
- # use exactly this command
- eval $CMD
- PIDS[$n]=$!;
- # Don't do anything if already running...
- else
- echo "DNS SD Proxy for service ${SERVICE_TYPES[$n]} on server ${SERVICE_NAMES[$n]} is already running"
- fi
- done
- else # We're not connected to ppp0
- echo "ppp0 is not connected"
- for ((n=0; n < ${#SERVICE_NAMES[@]}; n++)); do
- # If we have running dns-sd instances, stop them
- if [ ! "${PIDS[$n]}" = "" ]; then
- echo "Stopping DNS SD Proxy for service ${SERVICE_TYPES[$n]} on server ${SERVICE_NAMES[$n]}"
- kill "${PIDS[$n]}" &>/dev/null
- PIDS[$n]="";
- else
- echo "DNS SD Proxy for service ${SERVICE_TYPES[$n]} on server ${SERVICE_NAMES[$n]} is not running"
- fi
- done
- fi
- # Wait a while...
- sleep $SLEEP_INTERVAL
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement