From eeaa3af2579a4622fc333267d86eabe0936257c5 Mon Sep 17 00:00:00 2001 From: ervinismu Date: Sat, 21 Jan 2023 16:54:13 +0700 Subject: [PATCH 1/2] fix : move command exec into golang http --- cmd/cli/main.go | 62 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 9 deletions(-) diff --git a/cmd/cli/main.go b/cmd/cli/main.go index 121f526..55dec35 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -42,6 +42,14 @@ type Submission struct { SourceBranch string `json:"sourceBranch"` } +type GithubReleaseResponse struct { + Url string `json:"url"` + Assets []struct { + Name string `json:"name"` + BrowserDownloadUrl string `json:"browser_download_url"` + } +} + var ( app *cli.App homeDir string @@ -815,36 +823,72 @@ func main() { Name: "update", Usage: "Update the irgsh-cli tool", Action: func(c *cli.Context) (err error) { - cmdStr := "curl -ksL 'https://api.github.com/repos/BlankOn/irgsh-go/releases/latest' | jq -r '.assets | .[] | select(.name == \"irgsh-cli\")| .browser_download_url'" - output, err := exec.Command("bash", "-c", cmdStr).Output() + var ( + cmdStr = "ln -sf /usr/bin/irgsh-cli /usr/bin/irgsh && /usr/bin/irgsh-cli --version" + downloadURL string + githubResponse GithubReleaseResponse + githubAssetName = "irgsh-cli" + url = "https://api.github.com/repos/BlankOn/irgsh-go/releases/latest" + ) + + response, err := http.Get(url) if err != nil { - log.Println("error: %v\n", err) + log.Printf("error: %v\n", err) log.Println("Failed to get package name.") + return } - downloadURL := strings.TrimSuffix(string(output), "\n") + defer response.Body.Close() + + body, err := ioutil.ReadAll(response.Body) + if err != nil { + log.Printf("error: %v\n", err) + + return + } + + if err := json.Unmarshal(body, &githubResponse); err != nil { + log.Printf("error: %v\n", err) + + return err + } + + for _, asset := range githubResponse.Assets { + if asset.Name == githubAssetName { + downloadURL = strings.TrimSuffix(string(asset.BrowserDownloadUrl), "\n") + break + } + } + log.Println(downloadURL) log.Println("Self-updating...") + resp, err := http.Get(downloadURL) if err != nil { - log.Println(err) + log.Printf("error: %v\n", err) + return err } + defer resp.Body.Close() + err = update.Apply(resp.Body, update.Options{}) if err != nil { - log.Println(err) + log.Printf("error: %v\n", err) + return err } - cmdStr = "ln -sf /usr/bin/irgsh-cli /usr/bin/irgsh && /usr/bin/irgsh-cli --version" + log.Println(cmdStr) - output, err = exec.Command("bash", "-c", cmdStr).Output() + + output, err := exec.Command("bash", "-c", cmdStr).Output() if err != nil { log.Println(output) - log.Println("error: %v\n", err) + log.Printf("error: %v\n", err) log.Println("Failed to get package name.") } log.Println("Updated to " + strings.TrimSuffix(string(output), "\n")) + return }, }, From c6fa9a73e5ba0137ab1ba0084f023b9db698c1c4 Mon Sep 17 00:00:00 2001 From: ervinismu Date: Tue, 31 Jan 2023 11:36:08 +0700 Subject: [PATCH 2/2] fix : replace python-apt to python3-apt. --- .github/workflows/generic.yml | 2 +- .github/workflows/master.yml | 2 +- .gitpod.Dockerfile | 2 +- install.sh | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/generic.yml b/.github/workflows/generic.yml index a12ecba..1174caf 100644 --- a/.github/workflows/generic.yml +++ b/.github/workflows/generic.yml @@ -19,7 +19,7 @@ jobs: - uses: actions/checkout@v1 - name: Build Development release run: | - sudo apt update && sudo apt install -y gpg pbuilder debootstrap devscripts python-apt reprepro make + sudo apt update && sudo apt install -y gpg pbuilder debootstrap devscripts python3-apt reprepro make curl -O https://storage.googleapis.com/golang/go1.13.14.linux-amd64.tar.gz tar -xf go1.13.14.linux-amd64.tar.gz sudo mv go /usr/local diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 48dce5c..ba46746 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -15,7 +15,7 @@ jobs: - uses: actions/checkout@v1 - name: Run a multi-line script run: | - sudo apt update && sudo apt install -y gpg pbuilder debootstrap devscripts python-apt reprepro make + sudo apt update && sudo apt install -y gpg pbuilder debootstrap devscripts python3-apt reprepro make curl -O https://storage.googleapis.com/golang/go1.13.14.linux-amd64.tar.gz tar -xf go1.13.14.linux-amd64.tar.gz sudo mv go /usr/local diff --git a/.gitpod.Dockerfile b/.gitpod.Dockerfile index 64d47fd..873e256 100644 --- a/.gitpod.Dockerfile +++ b/.gitpod.Dockerfile @@ -1,5 +1,5 @@ FROM debian:buster-slim -RUN apt update && apt install -y gpg pbuilder debootstrap devscripts python-apt reprepro make && \ +RUN apt update && apt install -y gpg pbuilder debootstrap devscripts python3-apt reprepro make && \ curl -O https://storage.googleapis.com/golang/go1.13.14.linux-amd64.tar.gz && \ tar -xf go1.13.14.linux-amd64.tar.gz && \ mv go /usr/local && \ diff --git a/install.sh b/install.sh index 55920ea..f8f36ef 100755 --- a/install.sh +++ b/install.sh @@ -24,7 +24,7 @@ else apt install -y docker.io fi -apt install -y gnupg pbuilder debootstrap devscripts debhelper python-apt reprepro jq +apt install -y gnupg pbuilder debootstrap devscripts debhelper python3-apt reprepro jq if [ -f ./target/release.tar.gz ]; then # For development/testing purpose