Browse Source

ipfs sites list

Bob Mottram 8 years ago
parent
commit
045453e9ec
2 changed files with 78 additions and 5 deletions
  1. 26
    3
      src/freedombone-image-mesh
  2. 52
    2
      src/zeronetavahi

+ 26
- 3
src/freedombone-image-mesh View File

751
     IPFS_PATH=/usr/bin
751
     IPFS_PATH=/usr/bin
752
     IPFS_KEY_LENGTH=2048
752
     IPFS_KEY_LENGTH=2048
753
     IPFS_COMMAND=$IPFS_PATH/ipfs
753
     IPFS_COMMAND=$IPFS_PATH/ipfs
754
+    IPFS_PUBLIC=/home/$MY_USERNAME/.ipfs-public
754
 
755
 
755
     su -c "systemctl --user enable ipfs" - $MY_USERNAME
756
     su -c "systemctl --user enable ipfs" - $MY_USERNAME
756
     su -c "systemctl --user start ipfs" - $MY_USERNAME
757
     su -c "systemctl --user start ipfs" - $MY_USERNAME
757
 
758
 
759
+    if [ -d /home/$MY_USERNAME/Public ]; then
760
+        rm -rf /home/$MY_USERNAME/Public
761
+    fi
762
+
758
     if [ -d /home/$MY_USERNAME/.ipfs ]; then
763
     if [ -d /home/$MY_USERNAME/.ipfs ]; then
764
+        shred -zu /home/$MY_USERNAME/.ipfs/config
759
         rm -rf /home/$MY_USERNAME/.ipfs
765
         rm -rf /home/$MY_USERNAME/.ipfs
760
     fi
766
     fi
761
 
767
 
762
     if [ -f /home/$MY_USERNAME/.ipfs-id ]; then
768
     if [ -f /home/$MY_USERNAME/.ipfs-id ]; then
763
-        rm -f /home/$MY_USERNAME/.ipfs-id
769
+        shred -zu /home/$MY_USERNAME/.ipfs-id
770
+    fi
771
+
772
+    if [ -f /home/$MY_USERNAME/.ipfs-public ]; then
773
+        shred -zu /home/$MY_USERNAME/.ipfs-public
764
     fi
774
     fi
765
 
775
 
766
     if [ -f /home/$MY_USERNAME/.ipfs-users ]; then
776
     if [ -f /home/$MY_USERNAME/.ipfs-users ]; then
767
-        rm -f /home/$MY_USERNAME/.ipfs-users
777
+        shred -zu /home/$MY_USERNAME/.ipfs-users
768
     fi
778
     fi
769
 
779
 
770
     su -c "$IPFS_COMMAND init -b $IPFS_KEY_LENGTH" - $MY_USERNAME
780
     su -c "$IPFS_COMMAND init -b $IPFS_KEY_LENGTH" - $MY_USERNAME
787
         return
797
         return
788
     fi
798
     fi
789
 
799
 
800
+    # make a public directory
801
+    if [ -d /home/$MY_USERNAME/Desktop ]; then
802
+        if [ ! -d /home/$MY_USERNAME/Public ]; then
803
+            mkdir /home/$MY_USERNAME/Public
804
+            chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Public
805
+            su -c "echo \$($IPFS_COMMAND add -rq /home/$MY_USERNAME/Public | tail -n 1) > $IPFS_PUBLIC" - $MY_USERNAME
806
+            if [ ! -f $IPFS_PUBLIC ]; then
807
+                echo $'Unable to create public IPFS directory' >> $INSTALL_LOG
808
+                exit 368225
809
+            fi
810
+        fi
811
+    fi
812
+
790
     TOX_ID=$(su -c 'toxid' - $MY_USERNAME)
813
     TOX_ID=$(su -c 'toxid' - $MY_USERNAME)
791
-    create_avahi_service ipfs "ipfs" udp $IPFS_PORT "$IPFS_PEER_ID:$TOX_ID"
814
+    create_avahi_service ipfs "ipfs" udp $IPFS_PORT "${IPFS_PEER_ID}:${TOX_ID}"
792
 
815
 
793
     echo 'IPFS installed with ID $IPFS_PEER_ID' >> $INSTALL_LOG
816
     echo 'IPFS installed with ID $IPFS_PEER_ID' >> $INSTALL_LOG
794
 }
817
 }

+ 52
- 2
src/zeronetavahi View File

55
 IPFS_PATH=/usr/bin
55
 IPFS_PATH=/usr/bin
56
 IPFS_COMMAND=$IPFS_PATH/ipfs
56
 IPFS_COMMAND=$IPFS_PATH/ipfs
57
 IPFS_USERS_FILE=/home/$MY_USERNAME/.ipfs-users
57
 IPFS_USERS_FILE=/home/$MY_USERNAME/.ipfs-users
58
+IPFS_PUBLIC=/home/$MY_USERNAME/.ipfs-public
59
+IPFS_URL='http://127.0.0.1:8080/ipns'
58
 
60
 
59
 MY_BLOG_STR=$"My Blog"
61
 MY_BLOG_STR=$"My Blog"
60
 MY_MAIL_STR=$"My Mail"
62
 MY_MAIL_STR=$"My Mail"
84
 # List of tox users previously seen
86
 # List of tox users previously seen
85
 PREV_TOX_USERS_FILE=/root/.prev_tox_users
87
 PREV_TOX_USERS_FILE=/root/.prev_tox_users
86
 
88
 
89
+function ipfs_publish {
90
+    # Publishes anything within the ~/Public directory
91
+
92
+    DIR_TO_CHECK=/home/$MY_USERNAME/Public
93
+    if [ ! -d $DIR_TO_CHECK ]; then
94
+        return
95
+    fi
96
+
97
+    OLD_STAT_FILE=/home/$MY_USERNAME/.old_stat.txt
98
+
99
+    if [ -e $OLD_STAT_FILE ]
100
+    then
101
+        OLD_STAT=$(cat $OLD_STAT_FILE)
102
+    else
103
+        OLD_STAT="nothing"
104
+    fi
105
+
106
+    NEW_STAT=$(stat -t $DIR_TO_CHECK)
107
+
108
+    if [ "$OLD_STAT" != "$NEW_STAT" ]; then
109
+        su -c "echo \$($IPFS_COMMAND add -rq /home/$MY_USERNAME/Public | tail -n 1) > $IPFS_PUBLIC" - $MY_USERNAME
110
+        echo $NEW_STAT > $OLD_STAT_FILE
111
+    fi
112
+
113
+    if [ -f $IPFS_PUBLIC ]; then
114
+        IPFS_PUBLIC_ID=$(cat $IPFS_PUBLIC)
115
+        su -c "$IPFS_COMMAND name publish /ipfs/$IPFS_PUBLIC_ID" - $MY_USERNAME
116
+    fi
117
+}
118
+
87
 function ipfs_bootstrap {
119
 function ipfs_bootstrap {
88
     cat $TEMPFILE_BASE | grep "IPFS\|hostname =\|address =\|port =\|txt =" > $TEMPFILE
120
     cat $TEMPFILE_BASE | grep "IPFS\|hostname =\|address =\|port =\|txt =" > $TEMPFILE
89
 
121
 
90
     state=0
122
     state=0
91
     address=""
123
     address=""
92
     peer=""
124
     peer=""
93
-    echo -n '' > $IPFS_USERS_FILE
125
+    if [ -d /home/$MY_USERNAME/Desktop ]; then
126
+        echo -n '' > ${IPFS_USERS_FILE}.new
127
+    fi
94
     while IFS='' read -r line || [[ -n "$line" ]]; do
128
     while IFS='' read -r line || [[ -n "$line" ]]; do
95
         if [ ${state} -eq "3" ]; then
129
         if [ ${state} -eq "3" ]; then
96
             if [[ $line == *"txt ="* ]]; then
130
             if [[ $line == *"txt ="* ]]; then
98
                 ipfs_peer_id=$(echo "$ipfs_txt" | awk -F ':' '{print $1}')
132
                 ipfs_peer_id=$(echo "$ipfs_txt" | awk -F ':' '{print $1}')
99
                 ipfs_tox_id=$(echo "$ipfs_txt" | awk -F ':' '{print $2}')
133
                 ipfs_tox_id=$(echo "$ipfs_txt" | awk -F ':' '{print $2}')
100
                 $IPFS_COMMAND bootstrap add /ip4/${address}/tcp/${IPFS_PORT}/ipfs/${ipfs_peer_id}
134
                 $IPFS_COMMAND bootstrap add /ip4/${address}/tcp/${IPFS_PORT}/ipfs/${ipfs_peer_id}
101
-                echo "$ipfs_tox_id $ipfs_peer_id" >> $IPFS_USERS_FILE
135
+                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
140
+                fi
102
                 state=0
141
                 state=0
103
             fi
142
             fi
104
         fi
143
         fi
118
             state=1
157
             state=1
119
         fi
158
         fi
120
     done < "$TEMPFILE"
159
     done < "$TEMPFILE"
160
+
161
+    # Create a list of user sites, in alphabetical order by Tox nick
162
+    if [ -d /home/$MY_USERNAME/Desktop ]; then
163
+        if [ -f ${IPFS_USERS_FILE}.new ]; then
164
+            sites_list=$(cat ${IPFS_USERS_FILE}.new | sort -d)
165
+            echo "${sites_list}" > ${IPFS_USERS_FILE}
166
+            chown $MY_USERNAME:$MY_USERNAME ${IPFS_USERS_FILE}
167
+            rm ${IPFS_USERS_FILE}.new
168
+        fi
169
+    fi
121
 }
170
 }
122
 
171
 
123
 function detect_new_tox_users {
172
 function detect_new_tox_users {
506
 
555
 
507
 avahi_ipfs
556
 avahi_ipfs
508
 ipfs_bootstrap
557
 ipfs_bootstrap
558
+ipfs_publish
509
 #detect_tox_users
559
 #detect_tox_users
510
 avahi_remove_info
560
 avahi_remove_info
511
 
561