| 3993 |
dpurdie |
1 |
#!/bin/bash
|
|
|
2 |
################################################################################
|
|
|
3 |
# This file is to be run by root
|
|
|
4 |
# It is used to configure a new VM on first boot
|
|
|
5 |
#
|
|
|
6 |
# Source is controlled in the VIXubuntu1204LTS_VMcfg package
|
|
|
7 |
#
|
|
|
8 |
# This script is called from
|
|
|
9 |
# /etc/kde4/kdm/Xsetup
|
|
|
10 |
#
|
|
|
11 |
################################################################################
|
|
|
12 |
|
|
|
13 |
mkdir -p /root/Desktop
|
|
|
14 |
HelpFile="/root/Desktop/configureVM Help.txt"
|
|
|
15 |
function createHelpText {
|
|
|
16 |
cat > "$HelpFile" <<HelpDoc
|
|
|
17 |
Initial Machine Setup
|
|
|
18 |
|
|
|
19 |
This process will setup the VM.
|
|
|
20 |
It will be performed once, but can be manually rerun via $0
|
|
|
21 |
This text file can be found at: "$HelpFile"
|
|
|
22 |
|
|
|
23 |
Use Information:
|
|
|
24 |
Root Password: maple01
|
|
|
25 |
|
|
|
26 |
Machine Name:
|
|
|
27 |
This should be globally unique so as to avoid problems with IP address
|
|
|
28 |
assignment. The recommended name is based on:
|
|
|
29 |
1) Your Desktop machine Name. ie AUPERAWS123
|
|
|
30 |
2) The number of VMs that you already have created
|
|
|
31 |
ie: AUPERAWS123VM01
|
|
|
32 |
|
|
|
33 |
Configuration:
|
|
|
34 |
Automount home drivers
|
|
|
35 |
Intended for a Virtual Machine based in Perth attached to the Perth Unix
|
|
|
36 |
home drives. Use outside of Perth may suffer performance delays
|
|
|
37 |
|
|
|
38 |
Local Home
|
|
|
39 |
Intended for a VM not based in Perth, but aware of the Perth VIX NIS. The
|
|
|
40 |
machine will have a local home drive, but will use the Perth VIX NIS.
|
|
|
41 |
|
|
|
42 |
A local home directory will be configured. The user will authenicate against
|
|
|
43 |
the NIS, but use the local home drive.
|
|
|
44 |
|
|
|
45 |
Stand Alone:
|
|
|
46 |
Intended for a Virtual Machine that will not be attached to the Perth file
|
|
|
47 |
system. This type of machine will require that the user set up a
|
|
|
48 |
non-root user.
|
|
|
49 |
|
|
|
50 |
Package Server:
|
|
|
51 |
This is the name of the build system package server. It will be used to:
|
|
|
52 |
1) Provide the location of JATS
|
|
|
53 |
2) Provide dpkg_archive
|
|
|
54 |
Example: auperaarc01
|
|
|
55 |
It is expected that dpkg_archive will be found at:
|
|
|
56 |
/net/PackageServerName/export/devl/dpkg_archive
|
|
|
57 |
|
|
|
58 |
Additional Notes:
|
|
|
59 |
* Kdbg has been installed. This is a GUI interface to GDB
|
|
|
60 |
|
|
|
61 |
HelpDoc
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
#
|
|
|
65 |
# Examine user commandline.
|
|
|
66 |
# Expect one of
|
|
|
67 |
# -install - Used by installer
|
|
|
68 |
# -remove - Used by installer
|
|
|
69 |
# -auto - Invoked by startup at boot
|
|
|
70 |
# - User invocation
|
|
|
71 |
#
|
|
|
72 |
startupMode=No
|
|
|
73 |
for ii in $*; do
|
|
|
74 |
[ "$ii" = "-auto" ] && startupMode=
|
|
|
75 |
[ "$ii" = "-install" ] && startupMode=install
|
|
|
76 |
[ "$ii" = "-remove" ] && startupMode=remove
|
|
|
77 |
done
|
|
|
78 |
|
|
|
79 |
#
|
|
|
80 |
# Self install and removal
|
|
|
81 |
# Normally run from the installer
|
|
|
82 |
#
|
| 6010 |
dpurdie |
83 |
kdeScriptCfg=/.kde/share/config/configureVM
|
| 3993 |
dpurdie |
84 |
if [ "$startupMode" = "install" ] ; then
|
|
|
85 |
ln -s $0 /root/Desktop/configureVM
|
|
|
86 |
rm -f /root/.vix/config
|
|
|
87 |
createHelpText
|
| 6010 |
dpurdie |
88 |
rm -f $kdeScriptCfg
|
| 3993 |
dpurdie |
89 |
exit 0
|
|
|
90 |
elif [ "$startupMode" = "remove" ] ; then
|
|
|
91 |
rm -f /root/Desktop/configureVM*
|
|
|
92 |
rm -rf /root/.vix
|
| 6010 |
dpurdie |
93 |
rm -f $kdeScriptCfg
|
| 3993 |
dpurdie |
94 |
exit 0
|
|
|
95 |
fi
|
|
|
96 |
|
|
|
97 |
#
|
|
|
98 |
# Non Manual: Only run once
|
|
|
99 |
#
|
| 6010 |
dpurdie |
100 |
if [ -z "$startupMode" -a -f /root/.vix/config ]; then
|
|
|
101 |
#
|
|
|
102 |
# Non Manual: After first time
|
|
|
103 |
#
|
|
|
104 |
# Display the OS Type
|
|
|
105 |
# Machine Name
|
|
|
106 |
# IP Address
|
|
|
107 |
#
|
|
|
108 |
# Allows users to determine the IP address to:
|
|
|
109 |
# Simplify ssh access
|
|
|
110 |
# Show when it doesnot have an IP address
|
|
|
111 |
ipaddress=$(/sbin/ifconfig | grep "inet addr" | grep -v "127.0.0.1" | awk '{ print $2 }' | awk -F: '{ print $2 }')
|
|
|
112 |
text="
|
|
|
113 |
OS Version: $(lsb_release -sd)
|
|
|
114 |
HostName: $(hostname)
|
|
|
115 |
IP address: $ipaddress
|
| 3993 |
dpurdie |
116 |
|
| 6010 |
dpurdie |
117 |
Continue to login"
|
|
|
118 |
# May create /.kde/share/config/configureVM ($kdeScriptCfg)
|
|
|
119 |
kdialog --msgbox "$text" --dontagain configureVM:noipaddressmsg
|
|
|
120 |
exit
|
|
|
121 |
fi
|
|
|
122 |
rm -f $kdeScriptCfg
|
|
|
123 |
|
| 3993 |
dpurdie |
124 |
#
|
| 5273 |
dpurdie |
125 |
# Running full script
|
|
|
126 |
# Perform full logging to another log file
|
|
|
127 |
mkdir -p /root/.vix
|
|
|
128 |
exec 1>/root/.vix/vix_full.log 2>&1
|
|
|
129 |
echo Starting $*
|
|
|
130 |
env
|
|
|
131 |
set -x
|
|
|
132 |
|
|
|
133 |
#
|
| 3993 |
dpurdie |
134 |
# Create the Help Text
|
|
|
135 |
# Place link to this script on the Desktop
|
|
|
136 |
#
|
|
|
137 |
[ -e /root/Desktop/configureVM ] || /root/Desktop/configureVM
|
|
|
138 |
createHelpText
|
|
|
139 |
|
|
|
140 |
#
|
|
|
141 |
# Extract information from the user
|
|
|
142 |
#
|
|
|
143 |
#
|
|
|
144 |
TITLE='First Time VM Configuration'
|
|
|
145 |
|
|
|
146 |
#
|
|
|
147 |
# Display the Help Text
|
|
|
148 |
#
|
|
|
149 |
kdialog --title "$TITLE" --textbox "${HelpFile}" 800 800
|
|
|
150 |
|
|
|
151 |
#
|
|
|
152 |
# Set defaults, before overiding with users last values
|
|
|
153 |
#
|
|
|
154 |
mname=$(cat /etc/hostname)
|
|
|
155 |
mode='Automount home drives'
|
|
|
156 |
pkgServer='auperaarc01'
|
|
|
157 |
luser=""
|
|
|
158 |
[ -f /root/.vix/config.data ] && source /root/.vix/config.data
|
|
|
159 |
|
|
|
160 |
ok=false
|
|
|
161 |
prompt="Unique machine name\
|
|
|
162 |
<pre>Suggested format: AUPERAWSxxxVMnn\
|
|
|
163 |
<br>Where:\
|
|
|
164 |
<br> AUPERA - Site prefix\
|
|
|
165 |
<br> WSxxx - Your Workstation ID\
|
|
|
166 |
<br> VM - Indicated a VM\
|
|
|
167 |
<br> nn - VM Instance\
|
|
|
168 |
</pre>Machine Name:"
|
|
|
169 |
while ! $ok ; do
|
|
|
170 |
[ -z "$mname" ] && mname=AUPERAWSxxxVMnn
|
|
|
171 |
mname=$(kdialog --title "$TITLE" --inputbox "$prompt" "$mname")
|
|
|
172 |
[[ $mname =~ ^[a-zA-Z][a-zA-Z0-9-]+$ ]] && ok=true
|
|
|
173 |
[[ $mname =~ AUPERAWSx ]] && ok=false
|
|
|
174 |
[[ $mname =~ VMnn ]] && ok=false
|
|
|
175 |
done
|
|
|
176 |
|
|
|
177 |
ok=false
|
| 5273 |
dpurdie |
178 |
prompt="<pre>Stand Alone VM: No NIS, Setup local user\
|
| 3993 |
dpurdie |
179 |
<br>Local Home: Use NIS, Setup local home\
|
|
|
180 |
<br>Automount home drives: Use NIS, Mount Unix Home Drive\
|
|
|
181 |
</pre>Select configuration:"
|
|
|
182 |
while ! $ok ; do
|
|
|
183 |
umode=$(kdialog --title "$TITLE" --combobox "$prompt" \
|
|
|
184 |
'Stand Alone VM' \
|
|
|
185 |
'Local Home' \
|
|
|
186 |
'Automount home drives' \
|
|
|
187 |
--default "$mode" )
|
|
|
188 |
[ -n "$umode" ] && ok=true
|
|
|
189 |
done
|
|
|
190 |
mode="$umode"
|
|
|
191 |
|
|
|
192 |
if [ "$mode" = "Local Home" ] ; then
|
|
|
193 |
ok=false
|
|
|
194 |
prompt="Local Home with NIS support has been selected\
|
|
|
195 |
<br>Enter the name of a NIS user and a local home\
|
|
|
196 |
directory will be created\
|
|
|
197 |
<br>Cancel to skip this operation"
|
|
|
198 |
while ! $ok ; do
|
|
|
199 |
utext=$(kdialog --title "$TITLE" --inputbox "$prompt" "$luser")
|
|
|
200 |
[[ -z "$utext" ]] && ok=true
|
|
|
201 |
[[ -n "$utext" && "$utext" =~ ^[a-zA-Z][a-zA-Z0-9_]+$ ]] && ok=true
|
|
|
202 |
done
|
|
|
203 |
luser="$utext"
|
|
|
204 |
fi
|
|
|
205 |
|
|
|
206 |
ok=false
|
|
|
207 |
utext=""
|
|
|
208 |
prompt="The name of the build system package server\
|
|
|
209 |
<br>Package Server:"
|
|
|
210 |
while ! $ok ; do
|
|
|
211 |
[ -z "$utext" ] && utext="$pkgServer"
|
|
|
212 |
utext=$(kdialog --title "$TITLE" --inputbox "$prompt" "$utext")
|
|
|
213 |
[[ "$utext" =~ ^[a-zA-Z][a-zA-Z0-9_-]+$ ]] && ok=true
|
|
|
214 |
done
|
|
|
215 |
pkgServer="$utext"
|
|
|
216 |
|
| 5273 |
dpurdie |
217 |
erase=1
|
| 3993 |
dpurdie |
218 |
if [ -n "$startupMode" ]; then
|
|
|
219 |
kdialog --title "$TITLE" --yesno \
|
|
|
220 |
"This utility is being manually run.<br>\
|
|
|
221 |
Do you want to force the script to be run on the next reboot"
|
|
|
222 |
erase=$?
|
|
|
223 |
fi
|
|
|
224 |
|
|
|
225 |
#
|
|
|
226 |
# Save config for next time
|
|
|
227 |
#
|
|
|
228 |
echo $mname
|
|
|
229 |
echo $mode
|
|
|
230 |
echo $pkgServer
|
|
|
231 |
mkdir -p /root/.vix
|
|
|
232 |
cat > /root/.vix/config.data <<hereData
|
|
|
233 |
mname="$mname"
|
|
|
234 |
mode="$mode"
|
|
|
235 |
pkgServer="$pkgServer"
|
|
|
236 |
luser="$luser"
|
|
|
237 |
hereData
|
|
|
238 |
|
|
|
239 |
################################################################################
|
|
|
240 |
#
|
|
|
241 |
# Perform the initialisation
|
| 5273 |
dpurdie |
242 |
#
|
|
|
243 |
echo "--------------------------------"
|
|
|
244 |
echo "Data collected. Configure system"
|
| 3993 |
dpurdie |
245 |
|
| 5273 |
dpurdie |
246 |
# Extend the path
|
|
|
247 |
PATH="/sbin:$PATH"
|
|
|
248 |
|
| 3993 |
dpurdie |
249 |
# Machine-specific, so remove in case this system is going to be
|
|
|
250 |
# cloned. These will be regenerated on the first boot.
|
|
|
251 |
if [ -z "$startupMode" ] ; then
|
|
|
252 |
rm -f /etc/udev/rules.d/70-persistent-cd.rules
|
|
|
253 |
rm -f /etc/udev/rules.d/70-persistent-net.rules
|
|
|
254 |
|
|
|
255 |
# Potentially sensitive.
|
|
|
256 |
rm -f /root/.ssh/known_hosts
|
|
|
257 |
sed -i /etc/apt/apt.conf -e 's~http://.*@proxy~http://username:password@proxy~'
|
|
|
258 |
fi
|
|
|
259 |
|
|
|
260 |
#
|
|
|
261 |
# Set new machine name
|
|
|
262 |
#
|
|
|
263 |
echo $mname > /etc/hostname
|
| 5273 |
dpurdie |
264 |
sed -i /etc/hosts -e "s~^127\.0\.1\.1.*~127.0.1.1\t$mname.vix.local $mname~"
|
| 3993 |
dpurdie |
265 |
hostname -b -F /etc/hostname
|
|
|
266 |
|
|
|
267 |
#
|
|
|
268 |
# Set the required Mode
|
|
|
269 |
#
|
|
|
270 |
autoHome=false
|
|
|
271 |
perthNis=false
|
|
|
272 |
addUser=false
|
|
|
273 |
|
|
|
274 |
if [ "$mode" = "Stand Alone VM" ] ; then
|
|
|
275 |
autoHome=false
|
|
|
276 |
perthNis=false
|
|
|
277 |
addUser=true
|
|
|
278 |
|
|
|
279 |
elif [ "$mode" = "Local Home" ] ; then
|
|
|
280 |
autoHome=false
|
|
|
281 |
perthNis=true
|
|
|
282 |
|
|
|
283 |
else
|
|
|
284 |
autoHome=true
|
|
|
285 |
perthNis=true
|
|
|
286 |
fi
|
|
|
287 |
|
|
|
288 |
#
|
|
|
289 |
# Configure NIS
|
|
|
290 |
#
|
| 5273 |
dpurdie |
291 |
echo "Configure NIS"
|
| 3993 |
dpurdie |
292 |
if $perthNis; then
|
|
|
293 |
echo "Enable yp binding"
|
|
|
294 |
rm -f /etc/init/ypbind.override
|
|
|
295 |
[ -f /etc/defaultdomain.saved ] && mv /etc/defaultdomain.saved /etc/defaultdomain
|
|
|
296 |
start ypbind
|
|
|
297 |
for ii in passwd shadow group ; do
|
|
|
298 |
sed -i /etc/$ii -e "/^+/d"
|
|
|
299 |
echo >> /etc/$ii '+'
|
|
|
300 |
done
|
|
|
301 |
else
|
|
|
302 |
echo "Disable yp binding"
|
|
|
303 |
stop ypbind
|
|
|
304 |
echo 'manual' > /etc/init/ypbind.override
|
|
|
305 |
[ -f /etc/defaultdomain ] && mv /etc/defaultdomain /etc/defaultdomain.saved
|
|
|
306 |
for ii in passwd shadow group; do
|
|
|
307 |
sed -i /etc/$ii -e "/^+/d"
|
|
|
308 |
done
|
|
|
309 |
fi
|
|
|
310 |
|
|
|
311 |
#
|
|
|
312 |
# Configure auto mounting of Home Drives
|
|
|
313 |
#
|
|
|
314 |
if $autoHome; then
|
|
|
315 |
echo "Setup automount of /home"
|
|
|
316 |
sed -i /etc/auto.master -e 's~^#/home~/home~'
|
|
|
317 |
reload autofs
|
|
|
318 |
else
|
|
|
319 |
echo "Stop automount of /home"
|
|
|
320 |
sed -i /etc/auto.master -e 's~^/home~#/home~'
|
|
|
321 |
restart autofs
|
|
|
322 |
fi
|
|
|
323 |
|
|
|
324 |
#
|
| 5273 |
dpurdie |
325 |
#
|
| 3993 |
dpurdie |
326 |
# Create local user if need be
|
| 5273 |
dpurdie |
327 |
# Note: There is no need to create a local home directory for local users
|
|
|
328 |
# as Ubuntu appears to do this on the fly.
|
| 3993 |
dpurdie |
329 |
#
|
| 5273 |
dpurdie |
330 |
echo "Configure Local User"
|
| 3993 |
dpurdie |
331 |
if $addUser; then
|
|
|
332 |
kuser
|
|
|
333 |
fi
|
|
|
334 |
if [ -n "$luser" ] ; then
|
|
|
335 |
userPath="/home/$luser"
|
|
|
336 |
if [ ! -d "$userPath" ] ; then
|
|
|
337 |
mkdir -p "$userPath"
|
|
|
338 |
chmod 0777 "$userPath"
|
|
|
339 |
fi
|
|
|
340 |
fi
|
|
|
341 |
|
|
|
342 |
#
|
|
|
343 |
# Configure the package server
|
|
|
344 |
#
|
| 5273 |
dpurdie |
345 |
echo "Configure Package Server"
|
| 3993 |
dpurdie |
346 |
sed -i /etc/profile.d/jats.sh -e "s~^\(GBE_DPKG=/net\)/\([^/]*\)/\(.*\)~\1/$pkgServer/\3~"
|
|
|
347 |
|
|
|
348 |
#
|
|
|
349 |
# Flag - configuration done
|
|
|
350 |
# This should stop the auto script from running again
|
|
|
351 |
#
|
|
|
352 |
if [ -z "$startupMode" ]; then
|
|
|
353 |
echo "Flag - don't run again"
|
|
|
354 |
mkdir -p /root/.vix
|
|
|
355 |
touch /root/.vix/config
|
|
|
356 |
fi
|
| 5273 |
dpurdie |
357 |
if [ "$erase" -eq "0" ] ; then
|
|
|
358 |
echo "Erase config details. Force script to run on next reboot"
|
| 3993 |
dpurdie |
359 |
rm -f /root/.vix/config
|
|
|
360 |
fi
|
|
|
361 |
|
|
|
362 |
#
|
|
|
363 |
# Reboot the system
|
|
|
364 |
# If manually invoked then give the user the option of aborting the boot
|
|
|
365 |
#
|
|
|
366 |
ktype=yesno
|
|
|
367 |
[ -z "$startupMode" ] && ktype=msgbox
|
|
|
368 |
kdialog --title "$TITLE" --$ktype "The system will now reboot in order for the changes to take effect"
|
|
|
369 |
if [ $? -ne 1 ]; then
|
| 5273 |
dpurdie |
370 |
echo "Reboot the system"
|
| 3993 |
dpurdie |
371 |
reboot
|
| 5273 |
dpurdie |
372 |
echo "Reboot failed. Command returned"
|
| 3993 |
dpurdie |
373 |
fi
|
| 5273 |
dpurdie |
374 |
echo "Script complete"
|
| 3993 |
dpurdie |
375 |
|