Browse Source

An easy way to visit ipfs mesh sites

Bob Mottram 8 years ago
parent
commit
c1debe2a20
4 changed files with 93 additions and 5 deletions
  1. BIN
      img/avatars/ipfs.jpg
  2. 13
    0
      src/freedombone-image-customise
  3. 79
    0
      src/freedombone-mesh-visit-site
  4. 1
    5
      src/zeronetavahi

BIN
img/avatars/ipfs.jpg View File


+ 13
- 0
src/freedombone-image-customise View File

@@ -775,6 +775,16 @@ if [ \$no_of_users -gt 0 ]; then
775 775
     chmod +x /home/$MY_USERNAME/Desktop/Users.desktop
776 776
     chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Desktop/Users.desktop
777 777
 
778
+    if [ -f /home/$MY_USERNAME/.ipfs-users ]; then
779
+        echo 'Type=Application' >> /home/$MY_USERNAME/Desktop/sites.desktop
780
+        echo 'Comment=Visit a site' >> /home/$MY_USERNAME/Desktop/sites.desktop
781
+        echo 'Exec=bash /usr/local/bin/freedombone-mesh-visit-site' >> /home/$MY_USERNAME/Desktop/sites.desktop
782
+        echo 'Icon=/usr/share/freedombone/avatars/ipfs.jpg' >> /home/$MY_USERNAME/Desktop/sites.desktop
783
+        echo 'StartupNotify=false' >> /home/$MY_USERNAME/Desktop/sites.desktop
784
+        chmod +x /home/$MY_USERNAME/Desktop/sites.desktop
785
+        chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Desktop/sites.desktop
786
+    fi
787
+
778 788
     if [ ! -f /home/$MY_USERNAME/runtox ]; then
779 789
         echo 'qtox_running=\$(ps aux | grep qtox | grep data)' > /home/$MY_USERNAME/runtox
780 790
         echo 'if [ \${#qtox_running} -eq 0 ]; then' >> /home/$MY_USERNAME/runtox
@@ -801,6 +811,9 @@ else
801 811
         if [ -f /home/$MY_USERNAME/Desktop/Users.desktop ]; then
802 812
             rm /home/$MY_USERNAME/Desktop/Users.desktop
803 813
         fi
814
+        if [ -f /home/$MY_USERNAME/Desktop/sites.desktop ]; then
815
+            rm /home/$MY_USERNAME/Desktop/sites.desktop
816
+        fi
804 817
         if [ -f /home/$MY_USERNAME/Desktop/tox.desktop ]; then
805 818
             rm /home/$MY_USERNAME/Desktop/tox.desktop
806 819
         fi

+ 79
- 0
src/freedombone-mesh-visit-site View File

@@ -0,0 +1,79 @@
1
+#!/bin/bash
2
+#
3
+# .---.                  .              .
4
+# |                      |              |
5
+# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
6
+# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
7
+# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
8
+#
9
+#                    Freedom in the Cloud
10
+#
11
+# Visit ipfs sites by entering a username
12
+#
13
+# License
14
+# =======
15
+#
16
+# This program is free software: you can redistribute it and/or modify
17
+# it under the terms of the GNU Affero General Public License as published by
18
+# the Free Software Foundation, either version 3 of the License, or
19
+# (at your option) any later version.
20
+#
21
+# This program is distributed in the hope that it will be useful,
22
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
23
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
+# GNU Affero General Public License for more details.
25
+#
26
+# You should have received a copy of the GNU Affero General Public License
27
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
28
+
29
+PROJECT_NAME='freedombone'
30
+
31
+export TEXTDOMAIN=${PROJECT_NAME}-mesh-visit-site
32
+export TEXTDOMAINDIR="/usr/share/locale"
33
+
34
+IPFS_URL='http://127.0.0.1:8080/ipns'
35
+
36
+# The browser application to use
37
+BROWSER=iceweasel
38
+
39
+IPFS_USERS_FILE=/home/$USER/.ipfs-users
40
+if [ ! -f $IPFS_USERS_FILE ]; then
41
+    exit 0
42
+fi
43
+USERS_FILE=/home/$USER/Users.txt
44
+if [ ! -f $USERS_FILE ]; then
45
+    exit 0
46
+fi
47
+
48
+data=$(tempfile 2>/dev/null)
49
+trap "rm -f $data" 0 1 2 5 15
50
+dialog --title $"Visit IPFS site" \
51
+    --backtitle $"Freedombone mesh" \
52
+    --inputbox $"Enter the username for the site you wish to visit" 8 60 2>$data
53
+sel=$?
54
+case $sel in
55
+    0)
56
+        TOX_USERNAME=$(<$data)
57
+        if [ ${#TOX_USERNAME} -gt 0 ]; then
58
+            if ! grep -q "$TOX_USERNAME" $USERS_FILE; then
59
+                dialog --title $"Visit IPFS site" \
60
+                       --backtitle $"Freedombone mesh" \
61
+                       --msgbox $"The user '$TOX_USERNAME' was not found on the mesh" 8 60
62
+                exit 2
63
+            fi
64
+            TOX_ID=$(cat "$USERS_FILE" | grep "$TOX_USERNAME" | head -n 1 | awk -F ' ' '{print $2}')
65
+            if ! grep -q "$TOX_ID" $IPFS_USERS_FILE; then
66
+                dialog --title $"Visit IPFS site" \
67
+                       --backtitle $"Freedombone mesh" \
68
+                       --msgbox $"An IPFS site was not found for the user '$TOX_USERNAME'" 8 60
69
+                exit 3
70
+            fi
71
+            IPFS_FULL_URL=${IPFS_URL}/$(cat "$IPFS_USERS_FILE" | grep $TOX_ID | head -n 1 | awk -F ':' '{print $2}')
72
+            $BROWSER $IPFS_FULL_URL
73
+        else
74
+            exit 1
75
+        fi
76
+    ;;
77
+esac
78
+
79
+exit 0

+ 1
- 5
src/zeronetavahi View File

@@ -56,7 +56,6 @@ IPFS_PATH=/usr/bin
56 56
 IPFS_COMMAND=$IPFS_PATH/ipfs
57 57
 IPFS_USERS_FILE=/home/$MY_USERNAME/.ipfs-users
58 58
 IPFS_PUBLIC=/home/$MY_USERNAME/.ipfs-public
59
-IPFS_URL='http://127.0.0.1:8080/ipns'
60 59
 
61 60
 MY_BLOG_STR=$"My Blog"
62 61
 MY_MAIL_STR=$"My Mail"
@@ -133,10 +132,7 @@ function ipfs_bootstrap {
133 132
                 ipfs_tox_id=$(echo "$ipfs_txt" | awk -F ':' '{print $2}')
134 133
                 $IPFS_COMMAND bootstrap add /ip4/${address}/tcp/${IPFS_PORT}/ipfs/${ipfs_peer_id}
135 134
                 if [ -d /home/$MY_USERNAME/Desktop ]; then
136
-                    if grep -q "$ipfs_tox_id" $TOX_USERS_FILE; then
137
-                        ipfs_tox_nick=$(cat $TOX_USERS_FILE | grep $ipfs_tox_id | awk -F ' ' '{print $1}')
138
-                        echo "$ipfs_tox_nick:${IPFS_URL}/$ipfs_peer_id" >> ${IPFS_USERS_FILE}.new
139
-                    fi
135
+                    echo "$ipfs_tox_id:$ipfs_peer_id" >> ${IPFS_USERS_FILE}.new
140 136
                 fi
141 137
                 state=0
142 138
             fi