Import from vagrant-lxc
[obnox/vagrant/vagrant-lxc-base-boxes.git] / debian / install-extras.sh
1 #!/bin/bash
2 set -e
3
4 source common/ui.sh
5 source common/utils.sh
6
7 info 'Installing extra packages and upgrading'
8
9 debug 'Bringing container up'
10 utils.lxc.start
11
12 # Sleep for a bit so that the container can get an IP
13 log 'Sleeping for 5 seconds...'
14 sleep 5
15
16 # TODO: Support for appending to this list from outside
17 PACKAGES=(vim curl wget man-db bash-completion python-software-properties ca-certificates sudo)
18 if [ $DISTRIBUTION = 'ubuntu' ]; then
19   PACKAGES+=' software-properties-common'
20 fi
21 if [ $RELEASE != 'raring' ] && [ $RELEASE != 'saucy' ] && [ $RELEASE != 'trusty' ] ; then
22   PACKAGES+=' nfs-common'
23 fi
24 utils.lxc.attach apt-get update
25 utils.lxc.attach apt-get install ${PACKAGES[*]} -y --force-yes
26 utils.lxc.attach apt-get upgrade -y --force-yes
27
28 CHEF=${CHEF:-0}
29 PUPPET=${PUPPET:-0}
30 SALT=${SALT:-0}
31 BABUSHKA=${BABUSHKA:-0}
32
33 if [ $DISTRIBUTION = 'debian' ]; then
34   # Enable bash-completion
35   sed -e '/^#if ! shopt -oq posix; then/,/^#fi/ s/^#\(.*\)/\1/g' \
36     -i ${ROOTFS}/etc/bash.bashrc
37 fi
38
39 if [ $CHEF = 1 ]; then
40   if $(lxc-attach -n ${CONTAINER} -- which chef-solo &>/dev/null); then
41     log "Chef has been installed on container, skipping"
42   else
43     log "Installing Chef"
44     cat > ${ROOTFS}/tmp/install-chef.sh << EOF
45 #!/bin/sh
46 curl -L https://www.opscode.com/chef/install.sh -k | sudo bash
47 EOF
48     chmod +x ${ROOTFS}/tmp/install-chef.sh
49     utils.lxc.attach /tmp/install-chef.sh
50   fi
51 else
52   log "Skipping Chef installation"
53 fi
54
55 if [ $PUPPET = 1 ]; then
56   if $(lxc-attach -n ${CONTAINER} -- which puppet &>/dev/null); then
57     log "Puppet has been installed on container, skipping"
58   elif [ ${RELEASE} = 'trusty' ]; then
59     warn "Puppet can't be installed on Ubuntu Trusty 14.04, skipping"
60   elif [ ${RELEASE} = 'sid' ]; then
61     warn "Puppet can't be installed on Debian sid, skipping"
62   else
63     log "Installing Puppet"
64     wget http://apt.puppetlabs.com/puppetlabs-release-stable.deb -O "${ROOTFS}/tmp/puppetlabs-release-stable.deb" &>>${LOG}
65     utils.lxc.attach dpkg -i "/tmp/puppetlabs-release-stable.deb"
66     utils.lxc.attach apt-get update
67     utils.lxc.attach apt-get install puppet -y --force-yes
68   fi
69 else
70   log "Skipping Puppet installation"
71 fi
72
73 if [ $SALT = 1 ]; then
74   if $(lxc-attach -n ${CONTAINER} -- which salt-minion &>/dev/null); then
75     log "Salt has been installed on container, skipping"
76   elif [ ${RELEASE} = 'raring' ]; then
77     warn "Salt can't be installed on Ubuntu Raring 13.04, skipping"
78   else
79     if [ $DISTRIBUTION = 'ubuntu' ]; then
80       utils.lxc.attach add-apt-repository -y ppa:saltstack/salt
81     else # DEBIAN
82       if [ $RELEASE == "squeeze" ]; then
83         SALT_SOURCE_1="deb http://debian.saltstack.com/debian squeeze-saltstack main"
84         SALT_SOURCE_2="deb http://backports.debian.org/debian-backports squeeze-backports main contrib non-free"
85       elif [ $RELEASE == "wheezy" ]; then
86         SALT_SOURCE_1="deb http://debian.saltstack.com/debian wheezy-saltstack main"
87       else
88         SALT_SOURCE_1="deb http://debian.saltstack.com/debian unstable main"
89       fi
90       echo $SALT_SOURCE_1 > ${ROOTFS}/etc/apt/sources.list.d/saltstack.list
91       echo $SALT_SOURCE_2 >> ${ROOTFS}/etc/apt/sources.list.d/saltstack.list
92
93       utils.lxc.attach wget -q -O /tmp/salt.key "http://debian.saltstack.com/debian-salt-team-joehealy.gpg.key"
94       utils.lxc.attach apt-key add /tmp/salt.key
95     fi
96     utils.lxc.attach apt-get update
97     utils.lxc.attach apt-get install salt-minion -y --force-yes
98   fi
99 else
100   log "Skipping Salt installation"
101 fi
102
103 if [ $BABUSHKA = 1 ]; then
104   if $(lxc-attach -n ${CONTAINER} -- which babushka &>/dev/null); then
105     log "Babushka has been installed on container, skipping"
106   elif [ ${RELEASE} = 'trusty' ]; then
107     warn "Babushka can't be installed on Ubuntu Trusty 14.04, skipping"
108   else
109     log "Installing Babushka"
110     cat > $ROOTFS/tmp/install-babushka.sh << EOF
111 #!/bin/sh
112 curl https://babushka.me/up | sudo bash
113 EOF
114     chmod +x $ROOTFS/tmp/install-babushka.sh
115     utils.lxc.attach /tmp/install-babushka.sh
116   fi
117 else
118   log "Skipping Babushka installation"
119 fi