ipfs mesh implementation

This commit is contained in:
Bob Mottram 2016-08-12 13:32:23 +01:00
parent 2f18dec9a3
commit 1d994359ec
No known key found for this signature in database
GPG Key ID: 0452CC7CEA982E38
3 changed files with 99 additions and 0 deletions

View File

@ -201,7 +201,74 @@ function configure_firewall_for_ipfs {
echo 'configure_firewall_for_ipfs' >> $COMPLETION_FILE
}
function mesh_install_ipfs_js {
if grep -Fxq "mesh_install_ipfs_js" $COMPLETION_FILE; then
return
fi
chroot ${rootdir} apt-get -y install npm
chroot ${rootdir} apt-get -y install libpam0g-dev fuse
chroot ${rootdir} npm cache clean -f
chroot ${rootdir} npm install -g n
chroot ${rootdir} n ${IPFS_NODE_VERSION}
chroot ${rootdir} npm install ronin@${IPFS_JS_RONIN_VERSION} --global
chroot ${rootdir} npm install ipfs@${IPFS_JS_VERSION} --global
IPFS_PATH=/usr/local/bin
if [ ! -f ${rootdir}$IPFS_PATH/jsipfs ]; then
exit 637292
fi
# directories to mount to
if [ ! -d ${rootdir}/ipfs ]; then
chroot ${rootdir} mkdir /ipfs
chroot ${rootdir} mkdir /ipns
chroot ${rootdir} chown $MY_USERNAME:$MY_USERNAME /ipfs
chroot ${rootdir} chown $MY_USERNAME:$MY_USERNAME /ipns
fi
if [ -f ${rootdir}/etc/fuse.conf ]; then
chroot ${rootdir} chown $MY_USERNAME:$MY_USERNAME /etc/fuse.conf
fi
if [ -f ${rootdir}/dev/fuse ]; then
chroot ${rootdir} chown $MY_USERNAME:$MY_USERNAME /dev/fuse
fi
IPFS_DAEMON_NAME=ipfs
IPFS_DAEMON_FILE=${rootdir}/etc/systemd/system/${IPFS_DAEMON_NAME}.service
echo '[Unit]' > $IPFS_DAEMON_FILE
echo 'Description=IPFS javascript daemon' >> $IPFS_DAEMON_FILE
echo 'After=syslog.target' >> $IPFS_DAEMON_FILE
echo 'After=network.target' >> $IPFS_DAEMON_FILE
echo '' >> $IPFS_DAEMON_FILE
echo '[Service]' >> $IPFS_DAEMON_FILE
echo 'Type=simple' >> $IPFS_DAEMON_FILE
echo "User=$MY_USERNAME" >> $IPFS_DAEMON_FILE
echo "Group=$MY_USERNAME" >> $IPFS_DAEMON_FILE
echo "WorkingDirectory=/home/$MY_USERNAME" >> $IPFS_DAEMON_FILE
echo "ExecStart=${IPFS_PATH}/jsipfs daemon --mount" >> $IPFS_DAEMON_FILE
echo 'Restart=on-failure' >> $IPFS_DAEMON_FILE
echo "Environment=\"USER=$MY_USERNAME\" \"HOME=/home/$MY_USERNAME\"" >> $IPFS_DAEMON_FILE
echo '' >> $IPFS_DAEMON_FILE
echo '[Install]' >> $IPFS_DAEMON_FILE
echo 'WantedBy=multi-user.target' >> $IPFS_DAEMON_FILE
chroot ${rootdir} systemctl enable ${IPFS_DAEMON_NAME}
chroot ${rootdir} systemctl daemon-reload
function_check create_avahi_service
create_avahi_service ipfs "ipfs" udp $IPFS_PORT "IPFS_PEER_ID"
echo 'mesh install_ipfs_js' >> $COMPLETION_FILE
}
function install_ipfs_js {
if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
mesh_install_ipfs_js
return
fi
if grep -Fxq "install_ipfs_js" $COMPLETION_FILE; then
return
fi

View File

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

View File

@ -723,6 +723,36 @@ function setup_amnesic_data {
fi
}
function setup_ipfs {
IPFS_PATH=/usr/local/bin
IPFS_KEY_LENGTH=2048
su -c "$IPFS_PATH/jsipfs init -b $IPFS_KEY_LENGTH" - $MY_USERNAME
if [ ! -d ${rootdir}/home/$MY_USERNAME/.ipfs ]; then
echo "IPFS could not be initialised for user $MY_USERNAME" >> $INSTALL_LOG
exit 7358
fi
TEMP_IPFS_ID=/tmp/ipfsid
su -c "echo $($IPFS_PATH/jsipfs id | grep '\"ID\":' | awk -F '\"' '{print $4}') > $TEMP_IPFS_ID" - $MY_USERNAME
if [ ! -f $TEMP_IPFS_ID ]; then
echo 'No IPFS identity was created' >> $INSTALL_LOG
exit 37895
fi
IPFS_PEER_ID=$(cat $TEMP_IPFS_ID)
if [ ${#IPFS_PEER_ID} -lt 10 ]; then
echo 'Invalid IPFS peer ID' >> $INSTALL_LOG
echo "$IPFS_PEER_ID" >> $INSTALL_LOG
exit 74782
fi
# TODO in avahi service for ipfs replace IPFS_PEER_ID
rm $TEMP_IPFS_ID
echo 'IPFS installed with ID $IPFS_PEER_ID' >> $INSTALL_LOG
}
# whether to reset the identity
set_new_identity=
if [ $2 ]; then
@ -778,6 +808,7 @@ if [ -f $MESH_INSTALL_SETUP ]; then
fi
configure_toxcore
create_tox_user
setup_ipfs
mesh_amnesic
if [ ! -f $MESH_AMNESIC ]; then