Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
6868 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 VIXcentos7LTS_VMcfg package
7
#
8
# This script is called from
9
#    /etc/gdm/Init/:0
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: vix
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 [Perth Based Development]
63
             auperaarc02 [Pulse]
64
    It is expected that dpkg_archive will be found at:
65
        /net/PackageServerName/export/devl/dpkg_archive
66
 
67
Additional Notes:
68
    * Kedevelop has been installed. This is a GUI interface to GDB
69
 
70
HelpDoc
71
}
72
 
73
#
74
#   Examine user commandline.
75
#   Expect one of
76
#       -install    - Used by installer
77
#       -remove     - Used by installer
78
#       -auto       - Invoked by startup at boot
79
#                   - User invocation
80
#
81
startupMode=No
82
for ii in $*; do
83
    [ "$ii" = "-auto" ] && startupMode=
84
    [ "$ii" = "-install" ] && startupMode=install
85
    [ "$ii" = "-remove" ] && startupMode=remove
86
done
87
 
88
#
89
#   Self install and removal
90
#   Normally run from the installer
91
#
92
GdmBannerFile=/etc/dconf/db/gdm.d/01-banner-message
93
kdeScriptCfg=/.kde/share/config/configureVM
94
if [ "$startupMode" = "install" ] ; then
95
    ln -s $0 /root/Desktop/configureVM
96
    rm -f /root/.vix/config
97
    createHelpText
98
    rm -f $kdeScriptCfg
99
    exit 0
100
elif [ "$startupMode" = "remove" ] ; then
101
    rm -f /root/Desktop/configureVM*
102
    rm -rf /root/.vix
103
    rm -f $kdeScriptCfg
104
    rm -f $GdmBannerFile
105
    exit 0
106
fi
107
 
108
#
109
#   Non Manual: Only run once
110
#
111
if [ -z "$startupMode" -a -f /root/.vix/config ]; then
112
  #
113
  # Non Manual: After first time
114
  #
115
  # Display the OS Type
116
  #             Machine Name
117
  #             IP Address
118
  #
119
  # Allows users to determine the IP address to:
120
  #     Simplify ssh access
121
  #     Show when it does not have an IP address
122
  #
123
  # Note: Under Centos we can't pop up a dialog at this point as it will stall the logon
124
  #       process and prevent users from accessing the box via ssh
125
  #
126
  #       Under Centos we update the Greeter banner instead
127
  #
128
  IP=$(/sbin/ifconfig | grep "inet " | grep -v "127.0.0.1" | awk '{ print $2 }' )
129
  OS=$(hostnamectl | grep Operating | sed -e 's/.*: //')
130
  KERN=$(hostnamectl | grep Kernel| sed -e 's/.*: //')
131
  TEXT="Host Name: $(hostname)\\nOS: $OS\\nKernel: $KERN\\nIP Address: $IP"
132
 
133
  cat << EOF > $GdmBannerFile
134
[org/gnome/login-screen]
135
banner-message-enable=true
136
disable-user-list=true
137
banner-message-text='$TEXT'
138
EOF
139
  dconf update
140
 
141
#  text="
142
#OS Version: ${OS}
143
#Kernel: ${KERN}
144
#HostName: $(hostname)
145
#IP address: $ipaddress
146
#
147
#Continue to login"
148
#  # May create /.kde/share/config/configureVM ($kdeScriptCfg)
149
#  kdialog --msgbox "$text" --dontagain configureVM:noipaddressmsg
150
  exit
151
fi  
152
rm -f $kdeScriptCfg
153
 
154
#
155
#   Running full script
156
#   Perform full logging to another log file
157
mkdir -p /root/.vix
158
exec 1>/root/.vix/vix_full.log 2>&1
159
echo Starting $*
160
env
161
set -x
162
 
163
#
164
#   Create the Help Text
165
#   Place link to this script on the Desktop
166
#
167
[ -e /root/Desktop/configureVM ] || /root/Desktop/configureVM
168
createHelpText
169
 
170
#
171
# Extract information from the user
172
#
173
#
174
TITLE='First Time VM Configuration'
175
 
176
#
177
#   Display the Help Text
178
#
179
kdialog --title "$TITLE" --textbox "${HelpFile}" 800 800
180
 
181
#
182
#   Set defaults, before overiding with users last values
183
#
184
mname=$(cat /etc/hostname)
185
mode='Automount home drives'
186
pkgServer='auperaarc02'
187
[ -f /root/.vix/config.data ] && source /root/.vix/config.data
188
 
189
ok=false
190
prompt="Unique machine name\
191
        <pre>Suggested format: AUPERAWSxxxVMnn\
192
        <br>Where:\
193
        <br>   AUPERA - Site prefix\
194
        <br>   WSxxx  - Your Workstation ID\
195
        <br>   VM     - Indicated a VM\
196
        <br>   nn     - VM Instance\
197
        </pre>Machine Name:"
198
while ! $ok ; do
199
    [ -z "$mname" ] && mname=AUPERAWSxxxVMnn
200
    mname=$(kdialog --title "$TITLE" --inputbox "$prompt" "$mname")
201
    [[ $mname =~ ^[a-zA-Z][a-zA-Z0-9-]+$ ]] && ok=true
202
    [[ $mname =~ AUPERAWSx ]] && ok=false
203
    [[ $mname =~ VMnn ]] && ok=false
204
done
205
 
206
ok=false
207
prompt="<pre>Stand Alone VM:        No  NIS, Setup local user\
208
         <br>Local Home:            Use NIS, Setup local home\
209
         <br>Automount home drives: Use NIS, Mount Unix Home Drive\
210
        </pre>Select configuration:"
211
while ! $ok ; do
212
    umode=$(kdialog --title "$TITLE" --combobox "$prompt" \
213
            'Stand Alone VM' \
214
            'Local Home' \
215
            'Automount home drives' \
216
            --default "$mode"  )
217
    [ -n "$umode" ] && ok=true
218
done
219
mode="$umode"
220
 
221
ok=false
222
utext=""
223
prompt="The name of the build system package server\
224
        <br>Package Server:"
225
while ! $ok ; do
226
    [ -z "$utext" ] && utext="$pkgServer"
227
    utext=$(kdialog --title "$TITLE" --inputbox "$prompt" "$utext")
228
    [[ "$utext" =~ ^[a-zA-Z][a-zA-Z0-9_-]+$ ]] && ok=true
229
done
230
pkgServer="$utext"
231
 
232
erase=1
233
if [ -n "$startupMode" ]; then
234
    kdialog --title "$TITLE" --yesno \
235
        "This utility is being manually run.<br>\
236
        Do you want to force the script to be run on the next reboot"
237
    erase=$?
238
fi
239
 
240
#
241
#  Save config for next time
242
#
243
echo $mname
244
echo $mode
245
echo $pkgServer
246
mkdir -p /root/.vix
247
cat > /root/.vix/config.data <<hereData
248
mname="$mname"
249
mode="$mode"
250
pkgServer="$pkgServer"
251
hereData
252
 
253
################################################################################
254
#
255
#   Perform the initialisation
256
#
257
echo "--------------------------------"
258
echo "Data collected. Configure system"
259
 
260
# Extend the path
261
PATH="/sbin:$PATH"
262
 
263
# Machine-specific, so remove in case this system is going to be
264
# cloned.  These will be regenerated on the first boot.
265
if [ -z "$startupMode" ] ; then
266
    rm -f /etc/udev/rules.d/70-persistent-cd.rules
267
    rm -f /etc/udev/rules.d/70-persistent-net.rules
268
 
269
    # Potentially sensitive.
270
    rm -f /root/.ssh/known_hosts
271
    rm -f /root/.svn
272
fi
273
 
274
#
275
#   Set new machine name
276
#
277
echo $mname > /etc/hostname
278
hostname -b -F /etc/hostname
279
 
280
#
281
#   Set the required Mode
282
#
283
autoHome=false
284
perthNis=false
285
addUser=false
286
 
287
if [ "$mode" = "Stand Alone VM" ] ; then
288
    autoHome=false
289
    perthNis=false
290
    addUser=true
291
 
292
elif [ "$mode" = "Local Home" ] ; then
293
    autoHome=false
294
    perthNis=true
295
 
296
else
297
    autoHome=true
298
    perthNis=true
299
fi
300
 
301
#
302
#   Configure NIS
303
#
304
echo "Configure NIS"
305
if $perthNis; then
306
    echo "Enable yp binding"
307
    rm -f /usr/lib/systemd/system/ypbind.override
308
    for ii in passwd shadow group ; do
309
        sed -i /etc/$ii -e "/^+/d"
310
        echo >> /etc/$ii '+'
311
    done
312
    systemctl enable ypbind
313
    systemctl start ypbind
314
else
315
    echo "Disable yp binding"
316
    for ii in passwd shadow group; do
317
        sed -i /etc/$ii -e "/^+/d"
318
    done
319
    systemctl disable ypbind
320
fi
321
 
322
#
323
#   Configure auto mounting of Home Drives
324
#
325
echo "Configure Automounter"
326
VIXAUTOHOME=/etc/auto.master.d/vix.home.autofs
327
if $autoHome; then
328
    echo "Setup automount of /home"
329
    if [ -f ${VIXAUTOHOME}.disabled ] ; then
330
        mv ${VIXAUTOHOME}.disabled ${VIXAUTOHOME}
331
    fi
332
else
333
    echo "Stop automount of /home"
334
    if [ -f ${VIXAUTOHOME} ] ; then
335
        mv ${VIXAUTOHOME} ${VIXAUTOHOME}.disabled
336
    fi
337
fi
338
 
339
#
340
#   Stop auto mounter so that it will not interfere with the
341
#   creation of user home directories
342
#   
343
#   Note: This does not appear to stop the automounter
344
#         May not be an issue as we are about to reboot
345
systemctl stop autofs 
346
 
347
#
348
#   Create local user if need be
349
#   Note: There is no need to create a local home directory for local users
350
#         as Ubuntu appears to do this on the fly.
351
#
352
echo "Configure Local User"
353
if $addUser; then
354
    /usr/bin/python /usr/share/system-config-users/system-config-users.py
355
fi
356
 
357
#
358
#   Configure the package server
359
#
360
echo "Configure Package Server"
361
sed -i /etc/profile.d/jats.sh -e "s~^\(GBE_DPKG=/net\)/\([^/]*\)/\(.*\)~\1/$pkgServer/\3~"
362
 
363
#
364
#   Flag - configuration done
365
#   This should stop the auto script from running again
366
#
367
if [ -z "$startupMode" ]; then
368
    echo "Flag - don't run again"
369
    mkdir -p /root/.vix
370
    touch /root/.vix/config
371
fi
372
if [ "$erase" -eq "0" ] ; then
373
    echo "Erase config details. Force script to run on next reboot"
374
    rm -f /root/.vix/config
375
fi
376
 
377
#
378
#   Reboot the system
379
#   If manually invoked then give the user the option of aborting the boot
380
#
381
ktype=yesno
382
[ -z "$startupMode" ] && ktype=msgbox
383
kdialog --title "$TITLE" --$ktype "The system will now reboot in order for the changes to take effect"
384
if [ $? -ne 1 ]; then
385
    echo "Reboot the system"
386
    reboot --no-wall -f
387
    echo "Reboot failed. Command returned"
388
fi
389
echo "Script complete"
390