Deprecate home bootopion, drop mkpersistenthome.
[grml-autoconfig.git] / sbin / grml-autoconfig
1 #!/bin/bash
2 # Filename:      grml-autoconfig
3 # Purpose:       configuration interface for grml-autoconfig
4 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika(at)grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2.
7 ################################################################################
8
9 if [ $(id -u) != 0 ] ; then
10   echo "Error: please run this script with uid 0 (root)." ; exit 1
11 fi
12
13 LANG=C
14 LC_ALL=C
15 PN="$(basename $0)"
16 TMPFILE="$(mktemp)"
17
18 AUTOCONFIG=/etc/grml/autoconfig
19 [ -r $AUTOCONFIG ] || exit 1
20
21 . $AUTOCONFIG
22
23 # helper functions
24 activate_value()
25 {
26   check_entry $1
27   sed -i "s/$1.*/$1'yes'/" ${CONFIG_AUTOCONFIG_LOCAL}
28 }
29
30 deactivate_value()
31 {
32   check_entry $1
33   sed -i "s/$1.*/$1'no'/" ${CONFIG_AUTOCONFIG_LOCAL}
34 }
35
36 check_setting()
37 {
38   grep -q $* $TMPFILE && return 0 || return 1
39 }
40
41 check_entry()
42 {
43   if ! grep -q ${1} ${CONFIG_AUTOCONFIG_LOCAL} 2>/dev/null ; then
44     grep $1 ${AUTOCONFIG} >> ${CONFIG_AUTOCONFIG_LOCAL}
45   fi
46 }
47
48 is_set()
49 {
50     [ $1 = 'yes' ] && return 0 || return 1
51 }
52 check_current_state()
53 {
54   is_set $CONFIG_DHCP       && DHCPSTATUS=ON     || DHCPSTATUS=OFF
55   if [ "$(grep '^auto' /etc/network/interfaces | sed 's/ lo// ; s/auto// ; s/ //g')" != "" ] ; then
56      DHCPSTATUS=OFF
57   fi
58   is_set $CONFIG_FSTAB      && FSTABSTATUS=ON    || FSTABSTATUS=OFF
59   is_set $CONFIG_CPU        && CPUSTATUS=ON      || CPUSTATUS=OFF
60   is_set $CONFIG_ACPI_APM   && ACPI_APMSTATUS=ON || ACPI_APMSTATUS=OFF
61   is_set $CONFIG_SYSLOG     && SYSLOGSTATUS=ON   || SYSLOGSTATUS=OFF
62   is_set $CONFIG_GPM        && GPMSTATUS=ON      || GPMSTATUS=OFF
63 }
64
65 # main program
66 interface()
67 {
68   dialog --cr-wrap --clear --cancel-label "Exit" --title "$PN" --checklist "grml-autoconfig is the framework which includes hardware
69 detection, activation of system services and this is the
70 interface to activate or deactivate some features.
71
72 If you do not know what to do at this stage just leave it untouched,
73 the defaults represent the recommended values.
74
75 All the configuration happens in the file /etc/grml/autoconfig.local -
76 you can edit the file manually as well.
77
78 Please do not confuse these settings with plain Debian configuration.
79 For example disabling dhcp here will NOT deactivate any configured network
80 settings in /etc/network/interfaces, it just configures grml-autoconfig
81 related settings instead.
82 " 0 0 0 \
83 dhcp "check for network devices and run pump (get ip-address via DHCP)" $DHCPSTATUS \
84 fstab "update /etc/fstab entries (check for devices)" $FSTABSTATUS \
85 cpufreq "activate cpydyn/powernowd for frequency-scalable CPUs" $CPUSTATUS \
86 acpi_apm "load ACPI/APM modules" $ACPI_APMSTATUS \
87 syslog "start syslog-ng" $SYSLOGSTATUS \
88 gpm "start GPM (mouse on console)" $GPMSTATUS \
89   2>$TMPFILE
90 }
91
92 set_values()
93 {
94   check_setting dhcp      && activate_value CONFIG_DHCP=     || deactivate_value CONFIG_DHCP=
95   check_setting fstab     && activate_value CONFIG_FSTAB=    || deactivate_value CONFIG_FSTAB=
96   check_setting cpufreq   && activate_value CONFIG_CPU=      || deactivate_value CONFIG_CPU=
97   check_setting acpi_apm  && activate_value CONFIG_ACPI_APM= || deactivate_value CONFIG_ACPI_APM=
98   check_setting syslog    && activate_value CONFIG_SYSLOG=   || deactivate_value CONFIG_SYSLOG=
99   check_setting gpm       && activate_value CONFIG_GPM=      || deactivate_value CONFIG_GPM=
100 }
101
102 # and now run it:
103   check_current_state
104   interface
105   retval=$?
106   case $retval in
107    0)
108     set_values && dialog --stdout --title "${PN}" --msgbox "Adjusting values via grml-autoconfig was successful!" 5 60 || \
109     dialog --stdout --title "${PN}" --msgbox "There was an error adjusting values via grml-autoconfig. Sorry." 5 60
110     rm -f $TMPFILE &>/dev/null
111     ;;
112    1)
113     echo "Exit pressed."
114     ;;
115    255)
116     echo "ESC pressed."
117     exit 1
118     ;;
119   esac
120
121 ## END OF FILE #################################################################