freedombone/src/freedombone-mesh-visit-site

91 lines
2.9 KiB
Plaintext
Raw Normal View History

2016-09-04 19:50:13 +02:00
#!/bin/bash
#
# .---. . .
# | | |
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
#
# Freedom in the Cloud
#
# Visit ipfs sites by entering a username
#
# License
# =======
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PROJECT_NAME='freedombone'
export TEXTDOMAIN=${PROJECT_NAME}-mesh-visit-site
export TEXTDOMAINDIR="/usr/share/locale"
IPFS_URL='http://127.0.0.1:8080/ipns'
# The browser application to use
2016-09-08 18:12:24 +02:00
BROWSER=midori
2016-09-09 11:26:08 +02:00
BROWSER_OPTIONS='-p'
2016-09-04 19:50:13 +02:00
2016-09-08 21:45:04 +02:00
# An optional suffix to be appended to the URL
SUFFIX=$1
2016-09-12 16:21:03 +02:00
IPFS_USERS_FILE=/tmp/.ipfs-users
2016-09-04 19:50:13 +02:00
if [ ! -f $IPFS_USERS_FILE ]; then
exit 0
fi
2016-09-12 16:16:55 +02:00
USERS_FILE=/tmp/Users.txt
2016-09-04 19:50:13 +02:00
if [ ! -f $USERS_FILE ]; then
exit 0
fi
data=$(tempfile 2>/dev/null)
trap "rm -f $data" 0 1 2 5 15
dialog --title $"Visit IPFS site" \
--backtitle $"Freedombone mesh" \
2016-09-06 15:01:49 +02:00
--inputbox $"Enter the username or Tox ID for the site you wish to visit" 8 70 2>$data
2016-09-04 19:50:13 +02:00
sel=$?
case $sel in
0)
2016-09-06 15:01:49 +02:00
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:]]*//')
2016-09-04 19:50:13 +02:00
fi
2016-09-06 15:01:49 +02:00
2016-09-04 20:01:57 +02:00
if [ ${#TOX_ID} -gt 5 ]; then
if ! grep -q "$TOX_ID" $IPFS_USERS_FILE; then
dialog --title $"Visit IPFS site" \
--backtitle $"Freedombone mesh" \
2016-09-06 15:01:49 +02:00
--msgbox $"An IPFS site was not found for the user '$TOX_USERNAME_OR_ID'" 8 60
2016-09-04 20:01:57 +02:00
exit 3
fi
IPFS_FULL_URL=${IPFS_URL}/$(cat "$IPFS_USERS_FILE" | grep $TOX_ID | head -n 1 | awk -F ':' '{print $2}')
2016-09-08 18:07:12 +02:00
clear
echo $'Opening browser. Please wait...'
2016-09-09 00:38:47 +02:00
pkill $BROWSER
2016-09-09 00:47:42 +02:00
setsid sh -c "$BROWSER $BROWSER_OPTIONS $IPFS_FULL_URL$SUFFIX" > /dev/null 2>&1 < /dev/null &
2016-09-12 19:53:21 +02:00
# Need to wait a while for the browser to begin opening
sleep 3
2016-09-04 19:50:13 +02:00
fi
else
exit 1
fi
;;
esac
exit 0