Subversion Repositories DevTools

Rev

Rev 4900 | Details | Compare with Previous | Last modification | View Log | RSS feed

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