Subversion Repositories DevTools

Rev

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