www.nico.schottelius.org/software/cinit/browse_source/cinit-0.3pre2/bin/cinit.add.dependency

52 lines
1.2 KiB
Text
Raw Normal View History

#!/bin/sh
# Nico Schottelius
# cinit: create dependency: service a needs or wants service b
# init variables
. $(dirname $0)/cinit.read-conf
BASEDIR=$DESTDIR/$CINIT_DIR
if [ $# -ne 3 ]; then
echo "`basename $0`: service_A [wants|needs] service_B"
echo ""
echo " Service A needs or wants Service B."
echo " Use relative paths, not absolute."
echo " You must specify whether to use wants or needs."
echo ""
exit 23
fi
SVC_A=$1
DEP=$2
SVC_B=$3
# adding 'wishes' for x-mas and requires for 'the mass' and 'tv'
case $DEP in
wishes|wants) DEP=$C_WANTS ;;
needs|requires) DEP=$C_NEEDS ;;
*) echo "Did not I say \"want\" or \"need\"? You _must_ use those terms."
esac
# FIXME: could someone PLEASE simply that?
SLASHES=$(echo $SVC_A | sed -e 's,/$,,' -e 's,[^/],,g' -e 's,/,../,g' -e 's,^,../../,')
DEST_NAME=$(echo $SVC_B | sed -e 's,/$,,' -e 's,/,-,g')
SOURCE="${SLASHES}${SVC_B}"
DEP_DIR="${BASEDIR}/${SVC_A}/${DEP}"
if [ ! -d "$DEP_DIR" ]; then
echo "$DEP_DIR does not exist, creating..."
mkdir "$DEP_DIR"
if [ $? -ne 0 ]; then
echo "Error occured due to creating directory. Exiting."
exit 1
fi
fi
DEST="${DEP_DIR}/${DEST_NAME}"
echo -n "Linking $SOURCE to $DEST ... "
ln -sf "$SOURCE" "$DEST"
echo "finished."