When visiting a mesh site choose from a list of users
This commit is contained in:
parent
64d843d615
commit
dec2f54a1b
|
@ -49,38 +49,61 @@ if [ ! -f $USERS_FILE ]; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
data=$(zenity --entry --title="Visit IPFS site" --text="Enter the username or Tox ID for the site you wish to visit")
|
USERS_FILE_LINES=$(wc -l $USERS_FILE | awk -F ' ' '{print $1}')
|
||||||
sel=$?
|
|
||||||
case $sel in
|
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)
|
0)
|
||||||
TOX_USERNAME_OR_ID="$data"
|
TOX_USERNAME_OR_ID="$data"
|
||||||
if [ ${#TOX_USERNAME_OR_ID} -gt 0 ]; then
|
if [ ${#TOX_USERNAME_OR_ID} -gt 0 ]; then
|
||||||
if ! grep -q "$TOX_USERNAME_OR_ID" $USERS_FILE; then
|
if ! grep -q "$TOX_USERNAME_OR_ID" $USERS_FILE; then
|
||||||
TOX_ID="$TOX_USERNAME_OR_ID"
|
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
|
|
||||||
else
|
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
|
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
|
exit 0
|
||||||
|
|
Loading…
Reference in New Issue