summaryrefslogtreecommitdiff
path: root/update-rc.d
blob: a013fe24ae33a2aea37b43daeceae66c8c95cabc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/sh
#
# Copyright 2008 Hands.com Ltd <phil@hands.com>
# Copyright 2008 Neil Williams <codehelp@debian.org>
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 3 of the License, or
#  (at your option) any later version.

initd="/etc/init.d"
etcd="/etc/rc.d"
bn=$1;shift
if [ "$bn" = '-f' ]; then
	bn=$1
	shift
fi

defaults () {
	makelinks "S${1:-20}"
	makelinks "K${2:-${1:-20}}"
}

makelinks () {
	echo " Adding symlink for $initd/$bn ...";
	echo "${etcd}/${1}${bn} -> ../init.d/$bn"
	ln -s "../init.d/$bn" "${etcd}/${1}${bn}"
}

if [ -z "$bn" -o -z "$1" ]; then
	echo "Insufficient arguments"
	exit 1
fi
if [ ! -f "$initd/$bn" ]; then
	echo "update-rc.d: $initd/$bn: file does not exist"
	echo
	exit 1
fi
if [ "$1" = 'remove' ]; then
	shift
	echo "rm -f /etc/rc.d/*${bn}"
	rm -f "/etc/rc.d/*${bn}"
	exit;
elif [ "$1" = 'defaults' ]; then
	makelinks "S${2:-20}"
	makelinks "K${3:-${2:-20}}"
	exit 0;
else
	if [ "$1" = 'start' ]
	then
		shift
		num=$1
		# use two digit prefixes
		if [ $num -lt 10 ]; then
			num="0${num}"
		fi
		makelinks "S${num}"
		while [ "$1" != "." ]
		do
			shift
		done
		shift
		if [ "$1" = 'stop' ]; then
			shift
			makelinks "K${1}"
		fi
	fi
	exit 0;
fi