~hp-moonshot/ubuntu/trusty/hp-moonshot/hp-proliant

« back to all changes in this revision

Viewing changes to debian/hp-proliant/DEBIAN/preinst

  • Committer: Narinder Gupta
  • Date: 2014-09-04 20:45:24 UTC
  • Revision ID: narinder.gupta@canonical.com-20140904204524-9vhqysvi3s3ig3fu
renaming file from hp-moonshot.conf to hp-proliant.conf 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
set -e
 
3
set -x
 
4
 
 
5
#check our internal maas network settings.  Fall back to 10.14.
 
6
 
 
7
if [ -f /etc/hp-proliant.conf ]; then
 
8
        PREFIX=$(awk -F '[:]' NR==1'{print $3"."$4}' /etc/hp-proliant.conf)
 
9
else
 
10
        PREFIX="10.14"
 
11
fi
 
12
 
 
13
preflight_checks() {
 
14
        if [ "$(id -u ubuntu)" != "1000" ]; then
 
15
                echo "ERROR: Read the docs; a proper hp-proliant setup requires the default user to be [ubuntu]" 1>&2
 
16
                exit 1
 
17
        fi
 
18
        case $(hostname) in
 
19
                c*n*)
 
20
                        true
 
21
                ;;
 
22
                *)
 
23
                        echo "ERROR: Read the docs; a hp-proliant setup requires the hostname to be in the form [c*n*]" 1>&2
 
24
                        exit 1
 
25
                ;;
 
26
        esac
 
27
        # TODO: Check that the AMTs are on static IPs
 
28
        # TODO: Check dual hard drives, which one is which
 
29
        # TODO: Ensure we have two interfaces, one internal, one external
 
30
}
 
31
 
 
32
setup_debconf() {
 
33
        echo "debconf maas/default-maas-url string ${PREFIX}.4.1" | debconf-set-selections -
 
34
        echo "debconf maas-cluster-controller/maas-url string http://${PREFIX}.4.1/MAAS" | debconf-set-selections -
 
35
        echo "debconf maas/installation-note boolean true" | debconf-set-selections -
 
36
        echo "debconf iptables-persistent/autosave_done boolean true" | debconf-set-selections -
 
37
        echo "debconf iptables-persistent/autosave_v4 boolean true" | debconf-set-selections -
 
38
        echo "debconf iptables-persistent/autosave_v6 boolean true" | debconf-set-selections -
 
39
}
 
40
 
 
41
setup_networking() {
 
42
#       modprobe 8021q || true
 
43
#       sed -i -e "/8021q/d" /etc/modules || true
 
44
#       echo "8021q" >> /etc/modules
 
45
        # Set up the two network interfaces
 
46
        external_interface=$(ip route ls | grep ^default | awk '{print $5}')
 
47
        # TODO: ip addr ls
 
48
        for interface in $(ifconfig -a -s | grep -v ^Iface | awk '{print $1}'); do
 
49
                case "$interface" in
 
50
                        lo|br*|wlan*)
 
51
                                continue
 
52
                        ;;
 
53
                        $external_interface)
 
54
                                continue
 
55
                        ;;
 
56
                        *)
 
57
                                internal_interface="$interface"
 
58
                                break
 
59
                        ;;
 
60
                esac
 
61
        done
 
62
        # Set a sane default
 
63
        [ -z "$internal_interface" ] && internal_interface=eth0
 
64
        # TODO: use ip
 
65
        default_mac=$(ifconfig "$internal_interface" | grep "^$internal_interface" | sed -e "s/.*HWaddr //")
 
66
        # Tell NetworkManager to piss off
 
67
#       sed -i -e "/^unmanaged-devices=mac:$default_mac$/d" /etc/NetworkManager/NetworkManager.conf
 
68
#       cat >>/etc/NetworkManager/NetworkManager.conf <<EOF
 
69
#[keyfile]
 
70
#unmanaged-devices=mac:$default_mac
 
71
#EOF
 
72
#       invoke-rc.d network-manager restart
 
73
cp /etc/network/interfaces /etc/network/interfaces.orig
 
74
        cat >/etc/network/interfaces <<EOF
 
75
auto lo
 
76
iface lo inet loopback
 
77
 
 
78
auto $external_interface
 
79
iface $external_interface inet dhcp
 
80
 
 
81
auto $internal_interface
 
82
iface $internal_interface inet manual
 
83
 
 
84
auto br0
 
85
iface br0 inet static
 
86
        address ${PREFIX}.4.1
 
87
        netmask 255.255.0.0
 
88
        broadcast ${PREFIX}.255.255
 
89
        bridge_ports $internal_interface
 
90
        bridge_stp off
 
91
        bridge_fd 0
 
92
        bridge_maxwait 0
 
93
 
 
94
 
 
95
# VLAN 1, Network configuration network
 
96
#auto eth0.1
 
97
#iface eth0.1 inet static
 
98
#vlan-raw-device eth0
 
99
#address 10.90.90.1
 
100
#netmask 255.0.0.0
 
101
#gateway 0.0.0.0
 
102
#broadcast 10.255.255.255
 
103
 
 
104
EOF
 
105
        ifdown --force $internal_interface || true
 
106
        ifdown --force br0 || true
 
107
        ifup $internal_interface
 
108
        ifup br0
 
109
        # Wait a moment for the network to normalize
 
110
        echo "INFO: Conservatively sleeping 30 seconds to ensure networking has settled"
 
111
        sleep 30
 
112
}
 
113
 
 
114
setup_external_drive() {
 
115
        # External drive must be:
 
116
        #       a) partitioned into 1 big partition
 
117
        #       b) ext4 formatted
 
118
        # Find root disk
 
119
        root_disk=$(mount | grep " on / " | awk '{print $1}' | sed -e "s/[0-9]\+$//")
 
120
        # Find biggest non-root disk
 
121
        ext_disk=$(fdisk -l | grep "^Disk /" | grep -v $root_disk | sort -k4 -n -r | awk '{print $2}' | awk -F: '{print $1}')
 
122
        partition="${ext_disk}1"
 
123
        if [ -b "$ext_disk" ]; then
 
124
                if [ ! -b "$partition" ]; then
 
125
                        # Create the partition, if it doesn't exist already
 
126
                        echo "n
 
127
p
 
128
1
 
129
 
 
130
 
 
131
w
 
132
"|fdisk "$ext_disk"
 
133
                        mkfs.ext4 "$partition"
 
134
                fi
 
135
                sed -i -e "/ \/srv/d" /etc/fstab
 
136
                # Add the fstab entry
 
137
                uuid=$(blkid -s UUID -o value "$partition")
 
138
                echo "UUID=$uuid /srv    ext4    defaults        1 1" >> /etc/fstab
 
139
        fi
 
140
        umount $partition || true
 
141
        mount -a
 
142
        chown root:root /srv
 
143
        chmod 755 /srv
 
144
}
 
145
 
 
146
 
 
147
#preflight_checks
 
148
#setup_external_drive
 
149
setup_debconf
 
150
setup_networking
 
151
 
 
152
 
 
153
 
 
154
exit 0