Simplifying avahi browsing

This commit is contained in:
Bob Mottram 2015-09-11 19:36:04 +01:00
parent 12247529e4
commit fe8e416909
3 changed files with 6 additions and 11 deletions

View File

@ -250,7 +250,7 @@ if [[ $SERVER_INSTALLATION == "no" ]]; then
fi fi
fi fi
avahi-browse -atl | grep "Workstation" | awk -F ' ' '{print $4}' | sort -u > $PEERS_FILE avahi-browse -atl | awk -F ' ' '{print $4}' | sort -u > $PEERS_FILE
if [ ! -f $PEERS_FILE ]; then if [ ! -f $PEERS_FILE ]; then
echo 'No peers were found' echo 'No peers were found'

View File

@ -277,7 +277,7 @@ if [[ $SERVER_INSTALLATION == "no" ]]; then
fi fi
fi fi
avahi-browse -atl | grep "Workstation" | awk -F ' ' '{print $4}' | sort -u > $PEERS_FILE avahi-browse -atl | awk -F ' ' '{print $4}' | sort -u > $PEERS_FILE
if [ ! -f $PEERS_FILE ]; then if [ ! -f $PEERS_FILE ]; then
echo 'No peers were found' echo 'No peers were found'

View File

@ -114,7 +114,7 @@ fi
TEMPFILE_BASE=/tmp/tmpzeronetavahibase.txt TEMPFILE_BASE=/tmp/tmpzeronetavahibase.txt
TEMPFILE=/tmp/tmpzeronetavahi.txt TEMPFILE=/tmp/tmpzeronetavahi.txt
avahi-browse -atr > $TEMPFILE_BASE avahi-browse -atr > $TEMPFILE_BASE
cat $TEMPFILE_BASE | grep "Workstation\|hostname =\|address =\|port =" > $TEMPFILE cat $TEMPFILE_BASE | grep "hostname =\|address =\|port =" > $TEMPFILE
if [ ! -f $TEMPFILE ]; then if [ ! -f $TEMPFILE ]; then
exit 1 exit 1
fi fi
@ -131,7 +131,7 @@ address=""
peer="" peer=""
tracker_ctr=0 tracker_ctr=0
while IFS='' read -r line || [[ -n "$line" ]]; do while IFS='' read -r line || [[ -n "$line" ]]; do
if [ ${state} -eq "2" ]; then if [ ${state} -eq "1" ]; then
if [[ $line == *"address ="* ]]; then if [[ $line == *"address ="* ]]; then
address=$(echo $line | awk -F '[' '{print $2}' | awk -F ']' '{print $1}') address=$(echo $line | awk -F '[' '{print $2}' | awk -F ']' '{print $1}')
echo " http://$peer:$TRACKER_PORT/announce" >> $ZERONET_CONFIG.new echo " http://$peer:$TRACKER_PORT/announce" >> $ZERONET_CONFIG.new
@ -139,13 +139,8 @@ while IFS='' read -r line || [[ -n "$line" ]]; do
tracker_ctr=$((tracker_ctr + 1)) tracker_ctr=$((tracker_ctr + 1))
fi fi
fi fi
if [ ${state} -eq "1" ]; then if [[ $line == *"hostname ="* ]]; then
if [[ $line == *"hostname ="* ]]; then peer=$(echo $line | awk -F '[' '{print $2}' | awk -F ']' '{print $1}')
peer=$(echo $line | awk -F '[' '{print $2}' | awk -F ']' '{print $1}')
state=2
fi
fi
if [[ $line == *"Workstation"* && $line == "= "* ]]; then
state=1 state=1
fi fi
done < "$TEMPFILE" done < "$TEMPFILE"