* updated krdc (21.12.1 -> 21.12.2), untested
[t2-trunk.git] / package / base / stone / stone_mod_runlevel.sh
blob466cd5dca6d7a23e937ff08ac990600a0120da4d
1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
3 #
4 # T2 SDE: package/.../stone/stone_mod_runlevel.sh
5 # Copyright (C) 2004 - 2005 The T2 SDE Project
6 # Copyright (C) 1998 - 2003 ROCK Linux Project
7 #
8 # More information can be found in the files COPYING and README.
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; version 2 of the License. A copy of the
13 # GNU General Public License can be found in the file COPYING.
14 # --- T2-COPYRIGHT-NOTE-END ---
16 # [MAIN] 80 runlevel Runlevel Configuration (Services)
18 # Remove dead symlinks
19 for x in /etc/rc.d/rc[0-6].d/* ; do
20 [ -L "$x" -a ! -e "$x" ] && rm -f "$x"
21 done
23 chrlv() {
24 local srv=$1 rl=$2 pri=$3
25 if [ ! -e /etc/rc.d/rc$rl.d/S??$srv ]
26 then
27 ln -sf ../init.d/$srv /etc/rc.d/rc$rl.d/S$pri$srv
28 kpr=`printf "%02d" $(( 100 - $pri ))`
29 ln -sf ../init.d/$srv /etc/rc.d/rc$rl.d/K$kpr$srv
30 else
31 rm -f /etc/rc.d/rc$rl.d/[SK]??$srv
35 chpri() {
36 local srv=$1 pri=$2
38 gui_input "Changing priority for service $1" "$pri" pri
40 if [ ! -z "${pri#[0-9][0-9]}" ]
41 then
42 gui_message "The value you entered is not valid."
43 return
46 rm -f /etc/rc.d/rcX.d/X??$srv
47 echo "The script '$srv' has the priority $pri." \
48 > /etc/rc.d/rcX.d/X$pri$srv
50 for x in 0 1 2 3 4 5 6 ; do
51 if [ -e /etc/rc.d/rc$x.d/S??$srv ] ; then
52 rm -f /etc/rc.d/rc$x.d/[SK]??$srv
53 ln -sf ../init.d/$srv /etc/rc.d/rc$x.d/S$pri$srv
54 kpr=`printf "%02d" $(( 100 - $pri ))`
55 ln -sf ../init.d/$srv /etc/rc.d/rc$x.d/K$kpr$srv
57 done
60 edit_srv() {
61 local srv=$1 id="runlevel_$RANDOM" cmd=""
63 while
64 cmd="gui_menu $id 'Runlevel Editor - $srv'"
65 pri=`ls /etc/rc.d/rc?.d/[SX]??$srv 2> /dev/null | \
66 cut -c18-19 | head -n 1`
67 [ -z "$pri" ] && pri=99
69 for rl in 1 2 3 4 5 ; do
70 if [ -e /etc/rc.d/rc$rl.d/S??$srv ]
71 then cmd="$cmd '[*] " ; else cmd="$cmd '[ ] " ; fi
72 cmd="$cmd Run this script in runlevel $rl'"
73 cmd="$cmd 'chrlv $srv $rl $pri'"
74 done
76 cmd="$cmd '$pri This scripts priority (01-99)'"
77 cmd="$cmd 'chpri $srv $pri' '' ''"
79 cmd="$cmd 'Edit /etc/rc.d/init.d/$srv script'"
80 cmd="$cmd \"gui_edit 'SysV Init Script $srv'"
81 cmd="$cmd /etc/rc.d/init.d/$srv\""
82 cmd="$cmd \"(Re-)Start the '$srv' system service\""
83 cmd="$cmd '$STONE runlevel restart $srv'"
84 eval "$cmd"
85 do : ; done
88 restart() {
89 gui_cmd "(Re-)Starting System Service '$1'" \
90 "/sbin/rc $1 stop ; /sbin/rc $1 start"
93 main() {
94 while
95 cmd="gui_menu runlevel 'Runlevel Editor - Select an"
96 cmd="$cmd item to change the priority or runlevels'"
98 x=`mktemp`
99 for srv in $( ls /etc/rc.d/init.d/ )
101 [ -f /etc/rc.d/init.d/$srv ] || continue
103 pri=`ls /etc/rc.d/rc?.d/[SX]??$srv \
104 2> /dev/null | cut -c18-19 | head -n 1`
105 [ -z "$pri" ] && pri=99
107 rlv=''
108 for x in 1 2 3 4 5 ; do
109 if [ -e /etc/rc.d/rc$x.d/S??$srv ]
110 then rlv="${rlv}$x" ; else rlv="${rlv}-" ; fi
111 done
113 desc=`grep '# *Desc:' /etc/rc.d/init.d/$srv | \
114 cut -f2- -d: | tr -d "'" | cut -c1-45`
115 desc="$( printf "%-10s %s" "$srv" "$desc" )"
117 echo "$pri$srv '$pri $rlv $desc' 'edit_srv $srv'"
118 done | sort > $x
119 cmd="$cmd $(cut -f2- -d' ' < $x | tr '\n' ' ')"
120 rm -f $x ; eval "$cmd"
121 do : ; done