How to automatically download and update programs from github releases

github.com 是目前最大的开源软件下载网站

Windows 下,有些软件可以用 scoop 自动下载和更新,当这个方法不可用时,我们可以自己写个 bash 脚本文件实现目的

下面是 海云青飞 用的示例代码,你可能需要略作修改才能适合你的需求

#!/usr/bin/bash

# 作者 海云青飞
# 2024-11-16

owner=userQponm
repo=topProgram

# Download file to a temporary directory and do not save important files there
downloadTo=/downloads/tmp

# Unzip the file to a directory
extractTo=/myProgram


version=$(curl -Ls -o /dev/null -w %{url_effective} https://github.com/$owner/$repo/releases/latest)
version=${version##*/}

# You may want to customize the file name format
link=https://github.com/$owner/$repo/releases/download/$version/$repo-x86_64-pc-windows-msvc.zip

echo $version
echo $link

rm -rf $downloadTo/*
cd $downloadTo

# Sometimes the file downloaded by curl is empty
wget $link

# -o overwriting files without prompting
# -d extract files into directory
# -x exclude files
unzip -o *.zip -d $extractTo -x config.json

rm -rf $downloadTo/*

References

2024-11-16


独立思考最难得,赞赏支持是美德!(微信扫描下图)