diff --git a/cmd/cloudflared/updater/update.go b/cmd/cloudflared/updater/update.go index 6457a4ac..637fc345 100644 --- a/cmd/cloudflared/updater/update.go +++ b/cmd/cloudflared/updater/update.go @@ -4,12 +4,14 @@ import ( "context" "fmt" "os" + "path/filepath" "runtime" "time" "golang.org/x/crypto/ssh/terminal" "gopkg.in/urfave/cli.v2" + "github.com/cloudflare/cloudflared/cmd/cloudflared/config" "github.com/cloudflare/cloudflared/logger" "github.com/equinox-io/equinox" "github.com/facebookgo/grace/gracenet" @@ -17,10 +19,12 @@ import ( ) const ( - DefaultCheckUpdateFreq = time.Hour * 24 - appID = "app_idCzgxYerVD" - noUpdateInShellMessage = "cloudflared will not automatically update when run from the shell. To enable auto-updates, run cloudflared as a service: https://developers.cloudflare.com/argo-tunnel/reference/service/" - noUpdateOnWindowsMessage = "cloudflared will not automatically update on Windows systems." + DefaultCheckUpdateFreq = time.Hour * 24 + appID = "app_idCzgxYerVD" + noUpdateInShellMessage = "cloudflared will not automatically update when run from the shell. To enable auto-updates, run cloudflared as a service: https://developers.cloudflare.com/argo-tunnel/reference/service/" + noUpdateOnWindowsMessage = "cloudflared will not automatically update on Windows systems." + noUpdateManagedPackageMessage = "cloudflared will not automatically update if installed by a package manager." + isManagedInstallFile = ".installedFromPackageManager" ) var ( @@ -98,6 +102,11 @@ func Update(_ *cli.Context) error { return errors.Wrap(err, "error setting up logger") } + if wasInstalledFromPackageManager() { + logger.Error("cloudflared was installed by a package manager. Please update using the same method.") + return nil + } + updateOutcome := loggedUpdate(logger) if updateOutcome.Error != nil { return &statusErr{updateOutcome.Error} @@ -217,6 +226,11 @@ func SupportAutoUpdate(logger logger.Service) bool { return false } + if wasInstalledFromPackageManager() { + logger.Info(noUpdateManagedPackageMessage) + return false + } + if isRunningFromTerminal() { logger.Info(noUpdateInShellMessage) return false @@ -224,6 +238,11 @@ func SupportAutoUpdate(logger logger.Service) bool { return true } +func wasInstalledFromPackageManager() bool { + ok, _ := config.FileExists(filepath.Join(config.DefaultUnixConfigLocation, isManagedInstallFile)) + return ok +} + func isRunningFromTerminal() bool { return terminal.IsTerminal(int(os.Stdout.Fd())) } diff --git a/postinst.sh b/postinst.sh index b6c65eb7..d460ef3e 100644 --- a/postinst.sh +++ b/postinst.sh @@ -1,3 +1,5 @@ #!/bin/bash set -eu ln -s /usr/bin/cloudflared /usr/local/bin/cloudflared +mkdir -p /usr/local/etc/cloudflared/ +touch /usr/local/etc/cloudflared/.installedFromPackageManager || true diff --git a/postrm.sh b/postrm.sh index f84c20c3..dc912ad9 100644 --- a/postrm.sh +++ b/postrm.sh @@ -1,3 +1,4 @@ #!/bin/bash set -eu rm /usr/local/bin/cloudflared +rm /usr/local/etc/cloudflared/.installedFromPackageManager || true