Subversion Repositories DevTools

Rev

Go to most recent revision | Details | 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
#
91
if [ "$startupMode" = "install" ] ; then
92
    ln -s $0 /root/Desktop/configureVM
93
    rm -f /root/.vix/config
94
    createHelpText
95
    exit 0
96
elif [ "$startupMode" = "remove" ] ; then
97
    rm -f /root/Desktop/configureVM*
98
    rm -rf /root/.vix
99
    exit 0
100
fi
101
 
102
#
103
#   Non Manual: Only run once
104
#
105
[ -z "$startupMode" -a -f /root/.vix/config ] && exit
106
 
107
#
108
#   Running full script
109
#   Perform full logging to another log file
110
mkdir -p /root/.vix
111
exec 1>/root/.vix/vix_full.log 2>&1
112
echo Starting $*
113
env
114
set -x
115
 
116
#
117
#   Create the Help Text
118
#   Place link to this script on the Desktop
119
#
120
[ -e /root/Desktop/configureVM ] || /root/Desktop/configureVM
121
createHelpText
122
 
123
#
124
# Extract information from the user
125
#
126
#
127
TITLE='First Time VM Configuration'
128
 
129
#
130
#   Display the Help Text
131
#
132
kdialog --title "$TITLE" --textbox "${HelpFile}" 800 800
133
 
134
#
135
#   Set defaults, before overiding with users last values
136
#
137
mname=$(cat /etc/hostname)
138
mode='Automount home drives'
139
pkgServer='auperaarc01'
140
[ -f /root/.vix/config.data ] && source /root/.vix/config.data
141
 
142
ok=false
143
prompt="Unique machine name\
144
        <pre>Suggested format: AUPERAWSxxxVMnn\
145
        <br>Where:\
146
        <br>   AUPERA - Site prefix\
147
        <br>   WSxxx  - Your Workstation ID\
148
        <br>   VM     - Indicated a VM\
149
        <br>   nn     - VM Instance\
150
        </pre>Machine Name:"
151
while ! $ok ; do
152
    [ -z "$mname" ] && mname=AUPERAWSxxxVMnn
153
    mname=$(kdialog --title "$TITLE" --inputbox "$prompt" "$mname")
154
    [[ $mname =~ ^[a-zA-Z][a-zA-Z0-9-]+$ ]] && ok=true
155
    [[ $mname =~ AUPERAWSx ]] && ok=false
156
    [[ $mname =~ VMnn ]] && ok=false
157
done
158
 
159
ok=false
160
prompt="<pre>Stand Alone VM:        No  NIS, Setup local user\
161
         <br>Local Home:            Use NIS, Setup local home\
162
         <br>Automount home drives: Use NIS, Mount Unix Home Drive\
163
        </pre>Select configuration:"
164
while ! $ok ; do
165
    umode=$(kdialog --title "$TITLE" --combobox "$prompt" \
166
            'Stand Alone VM' \
167
            'Local Home' \
168
            'Automount home drives' \
169
            --default "$mode"  )
170
    [ -n "$umode" ] && ok=true
171
done
172
mode="$umode"
173
 
174
ok=false
175
utext=""
176
prompt="The name of the build system package server\
177
        <br>Package Server:"
178
while ! $ok ; do
179
    [ -z "$utext" ] && utext="$pkgServer"
180
    utext=$(kdialog --title "$TITLE" --inputbox "$prompt" "$utext")
181
    [[ "$utext" =~ ^[a-zA-Z][a-zA-Z0-9_-]+$ ]] && ok=true
182
done
183
pkgServer="$utext"
184
 
185
erase=1
186
if [ -n "$startupMode" ]; then
187
    kdialog --title "$TITLE" --yesno \
188
        "This utility is being manually run.<br>\
189
        Do you want to force the script to be run on the next reboot"
190
    erase=$?
191
fi
192
 
193
#
194
#  Save config for next time
195
#
196
echo $mname
197
echo $mode
198
echo $pkgServer
199
mkdir -p /root/.vix
200
cat > /root/.vix/config.data <<hereData
201
mname="$mname"
202
mode="$mode"
203
pkgServer="$pkgServer"
204
hereData
205
 
206
################################################################################
207
#
208
#   Perform the initialisation
209
#
210
echo "--------------------------------"
211
echo "Data collected. Configure system"
212
 
213
# Extend the path
214
PATH="/sbin:$PATH"
215
 
216
# Machine-specific, so remove in case this system is going to be
217
# cloned.  These will be regenerated on the first boot.
218
if [ -z "$startupMode" ] ; then
219
    rm -f /etc/udev/rules.d/70-persistent-cd.rules
220
    rm -f /etc/udev/rules.d/70-persistent-net.rules
221
 
222
    # Potentially sensitive.
223
    rm -f /root/.ssh/known_hosts
224
    sed -i /etc/apt/apt.conf -e 's~http://.*@proxy~http://username:password@proxy~'
225
fi
226
 
227
#
228
#   Set new machine name
229
#
230
echo $mname > /etc/hostname
231
sed -i /etc/hosts -e "s~^127\.0\.1\.1.*~127.0.1.1\t$mname~"
232
hostname -b -F /etc/hostname
233
 
234
#
235
#   Set the required Mode
236
#
237
autoHome=false
238
perthNis=false
239
addUser=false
240
 
241
if [ "$mode" = "Stand Alone VM" ] ; then
242
    autoHome=false
243
    perthNis=false
244
    addUser=true
245
 
246
elif [ "$mode" = "Local Home" ] ; then
247
    autoHome=false
248
    perthNis=true
249
 
250
else
251
    autoHome=true
252
    perthNis=true
253
fi
254
 
255
#
256
#   Configure NIS
257
#
258
echo "Configure NIS"
259
if $perthNis; then
260
    echo "Enable yp binding"
261
    rm -f /etc/init/ypbind.override
262
    [ -f /etc/defaultdomain.saved ] && mv /etc/defaultdomain.saved /etc/defaultdomain
263
    start ypbind
264
    for ii in passwd shadow group ; do
265
        sed -i /etc/$ii -e "/^+/d"
266
        echo >> /etc/$ii '+'
267
    done
268
else
269
    echo "Disable yp binding"
270
    stop ypbind
271
    echo 'manual' > /etc/init/ypbind.override
272
    [ -f /etc/defaultdomain ] && mv /etc/defaultdomain /etc/defaultdomain.saved
273
    for ii in passwd shadow group; do
274
        sed -i /etc/$ii -e "/^+/d"
275
    done
276
fi
277
 
278
#
279
#   Configure auto mounting of Home Drives
280
#
281
echo "Configure Automounter"
282
VIXAUTOHOME=/etc/auto.master.d/vix.home.autofs
283
if $autoHome; then
284
    echo "Setup automount of /home"
285
    if [ -f ${VIXAUTOHOME}.disabled ] ; then
286
        mv ${VIXAUTOHOME}.disabled ${VIXAUTOHOME}
287
    fi
288
else
289
    echo "Stop automount of /home"
290
    if [ -f ${VIXAUTOHOME} ] ; then
291
        mv ${VIXAUTOHOME} ${VIXAUTOHOME}.disabled
292
    fi
293
fi
294
 
295
#
296
#   Stop auto mounter so that it will not interfere with the
297
#   creation of user home directories
298
#   
299
#   Note: This does not appear to stop the automounter
300
#         May not be an issue as we are about to reboot
301
/etc/init.d/autofs stop
302
 
303
#
304
#   Create local user if need be
305
#   Note: There is no need to create a local home directory for local users
306
#         as Ubuntu appears to do this on the fly.
307
#
308
echo "Configure Local User"
309
if $addUser; then
310
    kuser "--title=Configure local user" "--caption=Don't forget the passwd"
311
fi
312
 
313
#
314
#   Configure the package server
315
#
316
echo "Configure Package Server"
317
sed -i /etc/profile.d/jats.sh -e "s~^\(GBE_DPKG=/net\)/\([^/]*\)/\(.*\)~\1/$pkgServer/\3~"
318
 
319
#
320
#   Flag - configuration done
321
#   This should stop the auto script from running again
322
#
323
if [ -z "$startupMode" ]; then
324
    echo "Flag - don't run again"
325
    mkdir -p /root/.vix
326
    touch /root/.vix/config
327
fi
328
if [ "$erase" -eq "0" ] ; then
329
    echo "Erase config details. Force script to run on next reboot"
330
    rm -f /root/.vix/config
331
fi
332
 
333
#
334
#   Reboot the system
335
#   If manually invoked then give the user the option of aborting the boot
336
#
337
ktype=yesno
338
[ -z "$startupMode" ] && ktype=msgbox
339
kdialog --title "$TITLE" --$ktype "The system will now reboot in order for the changes to take effect"
340
if [ $? -ne 1 ]; then
341
    echo "Reboot the system"
342
    reboot
343
    echo "Reboot failed. Command returned"
344
fi
345
echo "Script complete"
346