瀏覽代碼

ipfs mesh implementation

Bob Mottram 8 年之前
父節點
當前提交
1d994359ec
沒有帳戶連結到提交者的電子郵件
共有 3 個檔案被更改,包括 99 行新增0 行删除
  1. 67
    0
      src/freedombone-app-ipfs
  2. 1
    0
      src/freedombone-image-customise
  3. 31
    0
      src/freedombone-image-mesh

+ 67
- 0
src/freedombone-app-ipfs 查看文件

201
     echo 'configure_firewall_for_ipfs' >> $COMPLETION_FILE
201
     echo 'configure_firewall_for_ipfs' >> $COMPLETION_FILE
202
 }
202
 }
203
 
203
 
204
+function mesh_install_ipfs_js {
205
+    if grep -Fxq "mesh_install_ipfs_js" $COMPLETION_FILE; then
206
+        return
207
+    fi
208
+
209
+    chroot ${rootdir} apt-get -y install npm
210
+    chroot ${rootdir} apt-get -y install libpam0g-dev fuse
211
+
212
+    chroot ${rootdir} npm cache clean -f
213
+    chroot ${rootdir} npm install -g n
214
+    chroot ${rootdir} n ${IPFS_NODE_VERSION}
215
+    chroot ${rootdir} npm install ronin@${IPFS_JS_RONIN_VERSION} --global
216
+    chroot ${rootdir} npm install ipfs@${IPFS_JS_VERSION} --global
217
+
218
+    IPFS_PATH=/usr/local/bin
219
+
220
+    if [ ! -f ${rootdir}$IPFS_PATH/jsipfs ]; then
221
+        exit 637292
222
+    fi
223
+
224
+    # directories to mount to
225
+    if [ ! -d ${rootdir}/ipfs ]; then
226
+        chroot ${rootdir} mkdir /ipfs
227
+        chroot ${rootdir} mkdir /ipns
228
+        chroot ${rootdir} chown $MY_USERNAME:$MY_USERNAME /ipfs
229
+        chroot ${rootdir} chown $MY_USERNAME:$MY_USERNAME /ipns
230
+    fi
231
+
232
+    if [ -f ${rootdir}/etc/fuse.conf ]; then
233
+        chroot ${rootdir} chown $MY_USERNAME:$MY_USERNAME /etc/fuse.conf
234
+    fi
235
+    if [ -f ${rootdir}/dev/fuse ]; then
236
+        chroot ${rootdir} chown $MY_USERNAME:$MY_USERNAME /dev/fuse
237
+    fi
238
+
239
+    IPFS_DAEMON_NAME=ipfs
240
+    IPFS_DAEMON_FILE=${rootdir}/etc/systemd/system/${IPFS_DAEMON_NAME}.service
241
+    echo '[Unit]' > $IPFS_DAEMON_FILE
242
+    echo 'Description=IPFS javascript daemon' >> $IPFS_DAEMON_FILE
243
+    echo 'After=syslog.target' >> $IPFS_DAEMON_FILE
244
+    echo 'After=network.target' >> $IPFS_DAEMON_FILE
245
+    echo '' >> $IPFS_DAEMON_FILE
246
+    echo '[Service]' >> $IPFS_DAEMON_FILE
247
+    echo 'Type=simple' >> $IPFS_DAEMON_FILE
248
+    echo "User=$MY_USERNAME" >> $IPFS_DAEMON_FILE
249
+    echo "Group=$MY_USERNAME" >> $IPFS_DAEMON_FILE
250
+    echo "WorkingDirectory=/home/$MY_USERNAME" >> $IPFS_DAEMON_FILE
251
+    echo "ExecStart=${IPFS_PATH}/jsipfs daemon --mount" >> $IPFS_DAEMON_FILE
252
+    echo 'Restart=on-failure' >> $IPFS_DAEMON_FILE
253
+    echo "Environment=\"USER=$MY_USERNAME\" \"HOME=/home/$MY_USERNAME\"" >> $IPFS_DAEMON_FILE
254
+    echo '' >> $IPFS_DAEMON_FILE
255
+    echo '[Install]' >> $IPFS_DAEMON_FILE
256
+    echo 'WantedBy=multi-user.target' >> $IPFS_DAEMON_FILE
257
+
258
+    chroot ${rootdir} systemctl enable ${IPFS_DAEMON_NAME}
259
+    chroot ${rootdir} systemctl daemon-reload
260
+
261
+    function_check create_avahi_service
262
+    create_avahi_service ipfs "ipfs" udp $IPFS_PORT "IPFS_PEER_ID"
263
+
264
+    echo 'mesh install_ipfs_js' >> $COMPLETION_FILE
265
+}
266
+
204
 function install_ipfs_js {
267
 function install_ipfs_js {
268
+    if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
269
+        mesh_install_ipfs_js
270
+        return
271
+    fi
205
     if grep -Fxq "install_ipfs_js" $COMPLETION_FILE; then
272
     if grep -Fxq "install_ipfs_js" $COMPLETION_FILE; then
206
         return
273
         return
207
     fi
274
     fi

+ 1
- 0
src/freedombone-image-customise 查看文件

550
     install_tomb
550
     install_tomb
551
     install_tox
551
     install_tox
552
     install_web_server
552
     install_web_server
553
+    install_ipfs
553
     if [ $ENABLE_ZERONET ]; then
554
     if [ $ENABLE_ZERONET ]; then
554
         install_zeronet
555
         install_zeronet
555
     fi
556
     fi

+ 31
- 0
src/freedombone-image-mesh 查看文件

723
     fi
723
     fi
724
 }
724
 }
725
 
725
 
726
+function setup_ipfs {
727
+    IPFS_PATH=/usr/local/bin
728
+    IPFS_KEY_LENGTH=2048
729
+
730
+    su -c "$IPFS_PATH/jsipfs init -b $IPFS_KEY_LENGTH" - $MY_USERNAME
731
+    if [ ! -d ${rootdir}/home/$MY_USERNAME/.ipfs ]; then
732
+        echo "IPFS could not be initialised for user $MY_USERNAME" >> $INSTALL_LOG
733
+        exit 7358
734
+    fi
735
+
736
+    TEMP_IPFS_ID=/tmp/ipfsid
737
+    su -c "echo $($IPFS_PATH/jsipfs id | grep '\"ID\":' | awk -F '\"' '{print $4}') > $TEMP_IPFS_ID" - $MY_USERNAME
738
+    if [ ! -f $TEMP_IPFS_ID ]; then
739
+        echo 'No IPFS identity was created' >> $INSTALL_LOG
740
+        exit 37895
741
+    fi
742
+
743
+    IPFS_PEER_ID=$(cat $TEMP_IPFS_ID)
744
+    if [ ${#IPFS_PEER_ID} -lt 10 ]; then
745
+        echo 'Invalid IPFS peer ID' >> $INSTALL_LOG
746
+        echo "$IPFS_PEER_ID" >> $INSTALL_LOG
747
+        exit 74782
748
+    fi
749
+
750
+    # TODO in avahi service for ipfs replace IPFS_PEER_ID
751
+
752
+    rm $TEMP_IPFS_ID
753
+    echo 'IPFS installed with ID $IPFS_PEER_ID' >> $INSTALL_LOG
754
+}
755
+
726
 # whether to reset the identity
756
 # whether to reset the identity
727
 set_new_identity=
757
 set_new_identity=
728
 if [ $2 ]; then
758
 if [ $2 ]; then
778
     fi
808
     fi
779
     configure_toxcore
809
     configure_toxcore
780
     create_tox_user
810
     create_tox_user
811
+    setup_ipfs
781
     mesh_amnesic
812
     mesh_amnesic
782
 
813
 
783
     if [ ! -f $MESH_AMNESIC ]; then
814
     if [ ! -f $MESH_AMNESIC ]; then