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