~vsasi/charms/trusty/xcat/devfix

« back to all changes in this revision

Viewing changes to hooks/config-changed

  • Committer: vsasi
  • Date: 2015-08-13 10:05:10 UTC
  • Revision ID: vsasi-20150813100510-fro13pus3rhuo7i5
Commit with review comments

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
 
 
3
TARGET_REPO=`config-get XCAT_REPO`
 
4
OVERRIDE_DOMAIN=`config-get XCAT_DOMAIN`
 
5
 
 
6
 
 
7
FQDN_NAME=`/bin/hostname --fqdn`
 
8
HOSTNAME=`/bin/hostname`
 
9
#Release name like trusty
 
10
RELEASE=`lsb_release -c | cut -d":"  -f2 | tr -d '[[:space:]]'`
 
11
 
 
12
juju-log "FQDN: $FQDN_NAME"
 
13
juju-log "HOSTNAME: $HOSTNAME"
 
14
juju-log "OVERRIDE_DOMAIN: $OVERRIDE_DOMAIN"
 
15
juju-log "TARGET_REPO: $TARGET_REPO"
 
16
 
 
17
# Update the /etc/hosts file
 
18
# Argumenst: IP Address, FQDN, Host name
 
19
update_host_file()
 
20
{
 
21
 
 
22
        # If IP address already present, update the entry
 
23
        if grep -q "$1" /etc/hosts
 
24
        then
 
25
                sed -i "s/$1.*/$1 $2 $3/" /etc/hosts
 
26
        else
 
27
                echo "$1 $2 $3" >> /etc/hosts
 
28
        fi
 
29
 
 
30
}
 
31
 
 
32
juju-log "Installing software."
 
33
status-set maintenance "Installing software."
 
34
 
 
35
# Host name and fully qualified name are same
 
36
# Or the user has updated/set a new domain name
 
37
if [ "$HOSTNAME" = "$FQDN_NAME" -o "$OVERRIDE_DOMAIN" != "" ]
 
38
then
 
39
        #domain name is set correctly set. 
 
40
        if [ "$OVERRIDE_DOMAIN" ]
 
41
        then
 
42
                #user override for domain name 
 
43
                FQDN_NAME="$HOSTNAME.$OVERRIDE_DOMAIN"
 
44
                IPADDR=`unit-get private-address`
 
45
                update_host_file $IPADDR $FQDN_NAME $HOSTNAME
 
46
        else
 
47
                juju-log "Domain name not properly set in /etc/hosts.  Exiting."
 
48
                status-set blocked "Please set the XCAT_DOMAIN name."
 
49
                exit 0
 
50
        fi
 
51
else
 
52
        IPADDR=`unit-get private-address`
 
53
        update_host_file $IPADDR $FQDN_NAME $HOSTNAME
 
54
fi
 
55
 
 
56
# Target repository from where the packages are to be downloaded is not set
 
57
if [ "$TARGET_REPO" = ""  ]
 
58
then
 
59
        juju-log "Target repository not set."
 
60
        status-set blocked "Please set the XCAT_REPO value"
 
61
        exit 0
 
62
 
 
63
fi
 
64
 
 
65
/bin/ping -c 1 $TARGET_REPO
 
66
if [ "$?" -ne 0  ]
 
67
then
 
68
        juju-log "Target Repository ${TARGET_REPO} is unreachable.  Please check name or availability.  Exiting with error."
 
69
        status-set blocked "Target Repository ${TARGET_REPO} is not reachable"
 
70
        exit 0
 
71
fi
 
72
 
 
73
# Remove the previously installed software
 
74
if [ -f /etc/profile.d/xcat.sh ]
 
75
then
 
76
        juju-log "Removing the installed software."
 
77
        /usr/bin/apt-get -y remove software-properties-common xcat
 
78
fi
 
79
 
 
80
# Get the architecture from the uname command.
 
81
ARCHITECTURE=`uname -m`
 
82
if [ "$ARCHITECTURE" = "ppc64le" ]; then
 
83
        # Power Arch
 
84
        juju-log "Creating ppc64 repositories"
 
85
        apt-add-repository "deb [arch=ppc64el] http://${TARGET_REPO}/projects/xcat/files/ubuntu/2.9/core-snap $RELEASE main"
 
86
        apt-add-repository "deb [arch=ppc64el] http://${TARGET_REPO}/projects/xcat/files/ubuntu/xcat-dep $RELEASE main"
 
87
 else
 
88
        juju-log "Creating amd64 repositories"
 
89
        apt-add-repository "deb [arch=amd64] http://${TARGET_REPO}/projects/xcat/files/ubuntu/2.9/core-snap $RELEASE main"
 
90
        apt-add-repository "deb [arch=amd64] http://${TARGET_REPO}/projects/xcat/files/ubuntu/xcat-dep $RELEASE main"
 
91
fi
 
92
 
 
93
wget -O - "http://$TARGET_REPO/projects/xcat/files/ubuntu/apt.key/download" | apt-key add -
 
94
 
 
95
/usr/bin/apt-get -y update
 
96
if [ "$?" -ne 0 ]
 
97
then
 
98
        juju-log "Update call failed.  Check if permissions or access to repository correct. Exiting."
 
99
        exit 1
 
100
fi
 
101
 
 
102
# Install it
 
103
/usr/bin/apt-get -y install software-properties-common xcat
 
104
if [ "$?" -ne 0 ]
 
105
then
 
106
        juju-log "install software-properties-common or xcat call failed.  Check if permissions or access to repository correct. Exiting."
 
107
        exit 1
 
108
fi
 
109
 
 
110
/usr/bin/apt-get -y clean
 
111
 
 
112
source /etc/profile.d/xcat.sh
 
113
lsxcatd -a
 
114
tabdump site
 
115
if [ "$?" -eq 0 ]
 
116
then
 
117
        juju-log "xCAT is up"
 
118
        status-set active "xCAT is up"
 
119
else
 
120
        juju-log "Failed to get xCAT status."
 
121
        exit 1
 
122
fi