Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

add update Instructions

Maidul Islama4074c968773
diff --git a/cli/packages/util/check-for-update.go b/cli/packages/util/check-for-update.go
index a23b90ad1f..220b098e99 100644
--- a/cli/packages/util/check-for-update.go
+++ b/cli/packages/util/check-for-update.go
@@ -6,6 +6,11 @@ import (
"fmt"
"io/ioutil"
"net/http"
+ "os"
+ "os/exec"
+ "runtime"
+
+ "github.com/fatih/color"
)
func CheckForUpdate() {
@@ -15,7 +20,26 @@ func CheckForUpdate() {
return
}
if latestVersion != CLI_VERSION {
- PrintWarning(fmt.Sprintf("Please update your CLI. You are running version %s but the latest version is %s", CLI_VERSION, latestVersion))
+ yellow := color.New(color.FgYellow).SprintFunc()
+ blue := color.New(color.FgCyan).SprintFunc()
+ black := color.New(color.FgBlack).SprintFunc()
+
+ msg := fmt.Sprintf("%s %s %s %s",
+ yellow("A new release of infisical is available:"),
+ blue(CLI_VERSION),
+ black("->"),
+ blue(latestVersion),
+ )
+
+ fmt.Fprintln(os.Stderr, msg)
+
+ updateInstructions := GetUpdateInstructions()
+
+ if updateInstructions != "" {
+ msg = fmt.Sprintf("\n%s\n", GetUpdateInstructions())
+ fmt.Fprintln(os.Stderr, msg)
+ }
+
}
}
@@ -26,7 +50,7 @@ func getLatestTag(repoOwner string, repoName string) (string, error) {
return "", err
}
if resp.StatusCode != 200 {
- return "", errors.New(fmt.Sprintf("GitHub API returned status code %d", resp.StatusCode))
+ return "", errors.New(fmt.Sprintf("gitHub API returned status code %d", resp.StatusCode))
}
defer resp.Body.Close()
@@ -44,3 +68,53 @@ func getLatestTag(repoOwner string, repoName string) (string, error) {
return tags[0].Name[1:], nil
}
+
+func GetUpdateInstructions() string {
+ os := runtime.GOOS
+ switch os {
+ case "darwin":
+ return "To update, run: brew update && brew upgrade infisical"
+ case "windows":
+ return "To update, run: scoop update infisical"
+ case "linux":
+ pkgManager := getLinuxPackageManager()
+ switch pkgManager {
+ case "apt-get":
+ return "To update, run: sudo apt-get update && sudo apt-get install infisical"
+ case "yum":
+ return "To update, run: sudo yum update infisical"
+ case "apk":
+ return "To update, run: sudo apk update && sudo apk upgrade infisical"
+ case "yay":
+ return "To update, run: yay -Syu infisical"
+ default:
+ return ""
+ }
+ default:
+ return ""
+ }
+}
+
+func getLinuxPackageManager() string {
+ cmd := exec.Command("apt-get", "--version")
+ if err := cmd.Run(); err == nil {
+ return "apt-get"
+ }
+
+ cmd = exec.Command("yum", "--version")
+ if err := cmd.Run(); err == nil {
+ return "yum"
+ }
+
+ cmd = exec.Command("yay", "--version")
+ if err := cmd.Run(); err == nil {
+ return "yay"
+ }
+
+ cmd = exec.Command("apk", "--version")
+ if err := cmd.Run(); err == nil {
+ return "apk"
+ }
+
+ return ""
+}