Added vagrant/puppet config (created with https://puphpet.com)
[memberdb.git] / shell / librarian-puppet-vagrant.sh
1 #!/bin/bash
2
3 OS=$(/bin/bash /vagrant/shell/os-detect.sh ID)
4 CODENAME=$(/bin/bash /vagrant/shell/os-detect.sh CODENAME)
5
6 # Directory in which librarian-puppet should manage its modules directory
7 PUPPET_DIR=/etc/puppet/
8
9 $(which git > /dev/null 2>&1)
10 FOUND_GIT=$?
11
12 if [ "$FOUND_GIT" -ne '0' ] && [ ! -f /.puphpet-stuff/librarian-puppet-installed ]; then
13     $(which apt-get > /dev/null 2>&1)
14     FOUND_APT=$?
15     $(which yum > /dev/null 2>&1)
16     FOUND_YUM=$?
17
18     echo 'Installing git'
19
20     if [ "${FOUND_YUM}" -eq '0' ]; then
21         yum -q -y makecache
22         yum -q -y install git
23     else
24         apt-get -q -y install git-core >/dev/null
25     fi
26
27     echo 'Finished installing git'
28 fi
29
30 if [[ ! -d "$PUPPET_DIR" ]]; then
31     mkdir -p "$PUPPET_DIR"
32     echo "Created directory $PUPPET_DIR"
33 fi
34
35 cp "/vagrant/puppet/Puppetfile" "$PUPPET_DIR"
36 echo "Copied Puppetfile"
37
38 if [ "$OS" == 'debian' ] || [ "$OS" == 'ubuntu' ]; then
39     if [[ ! -f /.puphpet-stuff/librarian-base-packages ]]; then
40         echo 'Installing base packages for librarian'
41         apt-get install -y build-essential ruby-dev >/dev/null
42         echo 'Finished installing base packages for librarian'
43
44         touch /.puphpet-stuff/librarian-base-packages
45     fi
46 fi
47
48 if [ "$OS" == 'ubuntu' ]; then
49     if [[ ! -f /.puphpet-stuff/librarian-libgemplugin-ruby ]]; then
50         echo 'Updating libgemplugin-ruby (Ubuntu only)'
51         apt-get install -y libgemplugin-ruby >/dev/null
52         echo 'Finished updating libgemplugin-ruby (Ubuntu only)'
53
54         touch /.puphpet-stuff/librarian-libgemplugin-ruby
55     fi
56
57     if [ "$CODENAME" == 'lucid' ] && [ ! -f /.puphpet-stuff/librarian-rubygems-update ]; then
58         echo 'Updating rubygems (Ubuntu Lucid only)'
59         echo 'Ignore all "conflicting chdir" errors!'
60         gem install rubygems-update >/dev/null
61         /var/lib/gems/1.8/bin/update_rubygems >/dev/null
62         echo 'Finished updating rubygems (Ubuntu Lucid only)'
63
64         touch /.puphpet-stuff/librarian-rubygems-update
65     fi
66 fi
67
68 if [[ ! -f /.puphpet-stuff/librarian-puppet-installed ]]; then
69     echo 'Installing librarian-puppet'
70     gem install librarian-puppet >/dev/null
71     echo 'Finished installing librarian-puppet'
72
73     echo 'Running initial librarian-puppet'
74     cd "$PUPPET_DIR" && librarian-puppet install --clean >/dev/null
75     echo 'Finished running initial librarian-puppet'
76
77     touch /.puphpet-stuff/librarian-puppet-installed
78 else
79     echo 'Running update librarian-puppet'
80     cd "$PUPPET_DIR" && librarian-puppet update >/dev/null
81     echo 'Finished running update librarian-puppet'
82 fi