~gbmor/clinte

a69f61ca987afe9c9f4bc7ca03032b68ee99a55f — Benjamin Morrison a month ago e7544b9
moved makefile install target to shellscript

Testing for OS before decided what group to assign to binary and
files. If Linux, both groups are 'root'. If OpenBSD, the groups
are 'bin' and 'wheel'. I don't have a FreeBSD or NetBSD system
handy right now to check those.
2 files changed, 45 insertions(+), 26 deletions(-)

M Makefile
A install.sh
M Makefile => Makefile +1 -26
@@ 14,34 14,9 @@ clean:
	cargo clean
	@printf "\n%s\n" "...Done!"

.PHONY: update
update:
	@printf "\n%s\n" "Making sure we're on master..."
	git checkout master

	@printf "\n%s\n" "Updating from upstream repository..."
	git pull --rebase

	@printf "\n%s\n" "Checking out latest tag..."
	git checkout $(git describe --tags --abbrev=0)

	@printf "\n%s\n" "...Done!"

.PHONY: install
install:
	@printf "\n%s\n" "Installing clinte..."
	@printf "\n%s\n" "Creating directories..."
	mkdir -p $(DBDIR)

	@printf "\n%s\n" "Copying files..."
	install -m755 -o root -g root target/release/clinte $(BINDIR)

	@if [ -f "$(DBDIR)/clinte.json" ]; then printf "\n%s\n" "clinte.json exists. Skipping ..."; else install -m666 -o root -g root clinte.json "$(DBDIR)"; fi
	@if [ -e /etc/profile.d ]; then printf "%s\n" "Installing check_new_clinte_posts.sh to /etc/profile.d" && install -m644 -o root -g root check_new_clinte_posts.sh /etc/profile.d/; fi

	install -m644 -o root -g root clinte.1 $(PREFIX)/share/man/man1/

	@printf "\n%s\n" "...Done!"
	@sh install.sh $(PREFIX)

.PHONY: test
test:

A install.sh => install.sh +44 -0
@@ 0,0 1,44 @@
#!/bin/sh

# This is called in the Makefile.

if [ ! -e 'target/release/clinte' ]; then
    printf '\n%s "%s"\n\n' 'Please build clinte first:' 'make'
    exit 1
fi

PREFIX="$1"
BINDIR="$PREFIX/bin"
DBDIR="$PREFIX/clinte"
OS=$(uname)
BINGRP='root'
FILEGRP='root'

printf '\n%s\n' 'Installing clinte...'
printf '\n%s\n' 'Creating directories...'

mkdir -p "$DBDIR"

printf '\n%s\n' 'Copying files...'

if [ "$OS" = 'OpenBSD' ]; then
    BINGRP='bin'
    FILEGRP='wheel'
fi

install -m755 -o root -g "$BINGRP" target/release/clinte "$BINDIR"

if [ -f "$DBDIR/clinte.json" ]; then
    printf '\n%s\n' 'clinte.json exists. Skipping ...'
else 
    install -m666 -o root -g "$FILEGRP" clinte.json "$DBDIR"
fi

if [ -e /etc/profile.d ]; then
    printf '%s\n' 'Installing check_new_clinte_posts.sh to /etc/profile.d'
    install -m644 -o root -g "$FILEGRP" check_new_clinte_posts.sh /etc/profile.d/
fi

install -m644 -o root -g "$FILEGRP" clinte.1 "$PREFIX/share/man/man1/"

printf '\n%s\n' '...Done!'
\ No newline at end of file