Skip to content

Instantly share code, notes, and snippets.

@tonnenpinguin
Last active March 15, 2017 14:40
Show Gist options
  • Save tonnenpinguin/31e1ce897d2a0f49c009552fa7fd5c75 to your computer and use it in GitHub Desktop.
Save tonnenpinguin/31e1ce897d2a0f49c009552fa7fd5c75 to your computer and use it in GitHub Desktop.
Initial setup to get chef-client running on raspbian
#!/bin/bash
: <<'END' # Block comment
Use this script to prepare a clean raspbian image to run chef-client
Do not forget to add an empty file named "ssh" on the "boot" partition of your raspbian image to enable the ssh daemon.
If you did not run ssh-keygen before on your host machine, please do so before running this script.
This script sets up the debian testing packages as ruby 2.3 is currently not available in jessy. It also adds a pinning entry so packages available in jessy are preferred.
Afterwards it installs the chef gem and we are ready to bootstrap our new node :)
END
if [ $# -ne 1 ]; then
echo "usage: $0 ip_address"
fi
sshpass -V > /dev/null
if [ $? -ne 0 ]; then
sudo apt install sshpass
fi
ip=$1
username="pi"
pw="raspberry"
#delete old keys (from former trials :) ) from your known_hosts file
ssh-keygen -f "~/.ssh/known_hosts" -R $ip
#add our key to the raspberry without it requesting a password
sshpass -p $pw ssh-copy-id -o "StrictHostKeyChecking no" $username@$ip
# This is where the fun begins
ssh $username@$ip <<ENDSSH
echo "$pw" | sudo -S ls #trigger sudo password entry
sudo -i
echo "deb http://mirrordirector.raspbian.org/raspbian/ testing main contrib non-free rpi" | tee -a /etc/apt/sources.list
echo -e "Package: *\nPin: release a=testing\nPin-Priority: 400\n" | tee -a /etc/apt/preferences.d/testing
apt-get update
echo "Updating time"
apt-get -y install ntp ntpdate
service ntp stop
ntpdate -s time.nist.gov
service ntp start
echo "Installing ruby"
apt-get install -t testing -y ruby-dev
echo "Installing chef"
gem install chef
#echo "192.168.0.8 chef-server.test" | tee -a /etc/hosts
ENDSSH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment