Skip to content

Instantly share code, notes, and snippets.

@corrigat
Last active February 18, 2021 01:23
Show Gist options
  • Save corrigat/69a5e0a19bf317206998c27b1c950235 to your computer and use it in GitHub Desktop.
Save corrigat/69a5e0a19bf317206998c27b1c950235 to your computer and use it in GitHub Desktop.
linux tricks for packer
#!/bin/bash
set -e
set -x
CMAKE_VERSION=3.14.5
echo "Installing cmake $CMAKE_VERSION"
#Use newer curl on centos5
PATH=/usr/local/bin:$PATH
my_cpus=$(cat /proc/cpuinfo | grep processor | wc -l)
# For user-agnostic chowning and path resolution
whoami=$(whoami)
# Virtual disks expand, then that's it. Let's do things that take up space
# but aren't needed in the final product in tmpfs to keep final disk image
# size down. You will need more memory assigned to the VM or instance during
# the build, but your final image will not have expanded to include all your
# source tarballs and compiled objects.
mkdir cmake
sudo mount -t tmpfs -o size=4G tmpfs cmake
chown -R $whoami:$whoami cmake
pushd cmake
wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}.tar.gz
tar xzf cmake-${CMAKE_VERSION}.tar.gz
cd cmake-${CMAKE_VERSION}
./configure
if [[ ! -z "${my_cpus}" ]]; then
make -j$my_cpus
else
make
fi
sudo make install
popd
sudo umount cmake #poof
rm -rf cmake*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment