Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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