zu1k / nali

An offline tool for querying IP geographic information and CDN provider. 一个查询IP地理信息和CDN服务提供商的离线终端工具.
https://github.com/zu1k/nali
MIT License
3.74k stars 340 forks source link

feat: implement self-update for nali #177

Closed DateBro closed 11 months ago

DateBro commented 11 months ago

implemented self-update for nali, used creativeprojects/go-selfupdate.

locally tested, this is the log:

~/Documents/code_projects/nali/nali   go install
 ~/Documents/code_projects/nali/nali  nali 1.2.3.4                
1.2.3.4 [澳大利亚 APNIC Debogon-prefix网络] 
~/Documents/code_projects/nali/nali  nali --version
nali version unknown version
~/Documents/code_projects/nali/nali  nali update --version v0.7.2
2023/09/24 20:58:34 Decompressing gzip file
2023/09/24 20:58:34 Executable file "nali-darwin-arm64" was found in gzip file
2023/09/24 20:58:34 Will update /Users/zhaozhiyong/go/bin/nali to v0.7.2 downloaded from https://github.com/zu1k/nali/releases/download/v0.7.2/nali-darwin-arm64-v0.7.2.gz
2023/09/24 20:58:34 Successfully updated to version 0.7.2
~/Documents/code_projects/nali/nali  nali 1.2.3.4                
1.2.3.4 [澳大利亚 APNIC Debogon-prefix网络] 
 ~/Documents/code_projects/nali/nali  nali --version
nali version v0.7.2

issue: #171

zu1k commented 11 months ago

Our binary increased by 40% due to the introduction of a lot of non-essential code, which could have been avoided. We can no longer use go-selfupdate to do this, but need to implement this in nali itself.

The logic here is simple:

  1. Access https://api.github.com/repos/zu1k/nali/releases/latest
  2. Compare version numbers
  3. Filtering assets by GOOS and GOARCH
  4. Download the new version nali and its sha256 via the given browser_download_url
  5. Verifying files with sha256
  6. Unzip and replace nali itself
zu1k commented 11 months ago

LGTM

zu1k commented 11 months ago

Thanks