When visiting a mesh site choose from a list of users

This commit is contained in:
Bob Mottram 2017-12-09 10:56:22 +00:00
parent 64d843d615
commit dec2f54a1b
1 changed files with 53 additions and 30 deletions

View File

@ -49,38 +49,61 @@ if [ ! -f $USERS_FILE ]; then
exit 0
fi
data=$(zenity --entry --title="Visit IPFS site" --text="Enter the username or Tox ID for the site you wish to visit")
sel=$?
case $sel in
USERS_FILE_LINES=$(wc -l $USERS_FILE | awk -F ' ' '{print $1}')
if [ $USERS_FILE_LINES -gt 200 ]; then
# If there are more than a Dunbar number of peers then ask for the peer name or ID
data=$(zenity --entry --title="Visit IPFS site" --text="Enter the username or Tox ID for the site you wish to visit")
sel=$?
case $sel in
0)
TOX_USERNAME_OR_ID="$data"
if [ ${#TOX_USERNAME_OR_ID} -gt 0 ]; then
if ! grep -q "$TOX_USERNAME_OR_ID" $USERS_FILE; then
TOX_ID="$TOX_USERNAME_OR_ID"
else
TOX_ID=$(cat "$USERS_FILE" | grep "$TOX_USERNAME_OR_ID" | head -n 1 | sed "s|$TOX_USERNAME_OR_ID ||g" | sed -e 's/^[[:space:]]*//')
fi
if [ ${#TOX_ID} -gt 5 ]; then
if ! grep -q "$TOX_ID" $IPFS_USERS_FILE; then
dialog --title $"Visit IPFS site" \
--backtitle $"Freedombone mesh" \
--msgbox $"An IPFS site was not found for the user '$TOX_USERNAME_OR_ID'" 8 60
exit 3
fi
IPFS_FULL_URL=${IPFS_URL}/$(cat "$IPFS_USERS_FILE" | grep $TOX_ID | head -n 1 | awk -F ':' '{print $2}')
clear
echo $'Opening browser. Please wait...'
pkill $BROWSER
setsid sh -c "$BROWSER $BROWSER_OPTIONS $IPFS_FULL_URL$SUFFIX" > /dev/null 2>&1 < /dev/null &
# Need to wait a while for the browser to begin opening
sleep 3
fi
TOX_USERNAME_OR_ID="$data"
if [ ${#TOX_USERNAME_OR_ID} -gt 0 ]; then
if ! grep -q "$TOX_USERNAME_OR_ID" $USERS_FILE; then
TOX_ID="$TOX_USERNAME_OR_ID"
else
exit 1
TOX_ID=$(cat "$USERS_FILE" | grep "$TOX_USERNAME_OR_ID" | head -n 1 | sed "s|$TOX_USERNAME_OR_ID ||g" | sed -e 's/^[[:space:]]*//')
fi
;;
esac
if [ ${#TOX_ID} -gt 5 ]; then
if ! grep -q "$TOX_ID" $IPFS_USERS_FILE; then
zenity --info --title $"Visit a site" --text $"An IPFS site was not found for the user '$TOX_USERNAME_OR_ID'" --width 500
exit 3
fi
IPFS_FULL_URL=${IPFS_URL}/$(cat "$IPFS_USERS_FILE" | grep $TOX_ID | head -n 1 | awk -F ':' '{print $2}')
pkill $BROWSER
setsid sh -c "$BROWSER $BROWSER_OPTIONS $IPFS_FULL_URL$SUFFIX" > /dev/null 2>&1 < /dev/null &
# Need to wait a while for the browser to begin opening
sleep 3
fi
else
exit 1
fi
;;
esac
else
# If there are a relatively small number of users then choose from a list
TOX_ID=$(
cat $USERS_FILE | \
awk -F ' ' '{
for(i=1;i<=NF;i++){
print $i;
}
}' | \
zenity --list \
--title='Visit the site of another user' \
--column='Username' --column='Tox ID' \
--print-column=2 --hide-column=2 --width=300 --height=400)
if [ ! $TOX_ID ]; then
exit 0
fi
IPFS_FULL_URL=${IPFS_URL}/$(cat "$IPFS_USERS_FILE" | grep $TOX_ID | head -n 1 | awk -F ':' '{print $2}')
pkill $BROWSER
setsid sh -c "$BROWSER $BROWSER_OPTIONS $IPFS_FULL_URL$SUFFIX" > /dev/null 2>&1 < /dev/null &
# Need to wait a while for the browser to begin opening
sleep 3
fi
exit 0