view setup @ 32:5348758c622d draft

don't keep file descriptors open Signed-off-by: Changaco <changaco ατ changaco δοτ net>
author Changaco <changaco ατ changaco δοτ net>
date Sun, 05 Aug 2012 14:47:19 +0200
parents 75563016f269
children
line wrap: on
line source

#!/bin/sh

usage () {
	echo "usage: [DESTDIR=/] [PREFIX=/usr] $(basename "$0") install|uninstall|update" && exit 1
}

remove () {
	[ -e "$1" ] && rm -vrf --preserve-root "$1"
}

install_dir () {
	mkdir -p "$2"
	cp -rv "$1" "$2"
}

[ $# -eq 1 ] && action=$1 || usage

[ -z "$DESTDIR" ] && DESTDIR=/
[ -z "$PREFIX" ] && PREFIX=/usr
_PREFIX=${DESTDIR%%/}/${PREFIX##/}

[ ! -w "$DESTDIR" ] && echo "You don't have write access on $DESTDIR" && exit 1

progname=feed-push
confdir="${DESTDIR}etc/$progname"

if [ "$action" == install ]; then
	install -v -m 755 -D $progname "$_PREFIX/bin/$progname"
	install_dir examples "$_PREFIX/share/$progname"
	install -vd "$confdir"
	install -v -m 755 -D init/$progname.bash "${DESTDIR}etc/rc.d/$progname"
	install -v -m 644 -D init/$progname.service "${DESTDIR}usr/lib/systemd/system/$progname.service"
elif [ "$action" == uninstall ]; then
	remove "$_PREFIX/bin/$progname"
	remove "$_PREFIX/share/$progname/examples"
	remove "${DESTDIR}etc/rc.d/$progname"
	if [ $(ls -a "$confdir" | wc -l) -eq 2 ]; then rmdir "$confdir"
	else echo "not removing config dir $confdir (not empty)"
	fi
elif [ "$action" == update ]; then
	$0 uninstall &>/dev/null
	$0 install
else
	usage
fi

exit 0