From 6285b251e716918030b25c47becc6f9e8fae5958 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Thu, 31 Jan 2019 13:43:09 +0100 Subject: [PATCH] don't hardcode /usr/share paths Add a defines.mk file defining the standard default layout for installation (PREFIX, DATAROOTDIR, LIBDIR etc.). Add a $(JSDIR) variable and use env!("JSDIR") in place of the hardcoded /usr/share/javascript/proxmox-backup path. Have defines.mk include an *optional* local.mak to override JSDIR to www/ during local development. Add `make install` targets and remove debian/install. Note that service files are now in $libdir/proxmox-backup/ as there's usually no point in starting them from the command line, so /usr/sbin makes no sense. Signed-off-by: Wolfgang Bumiller --- Makefile | 47 +++++++++++++++++++++++++---- debian/install | 10 ++---- debian/proxmox-backup-proxy.service | 16 ---------- debian/proxmox-backup.service | 13 -------- debian/rules | 2 ++ defines.mk | 13 ++++++++ etc/Makefile | 18 +++++++++++ etc/proxmox-backup-proxy.service.in | 15 +++++++++ etc/proxmox-backup.service.in | 12 ++++++++ src/bin/proxmox-backup-api.rs | 2 +- src/bin/proxmox-backup-proxy.rs | 2 +- www/Makefile | 14 +++++++++ 12 files changed, 119 insertions(+), 45 deletions(-) delete mode 100644 debian/proxmox-backup-proxy.service delete mode 100644 debian/proxmox-backup.service create mode 100644 defines.mk create mode 100644 etc/Makefile create mode 100644 etc/proxmox-backup-proxy.service.in create mode 100644 etc/proxmox-backup.service.in diff --git a/Makefile b/Makefile index dbe8c417e..792478983 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,31 @@ -PACKAGE=proxmox-backup -PKGVER=0.1 -PKGREL=1 +include defines.mk ARCH:=$(shell dpkg-architecture -qDEB_BUILD_ARCH) GITVERSION:=$(shell git rev-parse HEAD) +# Binaries usable by users +USR_BIN := \ + proxmox-backup-client \ + catar + +# Binaries usable by admins +USR_SBIN := proxmox-backup-manager + +# Binaries for services: +SERVICE_BIN := \ + proxmox-backup-api \ + proxmox-backup-proxy + +COMPILEDIR := target/release +COMPILED_BINS := \ + $(addprefix $(COMPILEDIR)/,$(USR_BIN) $(USR_SBIN) $(SERVICE_BIN)) + export PROXMOX_PKG_VERSION=${PKGVER} export PROXMOX_PKG_RELEASE=${PKGREL} export PROXMOX_PKG_REPOID=${GITVERSION} +export PROXMOX_JSDIR := $(JSDIR) + DEB=${PACKAGE}_${PKGVER}-${PKGREL}_${ARCH}.deb DESTDIR= @@ -24,15 +41,15 @@ deb ${DEB}: rm -rf build # build here to cache results cargo build --release - make -C www - rsync -a debian Cargo.lock Cargo.toml src www target build + $(MAKE) -C www + rsync -a debian Cargo.toml src www etc target build cd build; dpkg-buildpackage -b -us -uc distclean: clean clean: - make -C www clean + $(MAKE) -C www clean cargo clean rm -rf *.deb *.buildinfo *.changes build find . -name '*~' -exec rm {} ';' @@ -40,3 +57,21 @@ clean: .PHONY: dinstall dinstall: ${DEB} dpkg -i ${DEB} + +.PHONY: build-release +build-release: + cargo build --release + +$(COMPILED_BINS): build-release + +install: $(COMPILED_BINS) + install -dm755 $(DESTDIR)$(BINDIR) + $(foreach i,$(USR_BIN), \ + install -m755 $(COMPILEDIR)/$(i) $(DESTDIR)$(BINDIR)/ ;) + install -dm755 $(DESTDIR)$(SBINDIR) + $(foreach i,$(USR_SBIN), \ + install -m755 $(COMPILEDIR)/$(i) $(DESTDIR)$(SBINDIR)/ ;) + install -dm755 $(DESTDIR)$(LIBDIR)/proxmox-backup + $(foreach i,$(SERVICE_BIN), \ + install -m755 $(COMPILEDIR)/$(i) $(DESTDIR)$(LIBDIR)/proxmox-backup/ ;) + $(MAKE) -C www install diff --git a/debian/install b/debian/install index ccc1a106d..68b509602 100644 --- a/debian/install +++ b/debian/install @@ -1,8 +1,2 @@ -target/release/proxmox-backup-api /usr/sbin -target/release/proxmox-backup-proxy /usr/bin -target/release/proxmox-backup-manager /usr/sbin -target/release/proxmox-backup-client /usr/sbin -target/release/catar /usr/sbin -www/images/logo-128.png /usr/share/javascript/proxmox-backup/images/ -www/images/proxmox_logo.png /usr/share/javascript/proxmox-backup/images/ -www/js/proxmox-backup-gui.js /usr/share/javascript/proxmox-backup/js/ +etc/proxmox-backup.service /lib/systemd/system/ +etc/proxmox-backup-proxy.service /lib/systemd/system/ diff --git a/debian/proxmox-backup-proxy.service b/debian/proxmox-backup-proxy.service deleted file mode 100644 index 481ff73c9..000000000 --- a/debian/proxmox-backup-proxy.service +++ /dev/null @@ -1,16 +0,0 @@ -[Unit] -Description=Proxmox API Proxy Server -ConditionPathExists=/usr/bin/proxmox-backup-proxy -Wants=proxmox-backup.service -After=syslog.service -After=network.target - -[Service] -User=www-data -Group=www-data -ExecStart=/usr/bin/proxmox-backup-proxy start -Type=simple -Restart=on-failure - -[Install] -WantedBy=multi-user.target diff --git a/debian/proxmox-backup.service b/debian/proxmox-backup.service deleted file mode 100644 index 38964b31f..000000000 --- a/debian/proxmox-backup.service +++ /dev/null @@ -1,13 +0,0 @@ -[Unit] -Description=Proxmox API Test Server -ConditionPathExists=/usr/sbin/proxmox-backup-api -After=syslog.service -After=network.target - -[Service] -ExecStart=/usr/sbin/proxmox-backup-api start -Type=simple -Restart=on-failure - -[Install] -WantedBy=multi-user.target diff --git a/debian/rules b/debian/rules index 9fe161d9e..e9d60d9e3 100755 --- a/debian/rules +++ b/debian/rules @@ -7,6 +7,8 @@ %: dh $@ --with=systemd --with=bash-completion +override_dh_autobuild: + make PROXY_USER=www-data override_dh_installinit: dh_installinit diff --git a/defines.mk b/defines.mk new file mode 100644 index 000000000..4eaffdf9e --- /dev/null +++ b/defines.mk @@ -0,0 +1,13 @@ +PACKAGE := proxmox-backup +PKGVER := 0.1 +PKGREL := 1 + +PREFIX := /usr +BINDIR := $(PREFIX)/bin +SBINDIR := $(PREFIX)/sbin +LIBDIR := $(PREFIX)/lib +DATAROOTDIR := $(PREFIX)/share +JSDIR := $(DATAROOTDIR)/javascript/proxmox-backup + +# For local overrides +-include local.mak diff --git a/etc/Makefile b/etc/Makefile new file mode 100644 index 000000000..70e3a479d --- /dev/null +++ b/etc/Makefile @@ -0,0 +1,18 @@ +include ../defines.mk + +UNITS := \ + proxmox-backup.service \ + proxmox-backup-proxy.service + +all: $(UNITS) + +clean: + rm -f $(UNITS) + +.SUFFIXES: .service.in .service +.service.in.service: + sed \ + -e 's!%LIBDIR%!$(LIBDIR)!g' \ + -e 's!%PROXY_USER%!$(PROXY_USER)!g' \ + $< >$@.tmp + mv $@.tmp $@ diff --git a/etc/proxmox-backup-proxy.service.in b/etc/proxmox-backup-proxy.service.in new file mode 100644 index 000000000..bbdf0f310 --- /dev/null +++ b/etc/proxmox-backup-proxy.service.in @@ -0,0 +1,15 @@ +[Unit] +Description=Proxmox Backup API Proxy Server +Wants=network-online.target +After=network.target syslog.service +Requires=proxmox-backup.service + +[Service] +Type=simple +ExecStart=%LIBDIR%/proxmox-backup/proxmox-backup-proxy +Restart=on-failure +User=%PROXY_USER% +Group=%PROXY_USER% + +[Install] +WantedBy=multi-user.target diff --git a/etc/proxmox-backup.service.in b/etc/proxmox-backup.service.in new file mode 100644 index 000000000..b4c5846ab --- /dev/null +++ b/etc/proxmox-backup.service.in @@ -0,0 +1,12 @@ +[Unit] +Description=Proxmox Backup API Server +Wants=network-online.target +After=network.target syslog.target + +[Service] +Type=simple +ExecStart=%LIBDIR%/proxmox-backup/proxmox-backup-api +Restart=on-failure + +[Install] +WantedBy=multi-user.target diff --git a/src/bin/proxmox-backup-api.rs b/src/bin/proxmox-backup-api.rs index e572434a8..fef08e9a0 100644 --- a/src/bin/proxmox-backup-api.rs +++ b/src/bin/proxmox-backup-api.rs @@ -41,7 +41,7 @@ fn main() { } let config = ApiConfig::new( - "/usr/share/javascript/proxmox-backup", &ROUTER, RpcEnvironmentType::PRIVILEDGED); + env!("PROXMOX_JSDIR"), &ROUTER, RpcEnvironmentType::PRIVILEDGED); let rest_server = RestServer::new(config); diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs index cc62e33f3..1605fecee 100644 --- a/src/bin/proxmox-backup-proxy.rs +++ b/src/bin/proxmox-backup-proxy.rs @@ -32,7 +32,7 @@ fn main() { } let mut config = ApiConfig::new( - "/usr/share/javascript/proxmox-backup", &ROUTER, RpcEnvironmentType::PUBLIC); + env!("PROXMOX_JSDIR"), &ROUTER, RpcEnvironmentType::PUBLIC); // add default dirs which includes jquery and bootstrap // my $base = '/usr/share/libpve-http-server-perl'; diff --git a/www/Makefile b/www/Makefile index 2f063f842..8cca37f6d 100644 --- a/www/Makefile +++ b/www/Makefile @@ -1,3 +1,9 @@ +include ../defines.mk + +IMAGES := \ + images/logo-128.png \ + images/proxmox_logo.png + JSSRC= \ Utils.js \ Logo.js \ @@ -24,3 +30,11 @@ js/proxmox-backup-gui.js: js OnlineHelpInfo.js ${JSSRC} clean: find . -name '*~' -exec rm {} ';' rm -rf js + +install: js/proxmox-backup-gui.js + install -dm755 $(DESTDIR)$(JSDIR) + install -dm755 $(DESTDIR)$(JSDIR)/js + install -m644 js/proxmox-backup-gui.js $(DESTDIR)$(JSDIR)/js/ + install -dm755 $(DESTDIR)$(JSDIR)/images + $(foreach i,$(IMAGES), \ + install -m644 $(i) $(DESTDIR)$(JSDIR)/images/ ;)