浏览代码

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,7 +201,74 @@ function configure_firewall_for_ipfs {
201 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 267
 function install_ipfs_js {
268
+    if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
269
+        mesh_install_ipfs_js
270
+        return
271
+    fi
205 272
     if grep -Fxq "install_ipfs_js" $COMPLETION_FILE; then
206 273
         return
207 274
     fi

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

@@ -550,6 +550,7 @@ initialise_mesh() {
550 550
     install_tomb
551 551
     install_tox
552 552
     install_web_server
553
+    install_ipfs
553 554
     if [ $ENABLE_ZERONET ]; then
554 555
         install_zeronet
555 556
     fi

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

@@ -723,6 +723,36 @@ function setup_amnesic_data {
723 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 756
 # whether to reset the identity
727 757
 set_new_identity=
728 758
 if [ $2 ]; then
@@ -778,6 +808,7 @@ if [ -f $MESH_INSTALL_SETUP ]; then
778 808
     fi
779 809
     configure_toxcore
780 810
     create_tox_user
811
+    setup_ipfs
781 812
     mesh_amnesic
782 813
 
783 814
     if [ ! -f $MESH_AMNESIC ]; then