From 3ea1b03436c38b94e66f5c03fba9fedd8321b1e5 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 2 Sep 2016 17:17:44 +0100 Subject: [PATCH] Improve ipfs installation on mesh clients --- src/freedombone-app-ipfs | 66 +++++-------- src/freedombone-image-mesh | 10 ++ src/freedombone-utils-go | 183 +++++++++++++++++++------------------ 3 files changed, 123 insertions(+), 136 deletions(-) diff --git a/src/freedombone-app-ipfs b/src/freedombone-app-ipfs index 239d8e8f..5e002ab5 100755 --- a/src/freedombone-app-ipfs +++ b/src/freedombone-app-ipfs @@ -32,7 +32,7 @@ VARIANTS='mesh' IPFS_GO_REPO_BASE="github.com/ipfs/go-ipfs" IPFS_GO_REPO="https://${IPFS_GO_REPO_BASE}" -IPFS_COMMIT='20b06a4cbce8884f5b194da6e98cb11f2c77f166' +IPFS_COMMIT='6fdfaaf6e4783ae1be7b348e7a6bc0640982c7df' IPFS_PORT=4001 IPFS_NODE_VERSION='6.2.2' IPFS_N_VERSION='2.1.4' @@ -382,46 +382,14 @@ function mesh_install_ipfs_go { mesh_upgrade_golang - GOPATH=/home/git/gvm/pkgsets/go${GO_VERSION}/global + GOPATH=/home/go/go${GO_VERSION} + IPFS_PATH=/usr/bin cat < ${rootdir}/root/install_ipfs_go.sh -#!/bin/bash - export GOPATH=$GOPATH +export GOROOT=/home/go -if [ ${#GOPATH} -lt 1 ]; then - echo $'GOPATH was not set' - exit 62925 -fi - -if [ ! -d /home/git ]; then - adduser --disabled-login --gecos 'Gogs' git - - # install Go - if ! grep -q "export GOPATH=" ~/.bashrc; then - echo "export GOPATH=\$GOPATH" >> ~/.bashrc - else - sed -i "s|export GOPATH=.*|export GOPATH=\$GOPATH|g" ~/.bashrc - fi - systemctl set-environment GOPATH=\$GOPATH - if ! grep -q "systemctl set-environment GOPATH=" ~/.bashrc; then - echo "systemctl set-environment GOPATH=\$GOPATH" >> ~/.bashrc - else - sed -i "s|systemctl set-environment GOPATH=.*|systemctl set-environment GOPATH=\$GOPATH|g" ~/.bashrc - fi - if [ ! -d \$GOPATH ]; then - mkdir -p \$GOPATH - fi -fi - -IPFS_PATH=\$GOPATH/bin -export PATH="\$GOPATH/bin:\$PATH:" -echo 'export PATH="\$GOPATH/bin:\$PATH:";' >> /home/$MY_USERNAME/.bashrc - -if grep -q 'GOPATH/bin' ~/.bashrc; then - sed -i "s|systemctl set-environment GOPATH=.*|systemctl set-environment GOPATH=\$GOPATH|g" ~/.bashrc -fi -chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.bashrc +IPFS_PATH=$IPFS_PATH echo "go get -u ${IPFS_GO_REPO_BASE}/cmd/ipfs" go get -u ${IPFS_GO_REPO_BASE}/cmd/ipfs @@ -434,21 +402,24 @@ if [ ! -d $GOPATH/src/$IPFS_GO_REPO_BASE ]; then exit 63923 fi -cd \$GOPATH/src/$IPFS_GO_REPO_BASE +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} /root/install_ipfs_go.sh - if [ ! "$?" = "0" ]; then - echo $'Failed to install ipfs go' - cat ${rootdir}/root/install_ipfs_go.sh - rm -f ${rootdir}/root/install_ipfs_go.sh - exit 365728 + chroot ${rootdir} bash /root/install_ipfs_go.sh + if [ ! -f ${rootdir}$IPFS_PATH/ipfs ]; then + echo 'IPFS was not installed' + exit 73529 fi chroot ${rootdir} rm -f /root/install_ipfs_go.sh @@ -464,7 +435,7 @@ EOF 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 'Restart=on-failure' >> ${rootdir}/etc/systemd/system/ipfs.service - echo "Environment=\"USER=$MY_USERNAME\" \"HOME=/home/$MY_USERNAME\" \"GOPATH=$GOPATH\" \"GVM_ROOT=$GVM_HOME\"" >> ${rootdir}/etc/systemd/system/ipfs.service + echo "Environment=\"USER=$MY_USERNAME\" \"HOME=/home/$MY_USERNAME\" \"GOPATH=$GOPATH\"" >> ${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 @@ -546,6 +517,11 @@ function install_ipfs_go { sed -i "s/ipfs commit.*/ipfs commit:$IPFS_COMMIT/g" $COMPLETION_FILE fi + make install + if [ ! "$?" = "0" ]; then + exit 547242 + fi + # initialise su -c "$IPFS_PATH/ipfs init -b 4096" - $MY_USERNAME if [ ! -d /home/$MY_USERNAME/.ipfs ]; then diff --git a/src/freedombone-image-mesh b/src/freedombone-image-mesh index 3ef0729f..c9fafe32 100755 --- a/src/freedombone-image-mesh +++ b/src/freedombone-image-mesh @@ -44,6 +44,8 @@ DEFAULT_USERNAME=fbone ZERONET_URL='http://127.0.0.1:43110' ZERONET_PORT=15441 +GO_VERSION=1.7 + TOX_NODES= #TOX_NODES=( # '192.254.75.102,2607:5600:284::2,33445,951C88B7E75C867418ACDB5D273821372BB5BD652740BCDF623A4FA293E75D2F,Tox RELENG,US' @@ -724,6 +726,14 @@ function setup_ipfs { IPFS_KEY_LENGTH=2048 IPFS_COMMAND=$IPFS_PATH/ipfs + if [ -d /home/$MY_USERNAME/.ipfs ]; then + 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 diff --git a/src/freedombone-utils-go b/src/freedombone-utils-go index c803aa3d..dfec310c 100755 --- a/src/freedombone-utils-go +++ b/src/freedombone-utils-go @@ -32,8 +32,9 @@ # before getting to the version we want GO_INTERMEDIATE_VERSION=1.4.2 -GO_VERSION=1.5 +GO_VERSION=1.7 +GO_REPO="https://go.googlesource.com/go" GO_PACKAGE_MANAGER_REPO="https://github.com/gpmgo/gopm" GVM_HOME=/home/git/gvm GVM_REPO="https://github.com/moovweb/gvm" @@ -62,117 +63,65 @@ function select_go_version { systemctl set-environment GOPATH=$GOPATH } -function mesh_upgrade_golang { +function mesh_upgrade_golang_from_source { + chroot "$rootdir" adduser --disabled-login --gecos 'go' ipfs + + git clone $GO_REPO $rootdir/home/go/go${GO_VERSION} + cd $rootdir/home/go/go${GO_VERSION} + git checkout go${GO_VERSION} -b go${GO_VERSION} + + git clone $GO_REPO $rootdir/home/go/go${GO_INTERMEDIATE_VERSION} + cd $rootdir/home/go/go${GO_INTERMEDIATE_VERSION} + git checkout go${GO_INTERMEDIATE_VERSION} -b go${GO_INTERMEDIATE_VERSION} + cat < ${rootdir}/root/upgrade_golang.sh #!/bin/bash -export GVM_ROOT=$GVM_HOME - apt-get -y install build-essential libc6-dev apt-get -y install gcc-multilib g++-multilib make apt-get -y install curl git mercurial binutils bison -if [ ! -d $INSTALL_DIR ]; then - mkdir $INSTALL_DIR -fi -cd $INSTALL_DIR -git clone $GVM_REPO gvm - -cd $INSTALL_DIR/gvm -git checkout $GVM_COMMIT -b $GVM_COMMIT -if [ ! -f binscripts/gvm-installer ]; then - echo $'gvm installer not found' -fi -chmod +x binscripts/gvm-installer - -if [ -d /root/.gvm ]; then - rm -rf /root/.gvm -fi -if [ -d $GVM_HOME ]; then - rm -rf $GVM_HOME -fi -if ! grep -q "export GVM_ROOT=" ~/.bashrc; then - echo "export GVM_ROOT=$GVM_HOME" >> ~/.bashrc -else - sed -i "s|export GVM_ROOT=.*|export GVM_ROOT=$GVM_HOME|g" ~/.bashrc +if [ -d /home/go/Maildir ]; then + rm -rf /home/go/Maildir fi -if [ ! -d /home/git ]; then - adduser --disabled-login --gecos 'Gogs' git -fi -if [ -d /home/git/Maildir ]; then - rm -rf /home/git/Maildir +export GOROOT=/home/go +export GOPATH=/home/go/go${GO_INTERMEDIATE_VERSION} + +cd /home/go/go${GO_INTERMEDIATE_VERSION}/src +./all.bash +if [ ! -f /home/go/go${GO_INTERMEDIATE_VERSION}/bin/go ]; then + exit 63722 fi -./binscripts/gvm-installer master /home/git +export GOROOT_BOOTSTRAP=/home/go/go${GO_INTERMEDIATE_VERSION} -if [ ! -d $GVM_HOME ]; then - echo $'Unable to install gvm' - exit 83537 +cd /home/go/go${GO_VERSION}/src +./all.bash +if [ ! -f /home/go/go${GO_VERSION}/bin/go ]; then + exit 528352 fi -[[ -s "$GVM_HOME/scripts/gvm" ]] && source "$GVM_HOME/scripts/gvm" -if [ ! -f $GVM_HOME/bin/gvm ]; then - echo $'gvm was not installed' -fi -if ! grep -q "export GVM_ROOT=" ~/.bashrc; then - echo "export GVM_ROOT=$GVM_HOME" >> ~/.bashrc -fi +chown -R go:go /home/go -cd $GVM_HOME/bin - -$GVM_HOME/bin/gvm install go${GO_INTERMEDIATE_VERSION} -if [ ! "\$?" = "0" ]; then - echo $"Unable to install intermediate go version ${GO_INTERMEDIATE_VERSION}" - if [ -f $GVM_HOME/logs/go-go${GO_INTERMEDIATE_VERSION}-compile.log ]; then - cat $GVM_HOME/logs/go-go${GO_INTERMEDIATE_VERSION}-compile.log - fi - exit 352872 -fi - -export GOROOT_BOOTSTRAP=/home/git/gvm/gos/go${GO_INTERMEDIATE_VERSION} - -$GVM_HOME/bin/gvm install go${GO_VERSION} -if [ ! "\$?" = "0" ]; then - echo $"Unable to install go version ${GO_VERSION}" - if [ -f $GVM_HOME/logs/go-go${GO_VERSION}-compile.log ]; then - cat $GVM_HOME/logs/go-go${GO_VERSION}-compile.log - fi - exit 529252 -fi - -chown -R git:git $GVM_HOME - -if [ ! -d $GVM_HOME/bin ]; then - echo $'GVM was not installed' - exit 629532 -fi - -if ! grep -q "GVM_ROOT=" ~/.bashrc; then - echo "export GVM_ROOT=$GVM_HOME" >> ~/.bashrc -else - sed -i "s|export GVM_ROOT=.*|export GVM_ROOT=$GVM_HOME|g" ~/.bashrc -fi - -cd $GVM_HOME/bin -[[ -s "$GVM_HOME/scripts/gvm" ]] && source "$GVM_HOME/scripts/gvm" -#$GVM_HOME/bin/gvm use go${GO_VERSION} --default -#if [ ! "\$?" = "0" ]; then -# echo $"Unable to use go version ${GO_VERSION}" -# if [ -f $GVM_HOME/logs/go-go${GO_VERSION}-compile.log ]; then -# cat $GVM_HOME/logs/go-go${GO_VERSION}-compile.log -# fi -#fi - -echo "export GOPATH=/home/git/gvm/pkgsets/go${GO_VERSION}/global" >> ~/.bashrc -export GOPATH=/home/git/gvm/pkgsets/go${GO_VERSION}/global +export GOPATH=/home/go/go${GO_VERSION} +export GOROOT=/home/go +echo "export GOPATH=/home/go/go${GO_VERSION}" >> /home/go/.bashrc +echo "export GOPATH=/home/go/go${GO_VERSION}" >> ~/.bashrc +echo "export GOROOT=/home/go" >> /home/go/.bashrc +echo "export GOROOT=/home/go" >> ~/.bashrc +echo "systemctl set-environment GOPATH=\$GOPATH" >> ~/.bashrc +echo "systemctl set-environment GOROOT=\$GOROOT" >> ~/.bashrc +echo "systemctl set-environment GOPATH=\$GOPATH" >> /home/go/.bashrc +echo "systemctl set-environment GOROOT=\$GOROOT" >> /home/go/.bashrc systemctl set-environment GOPATH=\$GOPATH +systemctl set-environment GOROOT=\$GOROOT exit 0 EOF chroot ${rootdir} chmod +x /root/upgrade_golang.sh chroot ${rootdir} /root/upgrade_golang.sh - if [ ! "$?" = "0" ]; then + if [ ! -f ${rootdir}/home/go/go${GO_VERSION}/bin/go ]; then echo $'Failed to upgrade golang' cat ${rootdir}/root/upgrade_golang.sh rm -f ${rootdir}/root/upgrade_golang.sh @@ -181,6 +130,55 @@ EOF rm -f ${rootdir}/root/upgrade_golang.sh } +function mesh_upgrade_golang { + chroot "$rootdir" adduser --disabled-login --gecos 'go' go + + GOARCH= + if [[ $ARCHITECTURE == *"386" ]]; then + GOARCH=386 + fi + if [[ $ARCHITECTURE == *"amd64" ]]; then + GOARCH=amd64 + fi + if [[ $ARCHITECTURE == *"arm"* ]]; then + GOARCH=armv6l + fi + if [ ! $GOARCH ]; then + return + fi + + GO_SOURCE=https://storage.googleapis.com/golang/go${GO_VERSION}.linux-${GOARCH}.tar.gz + + if [ ! -d ${rootdir}${INSTALL_DIR} ]; then + chroot "$rootdir" mkdir -p ${INSTALL_DIR} + fi + cd ${rootdir}${INSTALL_DIR} + wget ${GO_SOURCE} + if [ ! -f ${rootdir}${INSTALL_DIR}/go${GO_VERSION}.linux-${GOARCH}.tar.gz ]; then + exit 26524 + fi + chroot "$rootdir" tar -C /home/go -xzf ${INSTALL_DIR}/go${GO_VERSION}.linux-${GOARCH}.tar.gz + if [ ! -d ${rootdir}/home/go/go/bin ]; then + echo 'Go binary not installed' + exit 763562 + fi + mv ${rootdir}/home/go/go ${rootdir}/home/go/go${GO_VERSION} + echo "export GOROOT=/home/go" >> $rootdir/root/.bashrc + echo "export GOROOT=/home/go" >> $rootdir/home/$MY_USERNAME/.bashrc + echo "export GOROOT=/home/go" >> $rootdir/home/go/.bashrc + + echo "export GOPATH=\$GOROOT/go${GO_VERSION}/bin" >> $rootdir/root/.bashrc + echo "export GOPATH=\$GOROOT/go${GO_VERSION}/bin" >> $rootdir/home/$MY_USERNAME/.bashrc + echo "export GOPATH=\$GOROOT/go${GO_VERSION}/bin" >> $rootdir/home/go/.bashrc + + echo 'export PATH=$PATH:$GOPATH' >> $rootdir/root/.bashrc + echo 'export PATH=$PATH:$GOPATH' >> $rootdir/home/$MY_USERNAME/.bashrc + echo 'export PATH=$PATH:$GOPATH' >> $rootdir/home/go/.bashrc + chroot "$rootdir" chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME + chroot "$rootdir" chown -R go:go /home/go + cp ${rootdir}/home/go/go${GO_VERSION}/bin/* ${rootdir}/usr/bin +} + function upgrade_golang { if [[ $SYSTEM_TYPE == "$VARIANT_WRITER" || $SYSTEM_TYPE == "$VARIANT_MAILBOX" || $SYSTEM_TYPE == "$VARIANT_CLOUD" || $SYSTEM_TYPE == "$VARIANT_SOCIAL" || $SYSTEM_TYPE == "$VARIANT_MEDIA" || $SYSTEM_TYPE == "$VARIANT_CHAT" || $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then return @@ -247,6 +245,9 @@ function upgrade_golang { if ! grep -q "export GVM_ROOT=" ~/.bashrc; then echo "export GVM_ROOT=$GVM_ROOT" >> ~/.bashrc fi + if ! grep -q 'PATH=$PATH:$GVM_ROOT/bin' ~/.bashrc; then + echo 'PATH=$PATH:$GVM_ROOT/bin' >> ~/.bashrc + fi export GOROOT_BOOTSTRAP=$GOROOT