如何自动升级到最新的 github 软件发布版本?

How to do auto upgrade to latest github software release version?

每次发布上传到url喜欢 https://github.com/ipfs/go-ipfs/releases/tag/v0.9.1

我的剧本是

#!/bin/bash
rm /home/ipfs/go-ipfs -rf
rm go-ipfs.tar.gz
curl -s  https://api.github.com/repos/ipfs/go-ipfs/releases/latest | grep linux-amd64.tar.gz\" | grep download  | sed 's/.*: \"//g' | sed 's/\"//g' | wget -i - -O /home/ipfs/go-ipfs.tar.gz
if test -f /home/ipfs/go-ipfs.tar.gz then
        tar -xf /home/ipfs/go-ipfs.tar.g
        newsize=$(wc -c <"/home/ipfs/go-ipfs/ipfs")
        cursize=$(wc -c <"/home/ipfs/ipfs")
        if [$newsize -ne $cursize]; then
                mv /home/ipfs/go-ipfs/ipfs /home/ipfs/ipfs
                chmod +x /home/ipfs/ipfs
                pkill ipfs
        fi
fi

但它有一个我无法修复的错误

解决方案是

#!/bin/bash

#remove old repo folder
rm /home/ipfs/go-ipfs -rf

#remove old tar.gz
rm go-ipfs.tar.gz

#try to download new
curl -s  https://api.github.com/repos/ipfs/go-ipfs/releases/latest | grep linux-amd64.tar.gz\" | grep download  | sed 's/.*: \"//g' | sed 's/\"//g' | wget -i - -O /home/ipfs/go-ipfs.tar.gz

#check file exists
if [ -f /home/ipfs/go-ipfs.tar.gz ]; then
        #unpack tar gz
        tar -xf /home/ipfs/go-ipfs.tar.gz

        #get file sizes 
        newsize=$(wc -c <"/home/ipfs/go-ipfs/ipfs")
        cursize=$(wc -c <"/home/ipfs/ipfs")

        #if new file is not as current
        if (($newsize != $cursize)); then
                #replace it
                mv /home/ipfs/go-ipfs/ipfs /home/ipfs/ipfs
                chmod +x /home/ipfs/ipfs
                #kill old to restart new
                pkill ipfs
        fi
fi