#!/bin/sh # # rc_add - add an init script to a runlevel # # Copyright (c) 2005 Natanael Copa # # Distributed under GPL-2 # PROGRAM=`basename $0` #load the libraries . /sbin/functions.sh STARTNUM=50 RCDIR="$ROOT/etc/rcL.d" die() { echo "$1" >&2 exit 1 } # print usage and die usage() { echo "$PROGRAM $VERSION" echo "usage: $PROGRAM [-hv] [-s number] script" echo "" echo " -h Show help and exit." echo " -k Also add a corresponding kill link for shutdown/reboot." echo " -s Set two-digit start number (00-99). Default is $STARTNUM." echo " -S Add service as a system init service (rcS.d)." echo " -v Turn on verbose output." echo "" exit 1 } #parse args unset vflag while getopts "hks:Sv" opt ; do case "$opt" in h) usage;; k) KILL="-k";; s) STARTNUM="$OPTARG";; S) RCDIR="ROOT/rcS.d";; v) vflag="-v"; VERBOSE=1 ;; \?) usage;; esac done shift `expr $OPTIND - 1` # check if script is specified [ $# -lt 1 ] && usage while [ $# -gt 0 ] ; do SCRIPT="$1" # validate the start number echo "$STARTNUM" | grep '^[0-9][0-9]$' > /dev/null || die "Start number needs to be a 2 digit number. (00-99)" mkdir -p "$ROOT/$RCDIR" cd "$ROOT/$RCDIR" LINKTARGET="../init.d/$SCRIPT" [ -f "$LINKTARGET" ] || die "Could not find init script $LINKTARGET" SLINK="S$LEVEL$STARTNUM$SCRIPT" [ "$VERBOSE" ] && echo "Creating $ROOT/$RCDIR/$SLINK." ln -sf $LINKTARGET "$ROOT/$RCDIR/$SLINK" || exit $? if [ "$KILL" ] ; then KLINK="K$LEVEL$STARTNUM$SCRIPT" [ "$VERBOSE" ] && echo "Creating $ROOT/etc/rcK.d/$KLINK." mkdir -p "$ROOT/etc/rcK.d" ln -sf $LINKTARGET "$ROOT/etc/rcK.d/$KLINK" || exit $? fi shift done exit 0