Skip to content

Commit

Permalink
fix: github proxy not working when install (#331)
Browse files Browse the repository at this point in the history
  • Loading branch information
LinuxSuRen authored Jan 28, 2023
1 parent 00eae5a commit 171d64a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
10 changes: 7 additions & 3 deletions cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,19 +252,23 @@ func (o *downloadOption) runE(cmd *cobra.Command, args []string) (err error) {
return
}

cmd.Printf("start to download from %s\n", o.URL)
targetURL := o.URL
if o.ProxyGitHub != "" {
targetURL = strings.Replace(targetURL, "github.com", fmt.Sprintf("%s/github.com", o.ProxyGitHub), 1)
}
cmd.Printf("start to download from %s\n", targetURL)
if o.Thread <= 1 {
downloader := &net.ContinueDownloader{}
downloader.WithoutProxy(o.NoProxy).
WithRoundTripper(o.RoundTripper)
err = downloader.DownloadWithContinue(o.URL, o.Output, o.ContinueAt, -1, 0, o.ShowProgress)
err = downloader.DownloadWithContinue(targetURL, o.Output, o.ContinueAt, -1, 0, o.ShowProgress)
} else {
downloader := &net.MultiThreadDownloader{}
downloader.WithKeepParts(o.KeepPart).
WithShowProgress(o.ShowProgress).
WithoutProxy(o.NoProxy).
WithRoundTripper(o.RoundTripper)
err = downloader.Download(o.URL, o.Output, o.Thread)
err = downloader.Download(targetURL, o.Output, o.Thread)
}
return
}
Expand Down
23 changes: 19 additions & 4 deletions pkg/installer/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"path"
"path/filepath"
"strings"
)

// Install installs a package
Expand Down Expand Up @@ -64,13 +65,27 @@ func (o *Installer) Install() (err error) {

if configFile.OS == o.Execer.OS() {
if err = os.MkdirAll(configDir, 0750); err != nil {
err = fmt.Errorf("cannot create config dir: %s, error: %v", configDir, err)
return
if strings.Contains(err.Error(), "permission denied") {
err = o.Execer.RunCommandWithSudo("mkdir", "-p", configDir)
}

if err != nil {
err = fmt.Errorf("cannot create config dir: %s, error: %v", configDir, err)
return
}
}

if err = os.WriteFile(configFilePath, []byte(configFile.Content), 0622); err != nil {
err = fmt.Errorf("cannot write config file: %s, error: %v", configFilePath, err)
return
if strings.Contains(err.Error(), "permission denied") {
if err = o.Execer.RunCommandWithSudo("touch", configFilePath); err == nil {
err = o.Execer.RunCommandWithSudo("chmod", "+w", configFilePath)
}
}

if err != nil {
err = fmt.Errorf("cannot write config file: %s, error: %v", configFilePath, err)
return
}
}

fmt.Printf("config file [%s] is ready.\n", configFilePath)
Expand Down

0 comments on commit 171d64a

Please sign in to comment.