TUN-5853 Add "install" make target and build package manager info into executable
This commit is contained in:
parent
c54e8cd8e6
commit
9552bb7bc7
|
@ -10,6 +10,7 @@ cscope.*
|
||||||
/cloudflared.exe
|
/cloudflared.exe
|
||||||
/cloudflared.msi
|
/cloudflared.msi
|
||||||
/cloudflared-x86-64*
|
/cloudflared-x86-64*
|
||||||
|
/cloudflared.1
|
||||||
/packaging
|
/packaging
|
||||||
.DS_Store
|
.DS_Store
|
||||||
*-session.log
|
*-session.log
|
||||||
|
|
26
Makefile
26
Makefile
|
@ -23,6 +23,9 @@ endif
|
||||||
|
|
||||||
DATE := $(shell date -u '+%Y-%m-%d-%H%M UTC')
|
DATE := $(shell date -u '+%Y-%m-%d-%H%M UTC')
|
||||||
VERSION_FLAGS := -X "main.Version=$(VERSION)" -X "main.BuildTime=$(DATE)"
|
VERSION_FLAGS := -X "main.Version=$(VERSION)" -X "main.BuildTime=$(DATE)"
|
||||||
|
ifdef PACKAGE_MANAGER
|
||||||
|
VERSION_FLAGS := $(VERSION_FLAGS) -X "github.com/cloudflare/cloudflared/cmd/cloudflared/updater.BuiltForPackageManager=$(PACKAGE_MANAGER)"
|
||||||
|
endif
|
||||||
|
|
||||||
LINK_FLAGS :=
|
LINK_FLAGS :=
|
||||||
ifeq ($(FIPS), true)
|
ifeq ($(FIPS), true)
|
||||||
|
@ -39,8 +42,9 @@ endif
|
||||||
|
|
||||||
IMPORT_PATH := github.com/cloudflare/cloudflared
|
IMPORT_PATH := github.com/cloudflare/cloudflared
|
||||||
PACKAGE_DIR := $(CURDIR)/packaging
|
PACKAGE_DIR := $(CURDIR)/packaging
|
||||||
INSTALL_BINDIR := /usr/bin/
|
PREFIX := /usr
|
||||||
MAN_DIR := /usr/share/man/man1/
|
INSTALL_BINDIR := $(PREFIX)/bin/
|
||||||
|
INSTALL_MANDIR := $(PREFIX)/share/man/man1/
|
||||||
|
|
||||||
LOCAL_ARCH ?= $(shell uname -m)
|
LOCAL_ARCH ?= $(shell uname -m)
|
||||||
ifneq ($(GOARCH),)
|
ifneq ($(GOARCH),)
|
||||||
|
@ -141,12 +145,20 @@ publish-deb: cloudflared-deb
|
||||||
publish-rpm: cloudflared-rpm
|
publish-rpm: cloudflared-rpm
|
||||||
$(call publish_package,rpm,yum)
|
$(call publish_package,rpm,yum)
|
||||||
|
|
||||||
|
cloudflared.1: cloudflared_man_template
|
||||||
|
cat cloudflared_man_template | sed -e 's/\$${VERSION}/$(VERSION)/; s/\$${DATE}/$(DATE)/' > cloudflared.1
|
||||||
|
|
||||||
|
install: cloudflared cloudflared.1
|
||||||
|
mkdir -p $(DESTDIR)$(INSTALL_BINDIR) $(DESTDIR)$(INSTALL_MANDIR)
|
||||||
|
install -m755 cloudflared $(DESTDIR)$(INSTALL_BINDIR)/cloudflared
|
||||||
|
install -m644 cloudflared.1 $(DESTDIR)$(INSTALL_MANDIR)/cloudflared.1
|
||||||
|
|
||||||
# When we build packages, the package name will be FIPS-aware.
|
# When we build packages, the package name will be FIPS-aware.
|
||||||
# But we keep the binary installed by it to be named "cloudflared" regardless.
|
# But we keep the binary installed by it to be named "cloudflared" regardless.
|
||||||
define build_package
|
define build_package
|
||||||
mkdir -p $(PACKAGE_DIR)
|
mkdir -p $(PACKAGE_DIR)
|
||||||
cp cloudflared $(PACKAGE_DIR)/cloudflared
|
cp cloudflared $(PACKAGE_DIR)/cloudflared
|
||||||
cat cloudflared_man_template | sed -e 's/\$${VERSION}/$(VERSION)/; s/\$${DATE}/$(DATE)/' > $(PACKAGE_DIR)/cloudflared.1
|
cp cloudflared.1 $(PACKAGE_DIR)/cloudflared.1
|
||||||
fakeroot fpm -C $(PACKAGE_DIR) -s dir -t $(1) \
|
fakeroot fpm -C $(PACKAGE_DIR) -s dir -t $(1) \
|
||||||
--description 'Cloudflare Tunnel daemon' \
|
--description 'Cloudflare Tunnel daemon' \
|
||||||
--vendor 'Cloudflare' \
|
--vendor 'Cloudflare' \
|
||||||
|
@ -154,19 +166,19 @@ define build_package
|
||||||
--url 'https://github.com/cloudflare/cloudflared' \
|
--url 'https://github.com/cloudflare/cloudflared' \
|
||||||
-m 'Cloudflare <support@cloudflare.com>' \
|
-m 'Cloudflare <support@cloudflare.com>' \
|
||||||
-a $(TARGET_ARCH) -v $(VERSION) -n $(DEB_PACKAGE_NAME) $(NIGHTLY_FLAGS) --after-install postinst.sh --after-remove postrm.sh \
|
-a $(TARGET_ARCH) -v $(VERSION) -n $(DEB_PACKAGE_NAME) $(NIGHTLY_FLAGS) --after-install postinst.sh --after-remove postrm.sh \
|
||||||
cloudflared=$(INSTALL_BINDIR) cloudflared.1=$(MAN_DIR)
|
cloudflared=$(INSTALL_BINDIR) cloudflared.1=$(INSTALL_MANDIR)
|
||||||
endef
|
endef
|
||||||
|
|
||||||
.PHONY: cloudflared-deb
|
.PHONY: cloudflared-deb
|
||||||
cloudflared-deb: cloudflared
|
cloudflared-deb: cloudflared cloudflared.1
|
||||||
$(call build_package,deb)
|
$(call build_package,deb)
|
||||||
|
|
||||||
.PHONY: cloudflared-rpm
|
.PHONY: cloudflared-rpm
|
||||||
cloudflared-rpm: cloudflared
|
cloudflared-rpm: cloudflared cloudflared.1
|
||||||
$(call build_package,rpm)
|
$(call build_package,rpm)
|
||||||
|
|
||||||
.PHONY: cloudflared-pkg
|
.PHONY: cloudflared-pkg
|
||||||
cloudflared-pkg: cloudflared
|
cloudflared-pkg: cloudflared cloudflared.1
|
||||||
$(call build_package,osxpkg)
|
$(call build_package,osxpkg)
|
||||||
|
|
||||||
.PHONY: cloudflared-msi
|
.PHONY: cloudflared-msi
|
||||||
|
|
|
@ -31,6 +31,7 @@ const (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
version string
|
version string
|
||||||
|
BuiltForPackageManager = ""
|
||||||
)
|
)
|
||||||
|
|
||||||
// BinaryUpdated implements ExitCoder interface, the app will exit with status code 11
|
// BinaryUpdated implements ExitCoder interface, the app will exit with status code 11
|
||||||
|
@ -118,7 +119,11 @@ func Update(c *cli.Context) error {
|
||||||
log := logger.CreateLoggerFromContext(c, logger.EnableTerminalLog)
|
log := logger.CreateLoggerFromContext(c, logger.EnableTerminalLog)
|
||||||
|
|
||||||
if wasInstalledFromPackageManager() {
|
if wasInstalledFromPackageManager() {
|
||||||
log.Error().Msg("cloudflared was installed by a package manager. Please update using the same method.")
|
packageManagerName := "a package manager"
|
||||||
|
if BuiltForPackageManager != "" {
|
||||||
|
packageManagerName = BuiltForPackageManager
|
||||||
|
}
|
||||||
|
log.Error().Msg(fmt.Sprintf("cloudflared was installed by %s. Please update using the same method.", packageManagerName))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,7 +286,7 @@ func supportAutoUpdate(log *zerolog.Logger) bool {
|
||||||
|
|
||||||
func wasInstalledFromPackageManager() bool {
|
func wasInstalledFromPackageManager() bool {
|
||||||
ok, _ := config.FileExists(filepath.Join(config.DefaultUnixConfigLocation, isManagedInstallFile))
|
ok, _ := config.FileExists(filepath.Join(config.DefaultUnixConfigLocation, isManagedInstallFile))
|
||||||
return ok
|
return len(BuiltForPackageManager) != 0 || ok
|
||||||
}
|
}
|
||||||
|
|
||||||
func isRunningFromTerminal() bool {
|
func isRunningFromTerminal() bool {
|
||||||
|
|
Loading…
Reference in New Issue