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 <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2019-01-31 13:43:09 +01:00
parent 9fa03fa2d3
commit 6285b251e7
12 changed files with 119 additions and 45 deletions

View File

@ -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

10
debian/install vendored
View File

@ -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/

View File

@ -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

View File

@ -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

2
debian/rules vendored
View File

@ -7,6 +7,8 @@
%:
dh $@ --with=systemd --with=bash-completion
override_dh_autobuild:
make PROXY_USER=www-data
override_dh_installinit:
dh_installinit

13
defines.mk Normal file
View File

@ -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

18
etc/Makefile Normal file
View File

@ -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 $@

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -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';

View File

@ -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/ ;)