How to build your own binary instead of downloading Docker images

In case you’re building your own binary instead of downloading ugly Docker images, here’s my auto-update script:

#!/bin/bash

vercomp () {
    if [[ $1 == $2 ]]; then return 0; fi
    local IFS=.
    local i ver1=($1) ver2=($2)
    for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do ver1[i]=0; done
    for ((i=0; i<${#ver1[@]}; i++)); do
        if [[ -z ${ver2[i]} ]]; then ver2[i]=0; fi
        if ((10#${ver1[i]} > 10#${ver2[i]})); then return 11; fi
        if ((10#${ver1[i]} < 10#${ver2[i]})); then return 12; fi
    done
    return 0
}

set -e
cd /usr/local/src/storj
# set -x
V="v$(curl -s https://version.storj.io | jq -r '.processes."storagenode-updater"'.suggested.version)"
if test "$V" = "v"; then echo Bad Version from STORJ 2>&1; exit 1; fi
N=$(/usr/local/bin/storagenode --log.level WARN version | sed -ne s/Version:.//p)
set +e
vercomp "${N:1:99}" "${V:1:99}"  # skip the initial 'v'
case $? in
	(0) exit 0 ;;
	(11) echo "? Want $V but already on $N ?" >&2; exit 1 ;;
	(12) : ;;
    (*) echo "Version comparison error: '$N' vs '$V'" >&2; exit 1 ;;
esac
set -e
echo "Building $V to replace $N"
git fetch --tags
git checkout $V

go build -ldflags " -s -w -X storj.io/storj/internal/version.buildTimestamp=$(date +%s) -X storj.io/storj/internal/version.buildCommitHash=$(git rev-parse HEAD) -X storj.io/storj/internal/version.buildVersion=$V -X storj.io/storj/internal/version.buildRelease=true" -tags=grpc -o /usr/local/tmp storj.io/storj/cmd/storagenode
cd /usr/local/tmp; mv storagenode ../bin
echo "Done. Restarting node."

killall -INT storagenode

The node itself is on a systemd script that auto-restarts it two seconds after it dies; SIGINT shuts the node down gracefully.
Problem free for me, so far.

4 Likes

Hi, I’m really interested to use this but not sure I have the correct skills… are you able to offer any support. My NAS doesnt have the container APP so i can’t run docker which then means I can’t install the Storj APP. Is this something you could help with ?

1 Like