|
|
@ -47,11 +47,11 @@ func dlJSON(url string) (GithubRelease, error) {
|
|
|
|
|
|
|
|
|
|
|
|
func Uninstall(restic bool) error {
|
|
|
|
func Uninstall(restic bool) error {
|
|
|
|
if err := os.Remove(path.Join(INSTALL_PATH, "autorestic")); err != nil {
|
|
|
|
if err := os.Remove(path.Join(INSTALL_PATH, "autorestic")); err != nil {
|
|
|
|
colors.Error.Println(err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if restic {
|
|
|
|
if restic {
|
|
|
|
if err := os.Remove(path.Join(INSTALL_PATH, "restic")); err != nil {
|
|
|
|
if err := os.Remove(path.Join(INSTALL_PATH, "restic")); err != nil {
|
|
|
|
colors.Error.Println(err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
@ -79,11 +79,15 @@ func downloadAndInstallAsset(body GithubRelease, name string) error {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
defer tmp.Close()
|
|
|
|
defer tmp.Close()
|
|
|
|
tmp.Chmod(0755)
|
|
|
|
if err := tmp.Chmod(0755); err != nil {
|
|
|
|
io.Copy(tmp, bz)
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := io.Copy(tmp, bz); err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
to := path.Join(INSTALL_PATH, name)
|
|
|
|
to := path.Join(INSTALL_PATH, name)
|
|
|
|
os.Remove(to) // Delete if current, ignore error if file does not exits.
|
|
|
|
defer os.Remove(to) // Delete if current, ignore error if file does not exits.
|
|
|
|
if err := os.Rename(tmp.Name(), to); err != nil {
|
|
|
|
if err := os.Rename(tmp.Name(), to); err != nil {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -121,9 +125,11 @@ func Upgrade(restic bool) error {
|
|
|
|
// Upgrade restic
|
|
|
|
// Upgrade restic
|
|
|
|
if restic {
|
|
|
|
if restic {
|
|
|
|
if err := InstallRestic(); err != nil {
|
|
|
|
if err := InstallRestic(); err != nil {
|
|
|
|
colors.Error.Println(err)
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := upgradeRestic(); err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
upgradeRestic()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Upgrade self
|
|
|
|
// Upgrade self
|
|
|
@ -140,7 +146,9 @@ func Upgrade(restic bool) error {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if current.LT(latest) {
|
|
|
|
if current.LT(latest) {
|
|
|
|
downloadAndInstallAsset(body, "autorestic")
|
|
|
|
if err := downloadAndInstallAsset(body, "autorestic"); err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
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")
|
|
|
|