From 654ca169833e0876fcfbad2c5b35dac72ba24f2b Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 3 Sep 2016 15:36:44 +0100 Subject: [PATCH] ipfs on mesh --- src/freedombone-app-ipfs | 78 ++++++++++++++++----------------- src/freedombone-image-customise | 2 +- src/freedombone-image-mesh | 19 ++++++-- 3 files changed, 54 insertions(+), 45 deletions(-) diff --git a/src/freedombone-app-ipfs b/src/freedombone-app-ipfs index 5e002ab5..23463141 100755 --- a/src/freedombone-app-ipfs +++ b/src/freedombone-app-ipfs @@ -39,6 +39,7 @@ IPFS_N_VERSION='2.1.4' IPFS_JS_VERSION='0.14.3' IPFS_JS_RONIN_VERSION='0.3.11' IPFS_KEY_LENGTH=2048 +IPFS_GO_VERSION=0.4.2 function reconfigure_ipfs { echo -n '' @@ -378,50 +379,47 @@ function install_ipfs_js { } function mesh_install_ipfs_go { - chroot ${rootdir} apt-get -y install golang libpam0g-dev fuse + chroot ${rootdir} apt-get -y install libpam0g-dev fuse wget mesh_upgrade_golang - GOPATH=/home/go/go${GO_VERSION} + IPFS_ARCH= IPFS_PATH=/usr/bin - cat < ${rootdir}/root/install_ipfs_go.sh -export GOPATH=$GOPATH -export GOROOT=/home/go - -IPFS_PATH=$IPFS_PATH - -echo "go get -u ${IPFS_GO_REPO_BASE}/cmd/ipfs" -go get -u ${IPFS_GO_REPO_BASE}/cmd/ipfs -if [ ! "$?" = "0" ]; then - exit 8242 -fi - -if [ ! -d $GOPATH/src/$IPFS_GO_REPO_BASE ]; then - echo $'go get failed to get ipfs' - exit 63923 -fi - -cd \$GOPATH/src/${IPFS_GO_REPO_BASE} -git checkout $IPFS_COMMIT -b $IPFS_COMMIT -if [ ! "$?" = "0" ]; then - exit 735639 -fi - -make install -if [ ! "$?" = "0" ]; then - exit 6743895 -fi - -exit 0 -EOF - chroot ${rootdir} chmod +x /root/install_ipfs_go.sh - chroot ${rootdir} bash /root/install_ipfs_go.sh - if [ ! -f ${rootdir}$IPFS_PATH/ipfs ]; then - echo 'IPFS was not installed' - exit 73529 + if [ ! -d $rootdir$INSTALL_DIR/ipfs ]; then + mkdir -p $rootdir$INSTALL_DIR/ipfs + fi + cd $rootdir$INSTALL_DIR/ipfs + + if [[ $ARCHITECTURE == *"386" ]]; then + IPFS_ARCH=386 + fi + if [[ $ARCHITECTURE == *"amd64" ]]; then + IPFS_ARCH=amd64 + fi + if [[ $ARCHITECTURE == *"arm"* ]]; then + IPFS_ARCH=arm + fi + if [ ! $IPFS_ARCH ]; then + return + fi + + IPFS_FILE=go-ipfs_v${IPFS_GO_VERSION}_linux-${IPFS_ARCH}.tar.gz + wget https://ipfs.io/ipns/dist.ipfs.io/go-ipfs/v${IPFS_GO_VERSION}/${IPFS_FILE} + if [ ! -f $rootdir$INSTALL_DIR/ipfs/${IPFS_FILE} ]; then + echo $'IPFS package could not be downloaded' + exit 63725 + fi + tar -xzvf ${IPFS_FILE} + if [ ! -f $rootdir$INSTALL_DIR/ipfs/go-ipfs/ipfs ]; then + echo $"ipfs was not found in downloaded package" + exit 638235 + fi + chroot "$rootdir" cp $INSTALL_DIR/ipfs/go-ipfs/ipfs $IPFS_PATH + if [ ! -f $rootdir$IPFS_PATH/ipfs ]; then + echo $'IPFS was not installed' + exit 63722 fi - chroot ${rootdir} rm -f /root/install_ipfs_go.sh echo '[Unit]' > ${rootdir}/etc/systemd/system/ipfs.service echo 'Description=IPFS go daemon' >> ${rootdir}/etc/systemd/system/ipfs.service @@ -433,9 +431,9 @@ EOF echo "User=$MY_USERNAME" >> ${rootdir}/etc/systemd/system/ipfs.service echo "Group=$MY_USERNAME" >> ${rootdir}/etc/systemd/system/ipfs.service echo "WorkingDirectory=/home/$MY_USERNAME" >> ${rootdir}/etc/systemd/system/ipfs.service - echo "ExecStart=$IPFS_PATH/ipfs daemon --mount" >> ${rootdir}/etc/systemd/system/ipfs.service + echo "ExecStart=$IPFS_PATH/ipfs daemon" >> ${rootdir}/etc/systemd/system/ipfs.service echo 'Restart=on-failure' >> ${rootdir}/etc/systemd/system/ipfs.service - echo "Environment=\"USER=$MY_USERNAME\" \"HOME=/home/$MY_USERNAME\" \"GOPATH=$GOPATH\"" >> ${rootdir}/etc/systemd/system/ipfs.service + echo "Environment=\"USER=$MY_USERNAME\" \"HOME=/home/$MY_USERNAME\" \"GOPATH=/home/go/go${GO_VERSION}\"" >> ${rootdir}/etc/systemd/system/ipfs.service echo '' >> ${rootdir}/etc/systemd/system/ipfs.service echo '[Install]' >> ${rootdir}/etc/systemd/system/ipfs.service echo 'WantedBy=multi-user.target' >> ${rootdir}/etc/systemd/system/ipfs.service diff --git a/src/freedombone-image-customise b/src/freedombone-image-customise index e68dddcd..568d6f71 100755 --- a/src/freedombone-image-customise +++ b/src/freedombone-image-customise @@ -557,7 +557,7 @@ initialise_mesh() { install_tomb #install_tahoelafs #install_librevault - #install_ipfs + install_ipfs install_tox install_web_server if [ $ENABLE_ZERONET ]; then diff --git a/src/freedombone-image-mesh b/src/freedombone-image-mesh index c9fafe32..cb26d077 100755 --- a/src/freedombone-image-mesh +++ b/src/freedombone-image-mesh @@ -730,10 +730,6 @@ function setup_ipfs { rm -rf /home/$MY_USERNAME/.ipfs fi - if [ -f /home/git/gvm/bin/gvm ]; then - /home/git/gvm/bin/gvm use go${GO_VERSION} --default - fi - su -c "$IPFS_COMMAND init -b $IPFS_KEY_LENGTH" - $MY_USERNAME if [ ! -d /home/$MY_USERNAME/.ipfs ]; then echo "IPFS could not be initialised for user $MY_USERNAME" >> $INSTALL_LOG @@ -754,6 +750,21 @@ function setup_ipfs { return fi + # directories to mount to + if [ ! -d /ipfs ]; then + mkdir /ipfs + mkdir /ipns + chown $MY_USERNAME:$MY_USERNAME /ipfs + chown $MY_USERNAME:$MY_USERNAME /ipns + fi + + if [ -f /etc/fuse.conf ]; then + chown $MY_USERNAME:$MY_USERNAME /etc/fuse.conf + fi + if [ -f /dev/fuse ]; then + chown $MY_USERNAME:$MY_USERNAME /dev/fuse + fi + # TODO in avahi service for ipfs replace IPFS_PEER_ID echo 'IPFS installed with ID $IPFS_PEER_ID' >> $INSTALL_LOG