├── .chefignore ├── .gitignore ├── .rspec ├── .rubocop.yml ├── .travis.yml ├── Berksfile ├── Gemfile ├── LICENSE ├── README.md ├── Rakefile ├── attributes └── default.rb ├── files └── default │ └── resize2fs_once ├── metadata.rb ├── recipes ├── default.rb └── resize_root.rb ├── spec └── spec_helper.rb └── templates └── default ├── config.txt.erb └── inittab.erb /.chefignore: -------------------------------------------------------------------------------- 1 | # Put files/directories that should be ignored in this file when uploading 2 | # or sharing to the community site. 3 | # Lines that start with '# ' are comments. 4 | 5 | # OS generated files # 6 | ###################### 7 | .DS_Store 8 | Icon? 9 | nohup.out 10 | ehthumbs.db 11 | Thumbs.db 12 | 13 | # SASS # 14 | ######## 15 | .sass-cache 16 | 17 | # EDITORS # 18 | ########### 19 | \#* 20 | .#* 21 | *~ 22 | *.sw[a-z] 23 | *.bak 24 | REVISION 25 | TAGS* 26 | tmtags 27 | *_flymake.* 28 | *_flymake 29 | *.tmproj 30 | .project 31 | .settings 32 | mkmf.log 33 | 34 | ## COMPILED ## 35 | ############## 36 | a.out 37 | *.o 38 | *.pyc 39 | *.so 40 | *.com 41 | *.class 42 | *.dll 43 | *.exe 44 | */rdoc/ 45 | 46 | # Testing # 47 | ########### 48 | .watchr 49 | .rspec 50 | spec/* 51 | spec/fixtures/* 52 | test/* 53 | features/* 54 | Guardfile 55 | Procfile 56 | 57 | # SCM # 58 | ####### 59 | .git 60 | */.git 61 | .gitignore 62 | .gitmodules 63 | .gitconfig 64 | .gitattributes 65 | .svn 66 | */.bzr/* 67 | */.hg/* 68 | */.svn/* 69 | 70 | # Berkshelf # 71 | ############# 72 | Berksfile 73 | Berksfile.lock 74 | cookbooks/* 75 | tmp 76 | 77 | # Cookbooks # 78 | ############# 79 | CONTRIBUTING 80 | CHANGELOG* 81 | 82 | # Strainer # 83 | ############ 84 | Colanderfile 85 | Strainerfile 86 | .colander 87 | .strainer 88 | 89 | # Vagrant # 90 | ########### 91 | .vagrant 92 | Vagrantfile 93 | 94 | # Travis # 95 | ########## 96 | .travis.yml 97 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant 2 | Berksfile.lock 3 | *~ 4 | *# 5 | .#* 6 | \#*# 7 | .*.sw[a-z] 8 | *.un~ 9 | /cookbooks 10 | 11 | # Bundler 12 | Gemfile.lock 13 | bin/* 14 | .bundle/* 15 | 16 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | --format progress 3 | --order rand 4 | --require spec_helper 5 | --tag focus 6 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | Metrics/LineLength: 2 | Enabled: false 3 | 4 | Style/SingleSpaceBeforeFirstArg: 5 | Enabled: false 6 | 7 | Style/StringLiterals: 8 | Enabled: false 9 | 10 | AllCops: 11 | Exclude: 12 | - vendor/**/* 13 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | cache: bundler 3 | language: ruby 4 | 5 | env: 6 | - CHEF_VERSION=master 7 | - CHEF_VERSION=12.4.1 8 | - CHEF_VERSION=12.4.0 9 | - CHEF_VERSION=12.3.0 10 | - CHEF_VERSION=12.2.1 11 | - CHEF_VERSION=12.1.2 12 | - CHEF_VERSION=12.1.1 13 | - CHEF_VERSION=12.1.0 14 | 15 | rvm: 16 | - 2.0 17 | - 2.1 18 | - 2.2 19 | - ruby-head 20 | 21 | matrix: 22 | allow_failures: 23 | - rvm: ruby-head 24 | - env: CHEF_VERSION=master 25 | 26 | notifications: 27 | email: 28 | on_success: change 29 | on_failure: always 30 | 31 | #script: 32 | # - bundle exec rubocop 33 | # - bundle exec rspec --color --format progress 34 | # - bundle exec foodcritic -f any . 35 | -------------------------------------------------------------------------------- /Berksfile: -------------------------------------------------------------------------------- 1 | source "https://supermarket.chef.io" 2 | 3 | metadata 4 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | group :test do 4 | gem 'foodcritic' 5 | gem 'rubocop' 6 | end 7 | 8 | group :unit do 9 | gem 'berkshelf' 10 | gem 'chefspec' 11 | end 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2013 Smarkets Ltd 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Cookbook](http://img.shields.io/cookbook/v/nginx.svg)](https://github.com/Padgett/chef-raspberry-pi) 2 | [![Build Status](http://img.shields.io/travis/Padgett/chef-raspberry-pi.svg)](http://travis-ci.org/Padgett/chef-raspberry-pi) 3 | [![Dependencies](http://img.shields.io/gemnasium/Padgett/chef-raspberry-pi.svg)](https://gemnasium.com/Padgett/chef-raspberry-pi) 4 | 5 | # raspberry-pi Cookbook 6 | 7 | Cookbook to configure a Raspberry Pi from scratch. Manages the 8 | boot config file and optionally resizes the root partition. 9 | 10 | # Authors 11 | 12 | - Original Author: Russ Garrett (russ.garrett@smarkets.com) 13 | - Additional Features: Joshua Padgett 14 | - Contributor: Federico Castagnini 15 | 16 | # How To Use 17 | 18 | Coming Soon 19 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'rubocop/rake_task' 2 | require 'foodcritic' 3 | require 'rspec/core/rake_task' 4 | 5 | task default: ['style'] 6 | 7 | # Style tests. Rubocop and Foodcritic 8 | namespace :style do 9 | desc 'Run Ruby style checks' 10 | RuboCop::RakeTask.new(:ruby) 11 | 12 | desc 'Run Chef style checks' 13 | FoodCritic::Rake::LintTask.new(:chef) 14 | end 15 | 16 | desc 'Run all style checks' 17 | task style: ['style:ruby', 'style:chef'] 18 | 19 | # Rspec and ChefSpec 20 | desc 'Run ChefSpec examples' 21 | RSpec::Core::RakeTask.new(:spec) do |t| 22 | t.verbose = false 23 | end 24 | 25 | desc 'Find notes in code' 26 | task :notes do 27 | puts `egrep --exclude=Rakefile --exclude=*.log -n -r -i '(TODO|FIXME|OPTIMIZE)' .` 28 | end 29 | -------------------------------------------------------------------------------- /attributes/default.rb: -------------------------------------------------------------------------------- 1 | default["raspberry-pi"]["overscan"] = true 2 | default["raspberry-pi"]["hdmi_mode"] = nil 3 | default["raspberry-pi"]["memory_split"] = { 4 | "256" => 64, 5 | "512" => 128, 6 | "1024" => 128 7 | } 8 | -------------------------------------------------------------------------------- /files/default/resize2fs_once: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ### BEGIN INIT INFO 3 | # Provides: resize2fs_once 4 | # Required-Start: 5 | # Required-Stop: 6 | # Default-Start: 2 3 4 5 S 7 | # Default-Stop: 8 | # Short-Description: Resize the root filesystem to fill partition 9 | # Description: 10 | ### END INIT INFO 11 | 12 | . /lib/lsb/init-functions 13 | 14 | case "$1" in 15 | start) 16 | log_daemon_msg "Starting resize2fs_once" && 17 | resize2fs /dev/mmcblk0p2 && 18 | rm /etc/init.d/resize2fs_once && 19 | update-rc.d resize2fs_once remove && 20 | log_end_msg $? 21 | ;; 22 | *) 23 | echo "Usage: $0 start" >&2 24 | exit 3 25 | ;; 26 | esac 27 | -------------------------------------------------------------------------------- /metadata.rb: -------------------------------------------------------------------------------- 1 | name "raspberry-pi" 2 | maintainer "Russ Garrett" 3 | maintainer_email "russ.garrett@smarkets.com" 4 | license "MIT" 5 | description "Handles initial configuration of a Raspberry Pi" 6 | long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) 7 | version "0.2.0" 8 | -------------------------------------------------------------------------------- /recipes/default.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: raspberry-pi 3 | # Recipe:: default 4 | 5 | file "/etc/profile.d/raspi_config.sh" do 6 | action :delete 7 | end 8 | 9 | template "/boot/config.txt" do 10 | source "config.txt.erb" 11 | end 12 | 13 | template "/etc/inittab" do 14 | source "inittab.erb" 15 | end 16 | -------------------------------------------------------------------------------- /recipes/resize_root.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Resize the root partition to fit the SD card. 3 | # This is copied mostly verbatim from raspi-config 4 | # 5 | 6 | unless File.exist?('/etc/partition-resize-stamp') 7 | 8 | bash "resize_partition" do 9 | user "root" 10 | returns [1, 0] # fdisk will return an error if it can't re-read the partition table (normal) 11 | code <<-EOH 12 | PART_START=$(parted /dev/mmcblk0 -ms unit s p | grep "^2" | cut -f 2 -d:) 13 | [ "$PART_START" ] || return 1 14 | # Return value will likely be error for fdisk as it fails to reload the 15 | # partition table because the root fs is mounted 16 | fdisk /dev/mmcblk0 < 2 | # uncomment if you get no picture on HDMI for a default "safe" mode 3 | #hdmi_safe=1 4 | 5 | <% if node["raspberry-pi"]["overscan"] %> 6 | 7 | overscan_left=16 8 | overscan_right=16 9 | overscan_top=16 10 | overscan_bottom=16 11 | 12 | disable_overscan=0 13 | <% else %> 14 | overscan_left=0 15 | overscan_right=0 16 | overscan_top=0 17 | overscan_bottom=0 18 | 19 | disable_overscan=1 20 | <% end %> 21 | 22 | # uncomment to force a console size. By default it will be display's size minus 23 | # overscan. 24 | #framebuffer_width=1280 25 | #framebuffer_height=720 26 | 27 | # uncomment if hdmi display is not detected and composite is being output 28 | #hdmi_force_hotplug=1 29 | 30 | # uncomment to force a specific HDMI mode (this will force VGA) 31 | #hdmi_group=1 32 | 33 | <% if node["raspberry-pi"]["hdmi_mode"] %> 34 | hdmi_mode=<%=node["raspberry-pi"]["hdmi_mode"]%> 35 | <% end %> 36 | 37 | # uncomment to force a HDMI mode rather than DVI. This can make audio work in 38 | # DMT (computer monitor) modes 39 | #hdmi_drive=2 40 | 41 | # uncomment to increase signal to HDMI, if you have interference, blanking, or 42 | # no display 43 | #config_hdmi_boost=4 44 | 45 | # uncomment for composite PAL 46 | #sdtv_mode=2 47 | 48 | #uncomment to overclock the arm. 700 MHz is the default. 49 | #arm_freq=800 50 | 51 | #Set GPU/CPU memory split 52 | gpu_mem_256=<%= node["raspberry-pi"]["memory_split"]["256"] %> 53 | gpu_mem_512=<%= node["raspberry-pi"]["memory_split"]["512"] %> 54 | gpu_mem_1024=<%= node["raspberry-pi"]["memory_split"]["1024"] %> 55 | -------------------------------------------------------------------------------- /templates/default/inittab.erb: -------------------------------------------------------------------------------- 1 | # Generated by Chef 2 | 3 | # /etc/inittab: init(8) configuration. 4 | # $Id: inittab,v 1.91 2002/01/25 13:35:21 miquels Exp $ 5 | 6 | # The default runlevel. 7 | id:2:initdefault: 8 | 9 | # Boot-time system configuration/initialization script. 10 | # This is run first except when booting in emergency (-b) mode. 11 | si::sysinit:/etc/init.d/rcS 12 | 13 | # What to do in single-user mode. 14 | ~~:S:wait:/sbin/sulogin 15 | 16 | # /etc/init.d executes the S and K scripts upon change 17 | # of runlevel. 18 | # 19 | # Runlevel 0 is halt. 20 | # Runlevel 1 is single-user. 21 | # Runlevels 2-5 are multi-user. 22 | # Runlevel 6 is reboot. 23 | 24 | l0:0:wait:/etc/init.d/rc 0 25 | l1:1:wait:/etc/init.d/rc 1 26 | l2:2:wait:/etc/init.d/rc 2 27 | l3:3:wait:/etc/init.d/rc 3 28 | l4:4:wait:/etc/init.d/rc 4 29 | l5:5:wait:/etc/init.d/rc 5 30 | l6:6:wait:/etc/init.d/rc 6 31 | # Normally not reached, but fallthrough in case of emergency. 32 | z6:6:respawn:/sbin/sulogin 33 | 34 | # What to do when CTRL-ALT-DEL is pressed. 35 | ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now 36 | 37 | # Action on special keypress (ALT-UpArrow). 38 | #kb::kbrequest:/bin/echo "Keyboard Request--edit /etc/inittab to let this work." 39 | 40 | # What to do when the power fails/returns. 41 | pf::powerwait:/etc/init.d/powerfail start 42 | pn::powerfailnow:/etc/init.d/powerfail now 43 | po::powerokwait:/etc/init.d/powerfail stop 44 | 45 | # /sbin/getty invocations for the runlevels. 46 | # 47 | # The "id" field MUST be the same as the last 48 | # characters of the device (after "tty"). 49 | # 50 | # Format: 51 | # ::: 52 | # 53 | # Note that on most Debian systems tty7 is used by the X Window System, 54 | # so if you want to add more getty's go ahead but skip tty7 if you run X. 55 | # 56 | 1:2345:respawn:/sbin/getty 38400 tty1 57 | 2:23:respawn:/sbin/getty 38400 tty2 58 | 3:23:respawn:/sbin/getty 38400 tty3 59 | 4:23:respawn:/sbin/getty 38400 tty4 60 | 5:23:respawn:/sbin/getty 38400 tty5 61 | 6:23:respawn:/sbin/getty 38400 tty6 62 | 63 | #Spawn a getty on Raspberry Pi serial line 64 | T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100 65 | 66 | --------------------------------------------------------------------------------