Subversion Repositories DevTools

Rev

Rev 3993 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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