aboutsummaryrefslogtreecommitdiffstats
path: root/setup.in
blob: 00538d185d34f805eb47cec0602ba6739df9e2c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/bin/sh

set MACHINE=""

if [ -r @appconfdir@/defaults ]; then
	# this provides MACHINE, SUPPORTED_MACHINES and DEFAULT_MACHINE_SELECTION variables
	. @appconfdir@/defaults
fi

OLDMACHINE="${MACHINE}"

read KERNEL_COMMAND_LINE < /proc/cmdline
for i in $KERNEL_COMMAND_LINE; do
        case $i in
        target_machine=*)
		MACHINE="`echo $i | sed "s/^target_machine=//"`"
                ;;
        esac
done

if [ "${MACHINE}" = "" ]; then
	# do not change anything on the target image
	exit 0
fi

# Check weather the specified machine is a supported one
VALID_MACHINE=0
if [ "${MACHINE}" != "ask" ]; then
	for m in ${SUPPORTED_MACHINES}; do
		if ( [ "${m}" = "${MACHINE}" ] && [ -r "@appconfdir@/config/${MACHINE}/${MACHINE}.vars" ] ); then
			VALID_MACHINE=1
		fi
	done

	if ( [ "${MACHINE}" = "detect" ] || [ "${MACHINE}" = "detect-ask" ] || [ "${VALID_MACHINE}" != "1" ] ); then
		. @appconfdir@/scripts/detect-machine
	fi
fi

for m in ${SUPPORTED_MACHINES}; do
	if ( [ "${m}" = "${MACHINE}" ] && [ -r "@appconfdir@/config/${MACHINE}/${MACHINE}.vars" ] ); then
		VALID_MACHINE=1
	fi
done

if ( [ "${MACHINE}" = "ask" ] || [ "${MACHINE}" = "detect-ask" ] || [ "${VALID_MACHINE}" != "1" ] ); then
	. @appconfdir@/scripts/machine-selection-menu
fi

if [ -z "${MACHINE}" ]; then
	echo "Target machine is not set. Previous machine configuration is preserved."
	exit
fi

if [ -r "@appconfdir@/config/${MACHINE}/${MACHINE}.vars" ]; then
	. @appconfdir@/config/${MACHINE}/${MACHINE}.vars
fi

if [ "$OLDMACHINE" != "$MACHINE" ]; then
	rm -f @sysconfdir@/formfactor/machconfig
	if [ -f "@appconfdir@/config/${MACHINE}/${FORMFACTOR_FILE}" ]; then
		 cp -f @appconfdir@/config/${MACHINE}/${FORMFACTOR_FILE} @sysconfdir@/formfactor/machconfig
	fi

	if [ -w @sysconfdir@/pulse/default.pa ]; then
		sed "/^set-default-sink.*$/d" -i @sysconfdir@/pulse/default.pa
		if [ -n "${PULSEAUDIO_DEFAULT_SINK}" ]; then
			echo "set-default-sink ${PULSEAUDIO_DEFAULT_SINK}" >> @sysconfdir@/pulse/default.pa
		fi
		sed "/^set-default-source.*$/d" -i @sysconfdir@/pulse/default.pa
		if [ -n "${PULSEAUDIO_DEFAULT_SOURCE}" ]; then
			echo "set-default-source ${PULSEAUDIO_DEFAULT_SOURCE}" >> @sysconfdir@/pulse/default.pa
		fi
	fi

	rm -f @sysconfdir@/asound.conf
	if [ -f "@appconfdir@/config/${MACHINE}/${ALSA_CONFIG_FILE}" ]; then
		 cp -f @appconfdir@/config/${MACHINE}/${ALSA_CONFIG_FILE} @sysconfdir@/asound.conf
	fi

	rm -f /var/lib/alsa/asound.state
	if [ -f "@appconfdir@/config/${MACHINE}/${ALSA_STATE_FILE}" ]; then
		cp -f @appconfdir@/config/${MACHINE}/${ALSA_STATE_FILE} /var/lib/alsa/asound.state
	fi

	rm -f @sysconfdir@/X11/xorg.conf
	if [ -f "@appconfdir@/config/${MACHINE}/${XORG_CONFIG_FILE}" ]; then
		cp -f @appconfdir@/config/${MACHINE}/${XORG_CONFIG_FILE} @sysconfdir@/X11/xorg.conf
	fi

	rm -f @sysconfdir@/network/interfaces
	if [ -f "@appconfdir@/config/${MACHINE}/${NETWORK_INTERFACES_FILE}" ]; then
		cp -f @appconfdir@/config/${MACHINE}/${NETWORK_INTERFACES_FILE} @sysconfdir@/network/interfaces
	fi

	rm -f @sysconfdir@/pointercal
	if [ -f "@appconfdir@/config/${MACHINE}/${POINTERCAL_FILE}" ]; then
		cp -f @appconfdir@/config/${MACHINE}/${POINTERCAL_FILE} @sysconfdir@/pointercal
	fi

	rm -f @sysconfdir@/pointercal.xinput
	if [ -f "@appconfdir@/config/${MACHINE}/${XINPUT_POINTERCAL_FILE}" ]; then
		cp -f @appconfdir@/config/${MACHINE}/${XINPUT_POINTERCAL_FILE} @sysconfdir@/pointercal.xinput
	fi

	# Autoload kernel modules
	rm -f @sysconfdir@/modules-load.d/autoload.conf
	for mod in ${AUTOLOAD_KERNEL_MODULES}; do
		echo ${mod} >> @sysconfdir@/modules-load.d/autoload.conf
	done

	# Prohibit undesired kernel modules
	rm -f @sysconfdir@/modprobe.d/prohibit.conf
	for mod in ${PROHIBIT_KERNEL_MODULES}; do
		echo blacklist ${mod} >> @sysconfdir@/modprobe.d/prohibit.conf
	done

	# kernel boot parameters
	EXTRA_KERNEL_PARAMETERS_SED=`echo " :mst-begin ${EXTRA_KERNEL_PARAMETERS} mst-end: " | sed 's#/#\\/#g'`
	if [ -w /media/realroot/syslinux.cfg ]; then
		sed "s/ :mst-begin .* mst-end: / /" -i /media/realroot/syslinux.cfg
		if [ -n "${EXTRA_KERNEL_PARAMETERS}" ]; then
			sed "/^APPEND/{s/$/${EXTRA_KERNEL_PARAMETERS_SED}/}" -i /media/realroot/syslinux.cfg
		fi
	fi
	if [ -w /media/realroot/EFI/BOOT/grub.cfg ]; then
		sed "s/ mst-begin .* mst-end / /" -i /media/realroot/EFI/BOOT/grub.cfg
		if [ -n "${EXTRA_KERNEL_PARAMETERS}" ]; then
			sed "/^linux /{s/$/${EXTRA_KERNEL_PARAMETERS_SED}/}" -i /media/realroot/EFI/BOOT/grub.cfg
		fi
	fi

	# syslinux serial port config
	if [ -w /media/realroot/syslinux.cfg ]; then
		sed "/^serial.*$/d" -i /media/realroot/syslinux.cfg
		sed "/^SERIAL.*$/d" -i /media/realroot/syslinux.cfg
		if [ -n "${SYSLINUX_SERIAL_CONFIG}" ]; then
			SYSLINUX_SERIAL_CONFIG_SED=`echo "${SYSLINUX_SERIAL_CONFIG}" | sed 's#/#\\/#g'`
			sed "1i${SYSLINUX_SERIAL_CONFIG_SED}" -i /media/realroot/syslinux.cfg
		fi
	fi
	
	# grub serial port config
	if [ -w /media/realroot/EFI/BOOT/grub.cfg ]; then
		sed "/^serial.*$/d" -i /media/realroot/EFI/BOOT/grub.cfg
		sed "/^SERIAL.*$/d" -i /media/realroot/EFI/BOOT/grub.cfg
		if [ -n "${GRUB_SERIAL_CONFIG}" ]; then
			GRUB_SERIAL_CONFIG_SED=`echo "${GRUB_SERIAL_CONFIG}" | sed 's#/#\\/#g'`
			sed "1i${GRUB_SERIAL_CONFIG_SED}" -i /media/realroot/EFI/BOOT/grub.cfg
		fi
	fi

	# serial console config in /etc/inittab
	SEDPATERN=`echo "^[^0-9].*:12345:respawn:@base_sbindir@/getty .*" | sed 's#/#\\\\/#g'`
	sed "/${SEDPATERN}/d" -i @sysconfdir@/inittab
	for console in ${GETTY_SERIAL_CONSOLES}; do
		gettty_params=`echo ${console} | sed s/\;/\ /g`
		label=`echo ${console} | sed -e 's/^.*;tty//' -e 's/;.*//'`
		echo "$label:12345:respawn:@base_sbindir@/getty ${gettty_params}" >> @sysconfdir@/inittab
	done

	# enable root login on serial console in /etc/securetty
	sed "/^# Machine Setup Tool Section Begin$/,/^# Machine Setup Tool Section End$/d" -i @sysconfdir@/securetty
	if [ -n "${SERIAL_CONSOLES}" ]; then
		echo "# Machine Setup Tool Section Begin" >> @sysconfdir@/securetty
		for console in ${SERIAL_CONSOLES}; do
			ttydev=`echo "$console" | sed -e 's/^.*\;//' -e 's/\;.*//'`
			echo $ttydev >> @sysconfdir@/securetty
		done
		echo "# Machine Setup Tool Section End" >> @sysconfdir@/securetty
	fi

	# Machine specific setup scripts
	for script in ${SETUP_SCRIPTS}; do
		if [ -f "@appconfdir@/config/${MACHINE}/${script}" ]; then
			. @appconfdir@/config/${MACHINE}/${script}
		else
			echo "Error: The machine specific setup script file is missing: @appconfdir@/config/${MACHINE}/${script}"
		fi
	done

	# Save the machine selection permanently
	sed "/^MACHINE=/d" -i @appconfdir@/defaults
	echo MACHINE=${MACHINE} >> @appconfdir@/defaults

	if ( [ "$OLDMACHINE" != "$MACHINE" ] && [ "${REBOOT_AFTER_SETUP}" = "yes" ] ); then
		echo
		echo The machine need to reboot for the configuration changes to take effect.
		echo
		echo -n "Do you want to stop the automatic reboot in 60 seconds [yes/no]: "
		read -t 60 REPLY
	
		# read failed
		if [ "$?" != "0" ]; then
			REPLY="yes"
		fi

		if [ "${REPLY}" = "yes" ]; then
			echo Not rebooting now. To activate all the setup changes a reboot is needed.
		else
			echo Rebooting now to activate the new machine configuration.
			reboot
		fi
	fi
fi