Improve ipfs installation on mesh clients

This commit is contained in:
Bob Mottram 2016-09-02 17:17:44 +01:00
parent e2c194bb23
commit 3ea1b03436
No known key found for this signature in database
GPG Key ID: 0452CC7CEA982E38
3 changed files with 123 additions and 136 deletions

View File

@ -32,7 +32,7 @@ VARIANTS='mesh'
IPFS_GO_REPO_BASE="github.com/ipfs/go-ipfs" IPFS_GO_REPO_BASE="github.com/ipfs/go-ipfs"
IPFS_GO_REPO="https://${IPFS_GO_REPO_BASE}" IPFS_GO_REPO="https://${IPFS_GO_REPO_BASE}"
IPFS_COMMIT='20b06a4cbce8884f5b194da6e98cb11f2c77f166' IPFS_COMMIT='6fdfaaf6e4783ae1be7b348e7a6bc0640982c7df'
IPFS_PORT=4001 IPFS_PORT=4001
IPFS_NODE_VERSION='6.2.2' IPFS_NODE_VERSION='6.2.2'
IPFS_N_VERSION='2.1.4' IPFS_N_VERSION='2.1.4'
@ -382,46 +382,14 @@ function mesh_install_ipfs_go {
mesh_upgrade_golang mesh_upgrade_golang
GOPATH=/home/git/gvm/pkgsets/go${GO_VERSION}/global GOPATH=/home/go/go${GO_VERSION}
IPFS_PATH=/usr/bin
cat <<EOF > ${rootdir}/root/install_ipfs_go.sh cat <<EOF > ${rootdir}/root/install_ipfs_go.sh
#!/bin/bash
export GOPATH=$GOPATH export GOPATH=$GOPATH
export GOROOT=/home/go
if [ ${#GOPATH} -lt 1 ]; then IPFS_PATH=$IPFS_PATH
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
echo "go get -u ${IPFS_GO_REPO_BASE}/cmd/ipfs" echo "go get -u ${IPFS_GO_REPO_BASE}/cmd/ipfs"
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 exit 63923
fi fi
cd \$GOPATH/src/$IPFS_GO_REPO_BASE cd \$GOPATH/src/${IPFS_GO_REPO_BASE}
git checkout $IPFS_COMMIT -b $IPFS_COMMIT git checkout $IPFS_COMMIT -b $IPFS_COMMIT
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
exit 735639 exit 735639
fi fi
make install
if [ ! "$?" = "0" ]; then
exit 6743895
fi
exit 0 exit 0
EOF EOF
chroot ${rootdir} chmod +x /root/install_ipfs_go.sh chroot ${rootdir} chmod +x /root/install_ipfs_go.sh
chroot ${rootdir} /root/install_ipfs_go.sh chroot ${rootdir} bash /root/install_ipfs_go.sh
if [ ! "$?" = "0" ]; then if [ ! -f ${rootdir}$IPFS_PATH/ipfs ]; then
echo $'Failed to install ipfs go' echo 'IPFS was not installed'
cat ${rootdir}/root/install_ipfs_go.sh exit 73529
rm -f ${rootdir}/root/install_ipfs_go.sh
exit 365728
fi fi
chroot ${rootdir} rm -f /root/install_ipfs_go.sh 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 "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 --mount" >> ${rootdir}/etc/systemd/system/ipfs.service
echo 'Restart=on-failure' >> ${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 '' >> ${rootdir}/etc/systemd/system/ipfs.service
echo '[Install]' >> ${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 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 sed -i "s/ipfs commit.*/ipfs commit:$IPFS_COMMIT/g" $COMPLETION_FILE
fi fi
make install
if [ ! "$?" = "0" ]; then
exit 547242
fi
# initialise # initialise
su -c "$IPFS_PATH/ipfs init -b 4096" - $MY_USERNAME su -c "$IPFS_PATH/ipfs init -b 4096" - $MY_USERNAME
if [ ! -d /home/$MY_USERNAME/.ipfs ]; then if [ ! -d /home/$MY_USERNAME/.ipfs ]; then

View File

@ -44,6 +44,8 @@ DEFAULT_USERNAME=fbone
ZERONET_URL='http://127.0.0.1:43110' ZERONET_URL='http://127.0.0.1:43110'
ZERONET_PORT=15441 ZERONET_PORT=15441
GO_VERSION=1.7
TOX_NODES= TOX_NODES=
#TOX_NODES=( #TOX_NODES=(
# '192.254.75.102,2607:5600:284::2,33445,951C88B7E75C867418ACDB5D273821372BB5BD652740BCDF623A4FA293E75D2F,Tox RELENG,US' # '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_KEY_LENGTH=2048
IPFS_COMMAND=$IPFS_PATH/ipfs 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 su -c "$IPFS_COMMAND init -b $IPFS_KEY_LENGTH" - $MY_USERNAME
if [ ! -d /home/$MY_USERNAME/.ipfs ]; then if [ ! -d /home/$MY_USERNAME/.ipfs ]; then
echo "IPFS could not be initialised for user $MY_USERNAME" >> $INSTALL_LOG echo "IPFS could not be initialised for user $MY_USERNAME" >> $INSTALL_LOG

View File

@ -32,8 +32,9 @@
# before getting to the version we want # before getting to the version we want
GO_INTERMEDIATE_VERSION=1.4.2 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" GO_PACKAGE_MANAGER_REPO="https://github.com/gpmgo/gopm"
GVM_HOME=/home/git/gvm GVM_HOME=/home/git/gvm
GVM_REPO="https://github.com/moovweb/gvm" GVM_REPO="https://github.com/moovweb/gvm"
@ -62,117 +63,65 @@ function select_go_version {
systemctl set-environment GOPATH=$GOPATH 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 <<EOF > ${rootdir}/root/upgrade_golang.sh cat <<EOF > ${rootdir}/root/upgrade_golang.sh
#!/bin/bash #!/bin/bash
export GVM_ROOT=$GVM_HOME
apt-get -y install build-essential libc6-dev apt-get -y install build-essential libc6-dev
apt-get -y install gcc-multilib g++-multilib make apt-get -y install gcc-multilib g++-multilib make
apt-get -y install curl git mercurial binutils bison 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 if [ -d /home/go/Maildir ]; then
rm -rf /home/go/Maildir
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
fi fi
if [ ! -d /home/git ]; then export GOROOT=/home/go
adduser --disabled-login --gecos 'Gogs' git export GOPATH=/home/go/go${GO_INTERMEDIATE_VERSION}
fi
if [ -d /home/git/Maildir ]; then cd /home/go/go${GO_INTERMEDIATE_VERSION}/src
rm -rf /home/git/Maildir ./all.bash
if [ ! -f /home/go/go${GO_INTERMEDIATE_VERSION}/bin/go ]; then
exit 63722
fi fi
./binscripts/gvm-installer master /home/git export GOROOT_BOOTSTRAP=/home/go/go${GO_INTERMEDIATE_VERSION}
if [ ! -d $GVM_HOME ]; then cd /home/go/go${GO_VERSION}/src
echo $'Unable to install gvm' ./all.bash
exit 83537 if [ ! -f /home/go/go${GO_VERSION}/bin/go ]; then
exit 528352
fi fi
[[ -s "$GVM_HOME/scripts/gvm" ]] && source "$GVM_HOME/scripts/gvm" chown -R go:go /home/go
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
cd $GVM_HOME/bin export GOPATH=/home/go/go${GO_VERSION}
export GOROOT=/home/go
$GVM_HOME/bin/gvm install go${GO_INTERMEDIATE_VERSION} echo "export GOPATH=/home/go/go${GO_VERSION}" >> /home/go/.bashrc
if [ ! "\$?" = "0" ]; then echo "export GOPATH=/home/go/go${GO_VERSION}" >> ~/.bashrc
echo $"Unable to install intermediate go version ${GO_INTERMEDIATE_VERSION}" echo "export GOROOT=/home/go" >> /home/go/.bashrc
if [ -f $GVM_HOME/logs/go-go${GO_INTERMEDIATE_VERSION}-compile.log ]; then echo "export GOROOT=/home/go" >> ~/.bashrc
cat $GVM_HOME/logs/go-go${GO_INTERMEDIATE_VERSION}-compile.log echo "systemctl set-environment GOPATH=\$GOPATH" >> ~/.bashrc
fi echo "systemctl set-environment GOROOT=\$GOROOT" >> ~/.bashrc
exit 352872 echo "systemctl set-environment GOPATH=\$GOPATH" >> /home/go/.bashrc
fi echo "systemctl set-environment GOROOT=\$GOROOT" >> /home/go/.bashrc
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
systemctl set-environment GOPATH=\$GOPATH systemctl set-environment GOPATH=\$GOPATH
systemctl set-environment GOROOT=\$GOROOT
exit 0 exit 0
EOF EOF
chroot ${rootdir} chmod +x /root/upgrade_golang.sh chroot ${rootdir} chmod +x /root/upgrade_golang.sh
chroot ${rootdir} /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' echo $'Failed to upgrade golang'
cat ${rootdir}/root/upgrade_golang.sh cat ${rootdir}/root/upgrade_golang.sh
rm -f ${rootdir}/root/upgrade_golang.sh rm -f ${rootdir}/root/upgrade_golang.sh
@ -181,6 +130,55 @@ EOF
rm -f ${rootdir}/root/upgrade_golang.sh 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 { 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 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 return
@ -247,6 +245,9 @@ function upgrade_golang {
if ! grep -q "export GVM_ROOT=" ~/.bashrc; then if ! grep -q "export GVM_ROOT=" ~/.bashrc; then
echo "export GVM_ROOT=$GVM_ROOT" >> ~/.bashrc echo "export GVM_ROOT=$GVM_ROOT" >> ~/.bashrc
fi fi
if ! grep -q 'PATH=$PATH:$GVM_ROOT/bin' ~/.bashrc; then
echo 'PATH=$PATH:$GVM_ROOT/bin' >> ~/.bashrc
fi
export GOROOT_BOOTSTRAP=$GOROOT export GOROOT_BOOTSTRAP=$GOROOT