build/build_puppet.sh
changeset 407 2dba812c7ef2
child 467 762fc0eb4946
equal deleted inserted replaced
406:cf0f23803a53 407:2dba812c7ef2
       
     1 #!/usr/bin/env bash -l
       
     2 
       
     3 set -e
       
     4 
       
     5 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
       
     6 
       
     7 VAGRANT_STARTED=false
       
     8 
       
     9 green="\x1B[0;32m" # '\e[1;32m' is too bright for white bg.
       
    10 blue="\x1B[1;34m"
       
    11 endColor="\x1B[0m"
       
    12 
       
    13 function echoblue() {
       
    14     echo -e "${blue}$1${endColor}"
       
    15 }
       
    16 
       
    17 function install() {
       
    18     pushd "$DIR"
       
    19 
       
    20     echoblue "---> checking vagrant"
       
    21     if vagrant status | grep -q -v "running"; then
       
    22         echoblue "---> starting vagrant"
       
    23         # if which virtualenvwrapper.sh > /dev/null 2>&1 ; then
       
    24         #     echoblue "---> activating ansible"
       
    25         #     source `which virtualenvwrapper.sh`
       
    26         #     workon ansible
       
    27         # fi
       
    28         vagrant up
       
    29         VAGRANT_STARTED=true
       
    30         # if type -t deactivate > /dev/null 2>&1 ; then
       
    31         #     deactivate
       
    32         # fi
       
    33     fi
       
    34 
       
    35     echoblue "---> done"
       
    36 
       
    37     popd > /dev/null
       
    38 
       
    39     return 0
       
    40 }
       
    41 
       
    42 function usage() {
       
    43     cat <<EOF
       
    44 Usage: $0 [-I] [-h]
       
    45     -I : do not run install
       
    46     -h : print this message
       
    47 EOF
       
    48 }
       
    49 
       
    50 environment=""
       
    51 do_install=true
       
    52 
       
    53 
       
    54 while getopts "Ih" opt; do
       
    55   case $opt in
       
    56     I) do_install=false ;;
       
    57     h) usage; exit 0 ;;
       
    58     \?) usage >&2; exit 1 ;;
       
    59   esac
       
    60 done
       
    61 shift $((OPTIND-1))
       
    62 
       
    63 echo "do_install: $do_install"
       
    64 [[ "$do_install" == true ]] && echoblue "DO INSTALL" && install;
       
    65 
       
    66 pushd "$DIR"
       
    67 
       
    68 echoblue "---> cleaning build folder"
       
    69 rm -fr root-puppet
       
    70 
       
    71 echoblue "---> creating build folder"
       
    72 mkdir -p root-puppet/var/lib/puppet/provision
       
    73 mkdir -p root-puppet/etc/puppet/hiera
       
    74 
       
    75 echoblue "---> copying provision files"
       
    76 rsync --exclude='.git' --exclude='.hg*' --exclude='custom.yaml' -aviuPz ../dev/provisioning/ root-puppet/var/lib/puppet/provision/
       
    77 echoblue "---> copying provision files done"
       
    78 
       
    79 echoblue "---> copying template file"
       
    80 cp -a ../dev/provisioning/custom.yaml.tmpl root-puppet/etc/puppet/hiera
       
    81 echoblue "---> copying template files done"
       
    82 
       
    83 #  :datadir: "."
       
    84 echoblue "---> add path in root-puppet/var/lib/puppet/provision/hiera.yaml"
       
    85 sed -i "" -E 's/^([[:space:]]+\:datadir\:).*$/\1 \"\/etc\/puppet\/hiera\"/' root-puppet/var/lib/puppet/provision/hiera.yaml
       
    86 echoblue "---> add path in root-puppet/var/lib/puppet/provision/hiera.yaml done"
       
    87 
       
    88 
       
    89 echoblue "---> building package"
       
    90 vagrant ssh -c "/vagrant/build_rpm_puppet.sh"
       
    91 echoblue "---> building package done"
       
    92 
       
    93 if [ "$VAGRANT_STARTED" = true ]; then
       
    94     echoblue "---> Stopping vagrant"
       
    95     vagrant halt
       
    96     echoblue "---> Stopping vagrant done"
       
    97 fi
       
    98 
       
    99 popd > /dev/null
       
   100 
       
   101 echoblue "---> done"
       
   102