Skip to content

Instantly share code, notes, and snippets.

@sevaine
Created February 27, 2014 01:29
Show Gist options
  • Save sevaine/9242470 to your computer and use it in GitHub Desktop.
Save sevaine/9242470 to your computer and use it in GitHub Desktop.
Build executable tarball
### header.sh
#!/bin/sh
AWK=$(which awk 2>/dev/null)
PACKAGES="ruby rubygems git puppet"
TAR_FILENAME="puppetmaster_build.tar.gz"
TMPDIR=$(mktemp -d /tmp/NNNNN)
LINES=$(grep -n '###ENDSCRIPT###' $0 | cut -d':' -f1)
TAR_LINES=$(expr $(wc -l $0) - ${LINES})
tail -n ${TAR_LINES} $0 | cd ${TMPDIR} && tar zxvf -
sudo yum -y install ${PACKAGES}
sudo gem install rake bundler
cd ${TMPDIR}/puppetmaster_build && rake
###ENDSCRIPT###
### composite.sh
#!/bin/sh
cat $1 $2 > output.tar.sh
@denmat
Copy link

denmat commented Feb 28, 2014

Here's what I ended up with:
the unset stuff is because I use rvm on my vagrant host.

cat bootstrap/bootstrapper.sh 
#!/bin/sh
unset GEM_HOME
unset IRBRC
unset MY_RUBY_HOME
unset RUBY_VERSION
unset GEM_PATH
export PATH=/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/vagrant/bin:/home/vagrant/bin

AWK=$(which awk 2>/dev/null)
sudo rm -f /etc/yum.repos.d/*.repo
curl http://<host>/repo/OracleLinux/OL6/$1.repo -o /etc/yum.repos.d/$1.repo 
curl http://<host>/repo/puppetlabs/puppetlabs.repo -o /etc/yum.repos.d/puppetlab.repo
PACKAGES="ruby rubygems git"
TAR_FILENAME="puppet_bootstrapper.tar.gz"
TMPDIR=$(mktemp -d /tmp/puppet_bootstrap-XXXX)
LINES=`awk '/^###ENDSCRIPT###/ {print NR + 1; exit 0; }' $0`
tail -n+$LINES $0 | tar zx -C $TMPDIR
pushd $TMPDIR
sudo yum makecache
sudo yum -y install ${PACKAGES}
sudo /usr/bin/gem install rake bundler --no-rdoc --no-ri
sudo bash -c "export OLE_VERSION=$1 PUPPET_VERSION=$2; bundle install && bundle exec rake"
popd
rm -rf $TMPDIR
exit 0
###ENDSCRIPT###


cat bootstrap/build.sh 
#!/bin/bash

compress() {
  tar zcf puppet_bootstrapper.tar.gz ../
}

create_installer() {
  cat bootstrapper.sh puppet_bootstrapper.tar.gz > ../installer.sh
  cat bootstrapper_rvm.sh puppet_bootstrapper.tar.gz > ../installer_rvm.sh
  chmod 755 ../installer*.sh
}

compress
create_installer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment