forked from initng/initng-ifiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
genrunlevel.in
133 lines (113 loc) · 2.4 KB
/
genrunlevel.in
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
127
128
129
130
131
132
133
#!/bin/bash
#
# Search for libgenrunlevel
#
LIB="${0%/*}/libgenrunlevel"
[ -d "${LIB}" ] || LIB="@LIB_INSTALL_DIR@"
LIB="${LIB}/libgenrunlevel"
if [ ! -e "${LIB}" ]; then
echo "ERROR: ${LIB} not found!"
exit 1
fi
#
# Show the help
#
function show_help {
cat >&2 << EOF
USAGE:
${0} [options] [--all | runlevel1 runlevel2 ... runlevelN]
${0} --migrate
${0} --help
options:
--overwrite Overwrite files if they exist.
--path PATH Sets the search path for executables.
--destdir PATH Destination path prefix (default: /).
--confdir PATH Configuration directory (default: /etc/initng).
EOF
}
#
# Load libgenrunlevel
#
. "${LIB}"
migrate=
[ ${#} -eq 0 ] && set -e -- --help
while [ ${#} -gt 0 ]; do
case "${1}" in
--all)
all=true
;;
--overwrite)
overwrite=true
;;
--dist)
shift
dist=${1}
;;
--path)
shift
search_path=${1}
;;
--destdir)
shift
DESTDIR=${1}
;;
--confdir)
shift
CONFDIR=${1}
;;
--help)
show_help
exit 0
;;
--migrate)
migrate=1
;;
--)
shift
break
;;
*)
break
;;
esac
shift
done
[ "${CONFDIR}" ] || CONFDIR="${DESTDIR}/etc/initng"
mkdir -p "${CONFDIR}/runlevel"
if [ -n "${migrate}" ]; then
RUNLEVELDIR="${CONFDIR}/runlevel"
if [ -e "${RUNLEVELDIR}/system.virtual" ]; then
CONFDIR="${RUNLEVELDIR}"
else
install -d -m 755 -o root -g root "${RUNLEVELDIR}"
fi
[ -e "${CONFDIR}/system.virtual" ] || exit 1
for RUNLEVEL_FILE in "${CONFDIR}"/*.{runlevel,virtual}; do
cp "${RUNLEVEL_FILE}"{,.old}
while read SERVICE; do
if [ -e "${CONFDIR}/${SERVICE}.virtual" -o -e "${CONFDIR}/${SERVICE}.runlevel" ]; then
SERVICE="runlevel/${SERVICE}"
elif [ ! -e "${CONFDIR}/${SERVICE}.i" ]; then
NSERVICE="$(find "${CONFDIR}" -name $(basename "${SERVICE}").i | sed -r "s:^${CONFDIR}/(.*)\.i\$:\1:; s:\s::g")"
[ -n "${NSERVICE}" ] && SERVICE="${NSERVICE}"
fi
echo "${SERVICE}"
done < "${RUNLEVEL_FILE}.old" > "${RUNLEVELDIR}/$(basename "${RUNLEVEL_FILE}")"
done
exit 0
fi
[ "${search_path}" ] || search_path=$(echo $(
for dir in $()/bin /sbin /usr/bin /usr/sbin /usr/kde/\*/bin \
/usr/kde/\*/sbin /opt/bin /opt/sbin /opt/\*/bin \
/opt/\*/sbin /usr/local/sbin /usr/local/bin
do [ "$(echo ${dir})" ] && echo ${dir}
done | grep -v '*')
)
[ "${all}" ] && set -- $(get_runlevels)
for l; do
create_list ${l}
done
for rl in ${runlevels}; do
write_runlevel ${rl} > "${CONFDIR}/${rl}"
done
echo "Done generating files."