File: rclink2file.sh

package info (click to toggle)
file-rc 0.8.18
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 328 kB
  • ctags: 41
  • sloc: sh: 2,062; makefile: 46
file content (126 lines) | stat: -rwxr-xr-x 2,897 bytes parent folder | download | duplicates (3)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#! /bin/sh

# rclink2file - Convert old style /etc/rc?.d link structure
# Copyright (C) 1998       Martin Schulze <joey@debian.org>
# Copyright (C) 1999-2004  Roland Rosenfeld <roland@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 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.

# The functions element() and unique() are based on functions
# written by Winfried Trmper <winni@xpilot.org>

element() {
    local element i

    element="$1"; shift
	
    [ "$1" = "in" ] && shift
    [ "$1" = "-" ] && return 1
    [ "$1" = "*" ] && return 0

    for i in $*
    do
	if [ "$element" = "$i" ]
	then
	    return 0
	fi
    done
    return 1
}

unique() {
    local level_set i
    level_set="$1 "
    [ -z "$1" ] || shift

    for i in $*
    do
	if ! element $i in $level_set
	then
	    level_set="$level_set$i "
	fi
    done
    echo $level_set
}

cat <<EOF
# This file was automatically generated by $0.
# You can use your favourite editor or update-rc.d(8) to modify it.
# Read runlevel.conf(5) man page for more information about this file.
#
# Format:
# <sort> <off-> <on-levels>     <command>
EOF

(cat <<EOF
05	-	1		/etc/init.d/single
EOF
for script in /etc/init.d/* /usr/local/etc/init.d/*
do
    [ -x $script ] || continue
    filename=${script##*/}
# halt | reboot
    case $filename in
	boot | single | modules | *dist | *orig | skeleton | \
	rc | rcS | README | functions | powerfail | *.dpkg* | *.OLD)
	    continue
	    ;;
    esac
    seqs=""
    for link in /etc/rc[0-6S].d/[KS]??$filename
    do
	if [ -f $link ]
	then
	    nr=${link#/etc/rc?.d/[KS]}
	    nr=${nr%$filename}
	    seqs="$seqs$nr "
	fi
    done
    seqs=`unique $seqs`
    for seq in $seqs
    do
	STOP=""; START=""
	for link in /etc/rc[0-6S].d/K$seq$filename
	do
	    if [ -f $link ]
	    then
		nr=${link#/etc/rc}
		nr=${nr%.d/K$seq$filename}
		STOP=$STOP$nr,
	    fi
	done
	STOP=${STOP%%,}
	[ -z "$STOP" ] && STOP="-"

	for link in /etc/rc[0-6S].d/S$seq$filename
	do
	    if [ -f $link ]
	    then
		nr=${link#/etc/rc}
		nr=${nr%.d/S$seq$filename}
		START=$START$nr,
	    fi
	done
	START=${START%%,}
	[ -z "$START" ] && START="-"

	if [ "$START" != "-" -o "$STOP" != "-" ]
	then
	    echo "$seq	$STOP	$START		/etc/init.d/$filename"
	fi

    done
done) | sort -n
echo "# THE LAST LINE IS NEVER READ"