Produce notifications when users join the mesh

This commit is contained in:
Bob Mottram 2016-08-03 15:31:49 +01:00
parent e96cae2a55
commit 4eafa5884e
1 changed files with 318 additions and 285 deletions

View File

@ -76,6 +76,9 @@ ZERONET_ID_STR="ZeroNet ID Service"
TEMPFILE_BASE=$(mktemp /tmp/zeronetavahibase.XXXXXX)
TEMPFILE=$(mktemp /tmp/zeronetavahi.XXXXXX)
# List of tox users previously seen
PREV_TOX_USERS_FILE=/root/.prev_tox_users
function ipfs_bootstrap {
cat $TEMPFILE_BASE | grep "IPFS\|hostname =\|address =\|port =\|txt =" > $TEMPFILE
@ -108,10 +111,40 @@ function ipfs_bootstrap {
done < "$TEMPFILE"
}
function detect_new_tox_users {
CURRENT_USERS_FILE=$1
if [ ! -f $CURRENT_USERS_FILE ]; then
return
fi
# Check that this is a GUI installation with a desktop
if [ ! -d /home/fbone/Desktop ]; then
return
fi
# Produce notifications if new users appear
if [ -f $PREV_TOX_USERS_FILE ]; then
while IFS='' read -r line || [[ -n "$line" ]]; do
if ! grep -q "$line" $PREV_TOX_USERS_FILE; then
# get the nick of the user
toxuser="$(echo "$line" | awk -F ' ' '{print $1}')"
notify-send $"$PROJECT_NAME mesh" $"$toxuser has joined the mesh" --icon=dialog-information
fi
done < "$CURRENT_USERS_FILE"
fi
# Store the previous tox users list
cp -f $CURRENT_USERS_FILE $PREV_TOX_USERS_FILE
}
function detect_tox_users {
# don't show the first peer field
lstox | awk -F ' ' '{$1=""; print $0}' | sed -e 's/^[[:space:]]*//' | sort -d > $TEMPFILE
detect_new_tox_users $TEMPFILE
toxctr=0
echo '<ol type="square">' >> $TOX_USERS_FILE.new
while IFS='' read -r line || [[ -n "$line" ]]; do