~therve/pyjuju/rapi-uuid

« back to all changes in this revision

Viewing changes to juju/lib/lxc/data/juju-create

  • Committer: Kapil Thangavelu
  • Date: 2012-10-20 19:23:22 UTC
  • mfrom: (605.1.11 rapi-delta)
  • Revision ID: kapil@canonical.com-20121020192322-z34z59siiyz7lhcz
Merged svc-change-units into export-import.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
2
 
set -x
3
 
 
4
 
APT_OPTIONS="-o Dpkg::Options::= --force-confnew --force-yes -fuy"
5
 
 
6
 
setup_apt_cache()
7
 
{
8
 
# We ask the host to run apt-cache-server by default speeding the deployment of n units
9
 
# significantly. (and useful in repeated development runs)
10
 
    cat <<EOF >> /etc/apt/apt.conf.d/02juju-apt-proxy
11
 
Acquire::http { Proxy "http://192.168.122.1:3142"; };
12
 
Acquire::https { Proxy "false"; };
13
 
EOF
14
 
 
15
 
    chmod a+r /etc/apt/apt.conf.d/02juju-apt-proxy
16
 
 
17
 
    # explicitly update the cache w/ apt-cache inplace
18
 
    apt-get update
19
 
}
20
 
 
21
 
setup_networking()
22
 
{
23
 
    # Ensure we have the resolvconf installed before configuring it.
24
 
    apt-get install $APT_OPTIONS resolvconf
25
 
 
26
 
    # Use dnsmasq to resolve names from the bridge
27
 
    # This script executes from a chroot, so directly modify the output file.
28
 
    cat <<EOF > /etc/resolvconf/run/resolv.conf
29
 
nameserver 192.168.122.1
30
 
EOF
31
 
 
32
 
    cat <<EOF > /etc/resolvconf/resolv.conf.d/base
33
 
nameserver 192.168.122.1
34
 
EOF
35
 
 
36
 
    # By listing the container name first we can expect hostname and
37
 
    # hostname -f to return the routable name
38
 
    # note that lxc-clone will overwrite this
39
 
    cat <<EOF >/etc/hosts
40
 
127.0.0.1 $JUJU_CONTAINER_NAME localhost
41
 
EOF
42
 
}
43
 
 
44
 
 
45
 
setup_users()
46
 
{
47
 
    id ubuntu
48
 
    if [ $? != 0 ]; then
49
 
      # add the ubuntu user.
50
 
      adduser ubuntu --disabled-password --shell /bin/bash --gecos ""
51
 
    fi
52
 
 
53
 
    # Allow SSH access
54
 
    if [ -n "$JUJU_PUBLIC_KEY" ]; then
55
 
        if [ ! -e /home/ubuntu/.ssh ]; then
56
 
            mkdir /home/ubuntu/.ssh
57
 
            chmod 700 /home/ubuntu/.ssh
58
 
        fi
59
 
        echo $JUJU_PUBLIC_KEY >> /home/ubuntu/.ssh/authorized_keys
60
 
        chmod 700 /home/ubuntu/.ssh/authorized_keys
61
 
        chown -R ubuntu:ubuntu /home/ubuntu/.ssh
62
 
    fi
63
 
 
64
 
   # add to sudoers
65
 
    cat <<EOF > /etc/sudoers.d/lxc
66
 
ubuntu ALL=(ALL:ALL) NOPASSWD: ALL
67
 
EOF
68
 
    chmod 0440 /etc/sudoers.d/lxc
69
 
 
70
 
   # disable root ssh logins
71
 
    sed -i "s/PermitRootLogin yes/PermitRootLogin no/" /etc/ssh/sshd_config
72
 
    sed -i "s/#PasswordAuthentication yes/PasswordAuthentication no/" /etc/ssh/sshd_config
73
 
}
74
 
 
75
 
 
76
 
setup_juju()
77
 
{
78
 
    if [ ! -e /var/lib/juju ]; then
79
 
        mkdir /var/lib/juju
80
 
    fi
81
 
 
82
 
    if [ ! -e /var/log/juju ]; then
83
 
        mkdir /var/log/juju
84
 
    fi
85
 
 
86
 
    if [ $JUJU_ORIGIN = "ppa" ]; then
87
 
        echo "Using juju PPA for container"
88
 
    elif [ $JUJU_ORIGIN = "proposed" ]; then
89
 
        echo "Using juju distribution packages from proposed updates"
90
 
    elif [[ $JUJU_ORIGIN = lp:* ]]; then
91
 
        echo "Using juju branch" $JUJU_ORIGIN
92
 
    elif [ $JUJU_ORIGIN = "distro" ]; then
93
 
        echo "Using juju distribution packages"
94
 
    else
95
 
        echo "Unknown juju origin policy $JUJU_ORIGIN: expected [ppa|branch|disto]"
96
 
        exit 1
97
 
    fi
98
 
 
99
 
    export DEBIAN_FRONTEND=noninteractive
100
 
    echo "Setting up juju in container"
101
 
    apt-get install $APT_OPTIONS bzr tmux sudo python-software-properties python-yaml
102
 
 
103
 
    if [ $JUJU_ORIGIN = "ppa" ]; then
104
 
        # The echo forces an enter to get around the interactive
105
 
        # prompt in apt-add-repository
106
 
        echo y | apt-add-repository ppa:juju/pkgs
107
 
        apt-get update
108
 
        apt-get install $APT_OPTIONS juju python-txzookeeper
109
 
    elif [ $JUJU_ORIGIN = "proposed" ]; then
110
 
        # Enabled testing of proposed updates
111
 
        echo "deb http://archive.ubuntu.com/ubuntu/ $JUJU_SERIES-proposed main universe" >> /etc/apt/sources.list
112
 
        apt-get update
113
 
        apt-get install $APT_OPTIONS juju python-txzookeeper
114
 
 
115
 
    elif [[ $JUJU_ORIGIN = lp:* ]]; then
116
 
        apt-get install $APT_OPTIONS python-txzookeeper python-setuptools
117
 
        mkdir /usr/lib/juju
118
 
        # light weight checkout is significantly faster, no history though
119
 
        bzr co --lightweight $JUJU_ORIGIN /usr/lib/juju/juju
120
 
        bash -c "cd /usr/lib/juju/juju && sudo python setup.py develop"
121
 
        chmod -R a+r /usr/lib/juju
122
 
    elif [ $JUJU_ORIGIN = "distro" ]; then
123
 
        apt-get install --force-yes -y juju python-txzookeeper
124
 
    fi
125
 
 
126
 
}
127
 
 
128
 
# load configuration
129
 
source /etc/juju/juju.conf
130
 
 
131
 
if [ -z "$JUJU_ORIGIN" ]; then
132
 
    echo "JUJU_ORIGIN must be set to a supported policy"
133
 
    exit 1
134
 
fi
135
 
 
136
 
if [ "$(id -u)" != "0" ]; then
137
 
    echo "This script should be run as 'root'"
138
 
    exit 1
139
 
fi
140
 
 
141
 
if [ -z "$JUJU_CONTAINER_NAME" ]; then
142
 
    echo "JUJU_CONTAINER_NAME is required"
143
 
    exit 1
144
 
fi
145
 
 
146
 
if [ -z "$JUJU_PUBLIC_KEY" ]; then
147
 
    echo "Without JUJU_PUBLIC_KEY you will not have ssh access to your container"
148
 
fi
149
 
 
150
 
setup_apt_cache
151
 
setup_networking
152
 
setup_juju
153
 
# setup_juju ensures sudo is installed which is needed for setup_users
154
 
setup_users
155
 
 
156
 
echo "Container Customization Complete"