merged grml-quickconfig nonblocking branch
[grml-scripts.git] / usr_sbin / grml-setservices
1 #!/bin/sh
2 # Filename:      grml-setservices
3 # Purpose:       interface for basic configuration of system startup
4 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2.
7 # Latest change: Mit Jul 25 18:34:57 CEST 2007 [mika]
8 ################################################################################
9
10 PN="$(basename $0)"
11 TMP=$(mktemp)
12 DIALOG=dialog
13 CONFFILE='/etc/runlevel.conf'
14
15 . /etc/grml/script-functions
16 . /etc/grml/lsb-functions
17
18 check4root || exit 100
19
20 bailout(){
21   rm -f "$TMP"
22   exit 0
23 }
24
25 trap bailout 1 2 3 15
26
27 is_value_set(){
28  [ -n "$1" ] || return 2
29  [ -r "$TMP" ] || return 3
30  grep -q "$1" $TMP && return 0 || return 1
31 }
32
33 INFO="Which services would you like to have enabled on your system?
34
35 Notice: this script will adjust your ${CONFFILE}, the
36 file which provides the startup configuration for your
37 system. You can edit the file manually as well.
38
39 If you do not know what to choose just take the defaults
40 or choose cancel.
41 "
42
43 # enable checks only if the according init script is present
44 [ -r /etc/init.d/lvm2 ]   && LVM='lvm!logical volume management!on'
45 [ -r /etc/init.d/mdadm ]  && SRAID='mdadm!software-raid via mdadm!on'
46 [ -r /etc/init.d/dmraid ] && MRAID='dmraid!software-raid via dmraid!off'
47 [ -r /etc/init.d/dbus -o -r /etc/init.d/dbus-1 ] && DBUS='dbus!hal/dbus (important for KDE e.g.)!off'
48 [ -r /etc/init.d/hal ]    && HAL='hal!Hardware Abstraction Layer daemon (important for KDE e.g.)!off'
49 [ -r /etc/init.d/nfs-common ] && NFS='nfs!Network File System (client setup)!off'
50
51 ## adjust setup
52 # logic:
53 # if is_value_set
54 #    remove_from_runlevel.conf
55 #    set_up_defaults_as_intented_in_/var/lib/dpkg/info/$PACKAGE.postinst
56 # else
57 #    remove_from_runlevel.conf
58 #    set_up_only_for_stop_to_prevent_reactivation_via_maintainer_scripts_on_upgrade
59 set_values(){
60   if [ -n "$LVM" ] ; then
61      if is_value_set "lvm" ; then
62         update-rc.d -f lvm2 remove >/dev/null 2>&1
63         update-rc.d lvm2 start 26 S . start 50 0 6 .
64      else
65         update-rc.d -f lvm2 remove >/dev/null 2>&1
66         update-rc.d lvm2 stop 20 0 1 6 . >/dev/null 2>&1
67      fi
68   fi
69
70   if [ -n "$SRAID" ] ; then
71      if is_value_set "mdadm"  ; then
72         update-rc.d -f mdadm remove >/dev/null 2>&1
73         update-rc.d mdadm-raid start 25 S . start 50 0 6 . >/dev/null 2>&1
74         update-rc.d mdadm defaults 25 >/dev/null 2>&1
75      else
76         update-rc.d -f mdadm remove >/dev/null 2>&1
77         update-rc.d mdadm stop 20 0 1 6 . >/dev/null 2>&1
78         update-rc.d -f mdadm-raid remove >/dev/null 2>&1
79         update-rc.d mdadm-raid stop 20 0 1 6 . >/dev/null 2>&1
80      fi
81   fi
82
83   if [ -n "$MRAID" ] ; then
84      if is_value_set "dmraid" ; then
85         update-rc.d -f dmraid remove >/dev/null 2>&1
86         update-rc.d dmraid start 04 S . start 51 0 6 . >/dev/null
87      else
88         update-rc.d -f dmraid remove >/dev/null 2>&1
89         update-rc.d dmraid stop 20 0 1 6 . >/dev/null 2>&1
90      fi
91   fi
92
93   if [ -n "$DBUS" ] ; then
94      if is_value_set "dbus" ; then
95         update-rc.d -f dbus remove >/dev/null 2>&1
96         update-rc.d dbus defaults >/dev/null 2>&1
97      else
98         update-rc.d -f dbus remove >/dev/null 2>&1
99         update-rc.d dbus stop 20 0 1 6 . >/dev/null 2>&1
100      fi
101   fi
102
103   if [ -n "$HAL" ] ; then
104      if is_value_set "hal" ; then
105         update-rc.d -f hal remove >/dev/null 2>&1
106         update-rc.d hal start 24 2 3 4 5. stop 16 0 1 6 . >/dev/null 2>&1
107      else
108         update-rc.d -f hal remove >/dev/null 2>&1
109         update-rc.d hal stop 20 0 1 6 . >/dev/null 2>&1
110      fi
111   fi
112
113   if [ -n "$NFS" ] ; then
114      if is_value_set "nfs" ; then
115         update-rc.d -f nfs-common remove >/dev/null 2>&1
116         update-rc.d nfs-common start 20 2 3 4 5 . stop 20 0 1 6 . start 44 S . >/dev/null 2>&1
117      else
118         update-rc.d -f nfs-common remove >/dev/null 2>&1
119         update-rc.d nfs-common stop 20 0 1 6 . >/dev/null 2>&1
120      fi
121   fi
122 }
123
124 # the interface itself
125 oifs="$IFS"
126 IFS='!'
127 $DIALOG --title "$PN" --checklist "$INFO" 30 65 8 $LVM $SRAID $MRAID $DBUS $HAL $NFS 2>$TMP
128
129 retval="$?"
130 case $retval in
131     (0)   set_values ;;
132     (1)   echo "Cancel pressed." ; exit 1 ;;
133     (255) echo "ESC pressed."    ; exit 1 ;;
134 esac
135
136 retval=$?
137 case $retval in
138     (0)
139           $DIALOG --title "$PN" --stdout --msgbox "Adjusting system runlevel configuration via $CONFFILE was successful." 0 0
140           esyslog user.notice "$PN" "Writing language settings ($LANGUAGE) to $CONFFILE was successful."
141           ;;
142     *)
143           $DIALOG --title "$PN" --stdout --msgbox "Error writing settings to ${CONFFILE}." 0 0
144           esyslog user.notice "$PN" "Error writing settings to ${CONFFILE}."
145           ;;
146 esac
147
148 rm -f $TMP
149 IFS="$oifs"
150
151 ## END OF FILE #################################################################
152 # vim: ai tw=80 expandtab