<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Script on Space Dust</title>
    <link>https://blog.gani.win/tags/script/</link>
    <description>Recent content in Script on Space Dust</description>
    <image>
      <title>Space Dust</title>
      <url>https://blog.gani.win/favicon.png</url>
      <link>https://blog.gani.win/favicon.png</link>
    </image>
    <generator>Hugo -- 0.147.2</generator>
    <language>en-US</language>
    <lastBuildDate>Sat, 06 Jan 2024 14:03:10 +0000</lastBuildDate>
    <atom:link href="https://blog.gani.win/tags/script/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Download GitHub Latest Release</title>
      <link>https://blog.gani.win/posts/github/</link>
      <pubDate>Sat, 06 Jan 2024 14:03:10 +0000</pubDate>
      <guid>https://blog.gani.win/posts/github/</guid>
      <description>&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;
&lt;p&gt;A shell script &lt;code&gt;curl-github.sh&lt;/code&gt; to download the latest release of &lt;a href=&#34;https://github.com&#34;&gt;GitHub&lt;/a&gt; repositories. It needs &lt;code&gt;curl&lt;/code&gt; and &lt;code&gt;grep&lt;/code&gt;.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;usage: curl-github.sh [command] [repo] [keyword] 
commands: help, list, get.
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;script&#34;&gt;Script&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;#!/bin/sh
# download the latest release from github

[ -n &amp;#34;$2&amp;#34; ] &amp;amp;&amp;amp; REPO_PATH=&amp;#34;$2&amp;#34;
[ -n &amp;#34;$3&amp;#34; ] &amp;amp;&amp;amp; KEYWORD=&amp;#34;$3&amp;#34;
[ -n &amp;#34;$4&amp;#34; ] &amp;amp;&amp;amp; FILE_NAME=&amp;#34;$4&amp;#34;

[ -z &amp;#34;$REPO_PATH&amp;#34; ] &amp;amp;&amp;amp; REPO_PATH=&amp;#34;microsoft/vscode&amp;#34;
[ -z &amp;#34;$KEYWORD&amp;#34; ] &amp;amp;&amp;amp; KEYWORD=&amp;#34;tarball&amp;#34;

list()
{
    echo $REPO_PATH
    curl -sL &amp;#34;https://api.github.com/repos/$REPO_PATH/releases/latest&amp;#34; | grep &amp;#39;browser_download_url\|tarball_url\|zipball_url&amp;#39; | grep -o &amp;#39;https:[^&amp;#34;]*&amp;#39;
}

get()
{
    echo $REPO_PATH
    echo $KEYWORD
    URL=$(curl -sL &amp;#34;https://api.github.com/repos/$REPO_PATH/releases/latest&amp;#34; | grep &amp;#39;browser_download_url\|tarball_url\|zipball_url&amp;#39; | grep -o &amp;#39;https:[^&amp;#34;]*&amp;#39; | grep &amp;#34;$KEYWORD&amp;#34;) 
    echo $URL
    curl -LO &amp;#34;$URL&amp;#34;
}

help()
{
    echo &amp;#34;usage: curl-github.sh [command] [repo] [keyword], commands: help, list, get.&amp;#34;
}

CMD=$1
: ${CMD:=&amp;#39;help&amp;#39;}
$CMD
&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&#34;ps&#34;&gt;P.S.&lt;/h3&gt;
&lt;h4 id=&#34;grep--o-https&#34;&gt;&lt;code&gt;grep -o &#39;https:[^&amp;quot;]*&#39;&lt;/code&gt;&lt;/h4&gt;
&lt;p&gt;If the first character of the list is the caret ‘^’, then it matches any character not in the list, and it is unspecified whether it matches an encoding error. Check the &lt;a href=&#34;https://www.gnu.org/software/grep/manual/grep.html#Character-Classes-and-Bracket-Expressions&#34;&gt;manual&lt;/a&gt; for details.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
