全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
查看: 1864|回复: 4

[疑问] 分享一个奇**技巧,获取github最新的releases

[复制链接]
发表于 2018-3-13 15:54:00 | 显示全部楼层 |阅读模式
早上想写个Shell Script,但是包版本经常更新,我这个人又懒不想经常改动,怎么办呢
想起来github是有开放api的,这就好办了对吧,随便找找,顺利找到了api。
然后开写吧,shell解析json这个东西 真的很麻烦,写了半天正则,还是算了,不然正则比脚本还长。
然后谷歌一下,找到了jq这个东西,惊为天人,顺利把脚本缩减大半,这里也分享一下。
写点啥好呢,这里安装libsodium,相信你们懂的。



  1. wget -O jq https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64
  2. chmod +x ./jq
  3. mv jq /usr/bin

  4. wget $(curl -s https://api.github.com/repos/jedisct1/libsodium/releases/latest | jq -r '.assets[0].browser_download_url')
  5. #解释一下这里,用curl访问github api,获取到最新的包地址,然后用jq解析json数据
  6. #https://developer.github.com/v3/repos/releases/
  7. #https://stedolan.github.io/jq/
  8. tar xf libsodium-*.tar.gz && cd libsodium-*
  9. ./configure && make -j2 && make install
  10. ldconfig
复制代码
发表于 2018-3-13 16:10:03 | 显示全部楼层
https://gist.github.com/lukechilds/a83e1d7127b78fef38c2914c4ececc3c
 楼主| 发表于 2018-3-13 16:26:45 | 显示全部楼层
嫂子抱紧我 发表于 2018-3-13 16:10
https://gist.github.com/lukechilds/a83e1d7127b78fef38c2914c4ececc3c

大佬 牛逼 666
发表于 2018-3-13 16:35:27 | 显示全部楼层
算啥奇扌支**巧,从自用脚本里摘录给你
  1. get_latest_release() {
  2.   curl -s "https://github.com/$1/releases/latest" | perl -e 'while($_=<>){ /\/tag\/(.*)">redirected/; print $1;}
  3. }
  4. # Usage
  5. # $ get_latest_release "jpillora/cloud-torrent"
  6. # 0.8.24
复制代码
发表于 2018-3-14 09:13:28 | 显示全部楼层
要啥api
curl -s https://github.com/jpillora/cloud-torrent/releases| grep -oP "/releases/tag/[^\"^']+"| grep -oP "[^/^\"^']+"| head -n3|tail -n1
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2024-5-2 10:05 , Processed in 0.073547 second(s), 9 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表