mirror of
https://github.com/cupcakearmy/autorestic.git
synced 2024-12-22 16:26:25 +00:00
upgrade logic
This commit is contained in:
parent
ec2377287e
commit
976a3beab5
@ -57,16 +57,7 @@ func Uninstall(restic bool) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func InstallRestic() error {
|
func downloadAndInstallAsset(body GithubRelease, name string) error {
|
||||||
installed := internal.CheckIfCommandIsCallable("restic")
|
|
||||||
if installed {
|
|
||||||
colors.Body.Println("restic already installed")
|
|
||||||
return nil
|
|
||||||
} else {
|
|
||||||
body, err := dlJSON("https://api.github.com/repos/restic/restic/releases/latest")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
ending := fmt.Sprintf("_%s_%s.bz2", runtime.GOOS, runtime.GOARCH)
|
ending := fmt.Sprintf("_%s_%s.bz2", runtime.GOOS, runtime.GOARCH)
|
||||||
for _, asset := range body.Assets {
|
for _, asset := range body.Assets {
|
||||||
if strings.HasSuffix(asset.Name, ending) {
|
if strings.HasSuffix(asset.Name, ending) {
|
||||||
@ -82,7 +73,7 @@ func InstallRestic() error {
|
|||||||
bz := bzip2.NewReader(resp.Body)
|
bz := bzip2.NewReader(resp.Body)
|
||||||
|
|
||||||
// Save binary
|
// Save binary
|
||||||
file, err := os.Create(path.Join(INSTALL_PATH, "restic"))
|
file, err := os.Create(path.Join(INSTALL_PATH, name))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -90,12 +81,25 @@ func InstallRestic() error {
|
|||||||
defer file.Close()
|
defer file.Close()
|
||||||
io.Copy(file, bz)
|
io.Copy(file, bz)
|
||||||
|
|
||||||
colors.Success.Printf("Successfully installed restic under %s\n", INSTALL_PATH)
|
colors.Success.Printf("Successfully installed '%s' under %s\n", name, INSTALL_PATH)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return errors.New("could not find right binary for your system, please install restic manually. https://bit.ly/2Y1Rzai")
|
return errors.New("could not find right binary for your system, please install restic manually. https://bit.ly/2Y1Rzai")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func InstallRestic() error {
|
||||||
|
installed := internal.CheckIfCommandIsCallable("restic")
|
||||||
|
if installed {
|
||||||
|
colors.Body.Println("restic already installed")
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
if body, err := dlJSON("https://api.github.com/repos/restic/restic/releases/latest"); err != nil {
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
|
return downloadAndInstallAsset(body, "restic")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func upgradeRestic() error {
|
func upgradeRestic() error {
|
||||||
@ -127,7 +131,7 @@ func Upgrade(restic bool) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if current.GT(latest) {
|
if current.GT(latest) {
|
||||||
// TODO: Actually download and install
|
downloadAndInstallAsset(body, "autorestic")
|
||||||
colors.Success.Println("Updated autorestic")
|
colors.Success.Println("Updated autorestic")
|
||||||
} else {
|
} else {
|
||||||
colors.Body.Println("Already up to date")
|
colors.Body.Println("Already up to date")
|
||||||
|
Loading…
Reference in New Issue
Block a user