找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 43|回复: 4

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

[复制链接]

7

主题

71

回帖

183

积分

注册会员

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



[ol]
  • wget -O jq https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64
  • chmod +x ./jq
  • mv jq /usr/bin
  • wget $(curl -s https://api.github.com/repos/jedisct1/libsodium/releases/latest | jq -r '.assets[0].browser_download_url')
  • #解释一下这里,用curl访问github api,获取到最新的包地址,然后用jq解析json数据
  • #https://developer.github.com/v3/repos/releases/
  • #https://stedolan.github.io/jq/
  • tar xf libsodium-*.tar.gz && cd libsodium-*
  • ./configure && make -j2 && make install
  • ldconfig[/ol]复制代码
  • 回复

    使用道具 举报

    82

    主题

    1212

    回帖

    2774

    积分

    金牌会员

    积分
    2774
    发表于 2018-3-13 16:10:03 | 显示全部楼层
    https://gist.github.com/lukechilds/a83e1d7127b78fef38c2914c4ececc3c
    回复

    使用道具 举报

    7

    主题

    71

    回帖

    183

    积分

    注册会员

    积分
    183
     楼主| 发表于 2018-3-13 16:26:45 | 显示全部楼层

    嫂子抱紧我 发表于 2018-3-13 16:10

    https://gist.github.com/lukechilds/a83e1d7127b78fef38c2914c4ececc3c

    大佬 牛逼 666
    回复

    使用道具 举报

    60

    主题

    666

    回帖

    1570

    积分

    金牌会员

    积分
    1570
    发表于 2018-3-13 16:10:00 | 显示全部楼层
    算啥奇扌支**巧,从自用脚本里摘录给你
    [ol]
  • get_latest_release() {
  •   curl -s "https://github.com/$1/releases/latest" | perl -e 'while($_=){ /\/tag\/(.*)">redirected/; print $1;}
  • }
  • # Usage
  • # $ get_latest_release "jpillora/cloud-torrent"
  • # 0.8.24[/ol]复制代码
  • 回复

    使用道具 举报

    37

    主题

    330

    回帖

    811

    积分

    高级会员

    积分
    811
    发表于 2018-3-13 16:35:27 | 显示全部楼层
    要啥api
    curl -s https://github.com/jpillora/cloud-torrent/releases| grep -oP "/releases/tag/[^\"^']+"| grep -oP "[^/^\"^']+"| head -n3|tail -n1

    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    Archiver|手机版|小黑屋|Discuz! X

    GMT+8, 2025-2-23 07:19 , Processed in 0.017488 second(s), 4 queries , Gzip On, Redis On.

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

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