Debian Codegraph @

setup/files/DBN/DBN12.0/firstboot.DBN12.0.drbl

raw
1 #!/bin/bash
2 #
3 # firstboot: Starts the firstboot druid if it hasn't been run before
4 # If /etc/reconfigSys exists, run the reconfiguration
5 # program and remove /etc/reconfigSys when done.
6 # Also will run if 'reconfig' is on the kernel cmdline.
7 #
8 # Modified by Steven Shiau <steven _at_ clonezilla org> to use this in
9 # DRBL for Debian/Ubuntu.
10 #
11 # To avoid there is no input output in rc running, we add this one:
12 #exec </dev/console >/dev/console 2>&1
13
14 # Load DRBL setting and functions
15 DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"
16
17 . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
18
19 # We can not use runlevel to get the runlevel, since this service is still in
20 # rcS.d
21 #RL="$(runlevel | awk -F" " '{print $2}')"
22 # We have to filter the ocs_opt in /proc/cmdline to avoid some options, like -b or 1 inside it, which init will think it's emergency mode or other mode
23 pure_cmdline="$(sed -e "s/ocs_opt=\".*\"//g" /proc/cmdline)"
24 if [ -n "$(echo $pure_cmdline | grep -w -- "-s\|single\|S\|1")" ]; then
25 echo "We will be in runlevel 1, skip firstboot!"
26 exit 0
27 fi
28 #
29 if [ ! -e /etc/X11/X ]; then
30 echo "No X program! Skip firstboot!"
31 exit 0
32 elif [ ! -e /etc/init.d/gdm -a \
33 ! -e /etc/init.d/kdm -a \
34 ! -e /etc/init.d/xdm ]
35 then
36 echo "No gdm/kdm/xdm! Skip firstboot!"
37 exit 0
38 fi
39
40 # functions
41 set_priority() {
42 echo '*****************************************************'
43 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
44 echo "Which mode do you want when configuring X ?"
45 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
46 echo "0: Beginner mode, use whatever the default priority of question is."
47 echo "1: Medium mode."
48 echo "2: Expert mode, very verbose."
49 echo "NOTE: If X-window fails to start, you can run \"/etc/init.d/firstboot restart\" to configure it again."
50 echo -n "[0] "
51 read ans_ver
52 case "$ans_ver" in
53 # Beginner means only ask high priority question
54 # Expert means ask low priority question
55 1) PRIORITY="medium" ;;
56 2) PRIORITY="low" ;;
57 *) PRIORITY="high" ;;
58 esac
59 } # end of set_prority
60 #
61 reconfig_XF86() {
62 echo "X is not configured. Running dpkg-reconfigure xserver-xfree86"
63 set_priority
64 # We need /etc/X11/XF86Config-4 so that dpkg-reconfigure can create
65 # /etc/X11/XF86Config-4.
66 # /etc/X11/XF86Config-4.drbl.template is prepared by drblpush.
67 cp -af /etc/X11/XF86Config-4.drbl.template /etc/X11/XF86Config-4
68 md5sum /etc/X11/XF86Config-4 > /var/lib/xfree86/XF86Config-4.md5sum
69 LC_ALL=C dpkg-reconfigure --priority=$PRIORITY xserver-xfree86
70 echo "X is now configured."
71 } # end of reconfig_XF86
72 #
73 reconfig_Xorg() {
74 echo "X is not configured. Running dpkg-reconfigure xserver-xorg"
75 set_priority
76 # We need /etc/X11/xorg.conf so that dpkg-reconfigure can create
77 # /etc/X11/xorg.conf.
78 # /etc/X11/xorg.conf.drbl.template is prepared by drblpush.
79 cp -af /etc/X11/xorg.conf.drbl.template /etc/X11/xorg.conf
80 # For Sarge, Breezy, the xorg.conf.md5sum is in /var/lib/xfree86/
81 # For Dapper, the xorg.conf.md5sum is in /var/lib/x11/
82 if [ -d /var/lib/xfree86 ]; then
83 varx11=xfree86
84 elif [ -d /var/lib/x11 ]; then
85 varx11=x11
86 fi
87 md5sum /etc/X11/xorg.conf > /var/lib/$varx11/xorg.conf.md5sum
88 LC_ALL=C dpkg-reconfigure --priority=$PRIORITY xserver-xorg
89 echo "X is now configured."
90 } # end of reconfig_Xorg
91 #
92 run_config() {
93 if grep -i reconfig /proc/cmdline >/dev/null || [ -f /etc/reconfigSys ]; then
94
95 echo -n "Forced to re-configure X. Running dpkg-reconfigure..."
96 if [ -f /etc/X11/XF86Config-4.drbl.template ]; then
97 reconfig_XF86
98 elif [ -f /etc/X11/xorg.conf.drbl.template ]; then
99 reconfig_Xorg
100 fi
101 rm -f /etc/reconfigSys
102 exit 0
103 fi
104
105 if [ -n "$(ls /etc/rc2.d/S[0-9][0-9][kgx]dm 2>/dev/null)" ]; then
106 if [ ! -f /etc/X11/XF86Config-4 -a -f /etc/X11/XF86Config-4.drbl.template ] ; then
107 reconfig_XF86
108 elif [ ! -f /etc/X11/xorg.conf -a -f /etc/X11/xorg.conf.drbl.template ] ; then
109 reconfig_Xorg
110 fi
111 else
112 echo "No gdm, kdm, or xdm was found in /etc/rc2.d/. Skip X configure."
113 fi
114
115 exit 0
116 } # end of run_config
117
118 #
119 case "$1" in
120 start)
121 if [ -f /etc/X11/xorg.conf.drbl.template ]; then
122 # Ex: ii xserver-xorg 1:7.3+10 the X.Org X server
123 xserver_ver="$(LANG=C dpkg -l xserver-xorg | tail -n 1 | grep "^ii" | awk -F" " '{print $3}' | sed -e "s/^[[:digit:]]*://g")"
124 dpkg --compare-versions "$xserver_ver" ">" "7.2" && echo "X.org is 7.2 or later, skip configuring!" && exit 5
125 fi
126 run_config
127 ;;
128 restart)
129 # Clean the old config first before reconfigure
130 rm -f /etc/X11/xorg.conf /etc/X11/XF86Config-4
131 run_config
132 ;;
133 esac