diff --git a/Customfile b/Customfile new file mode 100644 index 0000000..d667f7a --- /dev/null +++ b/Customfile @@ -0,0 +1,4 @@ +config.vm.provider "virtualbox" do |v| + v.memory = 3072 + v.cpus = 4 +end diff --git a/LICENSE b/LICENSE index 68e9012..ff90f3a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2011 Florian Gilcher , Felix Gilcher +Copyright (c) 2011-2012 Florian Gilcher , Felix Gilcher , Nicholas Hutchinson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/README.md b/README.md index cbbee59..105e0a9 100644 --- a/README.md +++ b/README.md @@ -1,124 +1,66 @@ # Raspberry Pi Devbox -A virtual machine built for raspberry pi development, based on http://russelldavis.org/2012/01/27/setting-up-a-vm-for-raspberry-pi-development-using-virtualbox-scratchbox2-qemu-part-1/ +A [Vagrant](http://vagrantup.com) recipe for an Ubuntu 12.04 virtual machine, intented to make C/C++ development for Raspberry Pi a less painful experience. Forked from , updated to use a Raspbian 8 Jessie chroot and the latest [Raspberry Pi cross-compiler toolchain (gcc 4.8.3)](https://github.com/raspberrypi/tools). -## Words of Caution +This VM includes a sandboxed installation ("chroot") of [Raspbian](http://www.raspbian.org), an ARM variant of the Debian Linux distribution optimized for Raspberry Pi. Use of the sandbox is mediated by a cross-compiling tool called [ScratchBox2](http://maemo.gitorious.org/scratchbox2). ScratchBox2 craftily translates the ARM executables bundled with Raspbian such that they run on your Intel box. -Vagrant uses a default user with a default password and a well known keypair for authentication. The default user has superuser access. Running a vagrant box in a configuration that makes it accessible from the outside is a major security risk. The default configuration prevents outside access by using NAT and host-only networking exclusively. Do not tamper with that configuration unless you know what you're doing. If you need to run a vagrant box in a network-accessible configuration at least change the passwords and keypairs. +Why is this so nice? Suppose you have C++ app that you want to build for the Raspberry Pi, but it requires a bunch of third-party libraries. Do you really want to hunt down these libraries, their dependencies, their dependencies dependencies, their dependencies dependencies dependencies and so on, until you're able to build your own app? It should be clear that that way lies madness. Perhaps you'll just copy the headers and libraries from your Raspberry to your Intel box, and point your compiler at those. That might work, but it'll be fragile and annoying. -## Virtualbox +How about we let the Raspbian folks do all the hard work? With ScratchBox2, you can simply apt-get to your heart's content. Just type: -The basic virtualization-layer is [[Virtualbox | https://www.virtualbox.org/]]. Any current version should do, however the guest additions are pinned to version of the GA release at the time the base box was built (4.1.8). A mismatch between the guest-additions and the virtualbox version may result in strange behavior, mostly affecting shared folders and networking. To update the guest additions follow the instructions in the virtualbox manual. + sb2 -eR apt-get install ... -## Vagrant - -[[Vagrant | http://vagrantup.com/]] is the scripting toolkit used to control all interaction with the devbox. Any recent version of vagrant (>= 0.9) should work. - -A full guide on vagrant can be found on the [[Vagrant site | http://vagrantup.com/docs ]]. As a short primer, the following commands should be sufficient: - -* `vagrant up ` start the given box. If the box has not been initialized and created, this will download the basebox as required, bootstrap it and run the provisioner. Running `vagrant up` when the box is already running is a NOOP and has no effect. -* `vagrant halt ` stop the given box. Has no effect if the box is not running. May require an invocation using the `--force` flag (`vagrant halt --force `) if the box crashed, locked up or cannot be accessed via `vagrant ssh` -* `vagrant reload ` stop and start the given box. Runs the provisioner. -* `vagrant provision ` Runs the provisioner. -* `vagrant destroy ` destroys the given box. This is useful if for some reason the box has been damaged or to free diskspace. Running `vagrant up` after running `vagrant destroy` bootstraps a new box. -* `vagrant ssh ` open an ssh connection to the given box. - -By default all boxes are set to boot in headleass mode, that is without a graphical user interface. Gui mode can be enabled by uncommenting the `box.vm.boot_mode = :gui` line in the appropriate section of the vagrantfile. - -## Hardware - -At the moment, the devbox only works in 64bit processors with Vanderpool (hardware virtualization, VT-x for Intel, AMD-V for AMD processors) enabled. While the first can be fixed by compiling a 32bit devbox, the latter will lead to an excessive performance penalty. Be aware that even if a processor supports implements VT-x, some notebook vendors deactivate it. Known states: +This executes `apt-get` in the default ScratchBox2 container (in our case, we only have the one. It's called "raspberry".) The `-e` flag is for chroot (emulated) mode; `-R` runs the command as the equivalent of *root* in the sandboxed environment. For a slightly more thorough explanation of ScratchBox2, see these presentation slides: . -* Dell Latitude: works out of the box - - Some Dell models deactivate VT-x by default, but this can be changed in BIOS -* All Apple notebooks currently available work -* All Intel i3/5/7 processors support VT-x, if not disabled by the vendor. +## Installation +1. Install both VirtualBox and Vagrant. +2. In a terminal, execute `git clone git://github.com/nickhutchinson/raspberry-devbox.git && cd raspberry-devbox` +3. Execute `vagrant up` to launch and provision your Virtual Machine. -## Puppet - -Package and config-file management is handled by puppet and the vagrant puppet provisioner. The required puppet installation is in the base box, all manifests can be found in the toolbox repository. No puppet installation is needed on the host system. - -## Installation / First Use - -* Install Virtualbox and Vagrant. See [[Installing Vagrant | http://vagrantup.com/docs/getting-started/index.html]] for a guide. You may skip the last step. -* Clone the repository using a git client of your choice. Mac users that are not comfortable using the commandline may use [[Github for Mac | http://mac.github.com/]] to download the repository and any updates -* Open the shell of your choice and navigate to the repository -* Run `vagrant up ` to boot the box. See the list of available boxes for the name. - -Vagrant will now download the basebox, bootstrap the environment and run the provisioner for the first time. Since the basebox must be downloaded and some source must be compiled, the first run may take some time depending on your machines speed and network connection. No supervision should be required, running the install over night should be just fine. Future runs will be faster since the software is only installed on the first run. Future runs should not require network connectivity, execpt when destroying and rebuilding a box. - -## Pulling Updates +Vagrant will now download the basebox, bootstrap the environment and run the provisioner for the first time. Since the basebox and numerous packages must be downloaded, the first run may take some time depending on your network connection. No supervision should be required; running the install overnight should be just fine. Future runs will be much faster, and won't require network connectivity. -Pulling updates is done by updating the repository to get the latest puppet manifests and/or remove the src folder as well as the raspberry_pi_development folder inside the box to trigger a redownload of the src and a rebuild of the packages. After updating the repository the provisioner needs to be triggered by running `vagrant provision ` on the console. This will install any new packages and update config-files as required. The provisioner is also triggered on each fresh boot of the devbox. +If like to see words dribble down your screen, you can monitor the bootstrap progress by running `vagrant ssh` to ssh into your VM, and then `tail -F ~/raspberry-dev/rootfs/debootstrap/debootstrap.log` -## Help, Something went wrong. +After installation has completed, you should find: -* Sometimes vagrant fails to mount the shared folders for the puppet provisioner. This usually results in puppet complaining about a missing file or folder. Reloading the box using `vagrant reload ` usually solves this problem. -* Sometimes dependencies between puppet packages are not modeled correctly. This usually results in puppet printing the message "Skipping because of failed dependencies" to the console. This problem usually can be solved by re-running the puppet provisioner using `vagrant provision `. Sometimes multiple runs are required to solve the issue. Please report such issues so that we can fix the dependencies. -* Box does not boot properly and cannot be accessed via `vagrant ssh`: Enable gui mode by uncommenting the `box.vm.boot_mode = :gui` line in the config and reload the box using the `--force` flag. Observe the error messages. +- In `~/raspberry-dev/rootfs` + - the [Raspbian](http://www.raspbian.org) chroot. +- In `/opt/raspberry-dev` + - the official [GCC 4.8.3 cross-compiler toolchain](https://github.com/raspberrypi/tools): `arm-linux-gnueabihf-gcc`, `arm-linux-gnueabihf-ld` and so on. + - [QEmu](http://wiki.qemu.org/Main_Page) 1.3.0 + - [ScratchBox2](http://maemo.gitorious.org/scratchbox2) @ git tag 2.3.90 (earlier releases didn't seem to work) -## Boxes +The default configuration allocates 4 CPU cores and 4 GB of RAM to the VM. This can be configured by editing the following lines in the `Vagrantfile`: -### No X (nox) + v.memory = 4096 + v.cpus = 4 -Start using `vagrant up nox`. The box does not include an X environment. Instead it allows ssh access and exports the home directory via nfs. This way you can develop using your favorite IDE on your host system. A box that contains a full X11-environment will be provided. +## Example Usage +* Starting the VM: in the program root directory, run `vagrant up` to start the VM, then `vagrant ssh` to enter it. +* `sb2 make` make using host cross compiler toolchain. +* `sb2 -e make` make using emulated target toolchain. +* `sb2 -eR make install` install in emulation mode as root. -## Tips & Tricks +## VirtualBox -### Connecting to the Box +The basic virtualization layer is [VirtualBox](https://www.virtualbox.org). Any current version should do, however the guest additions are pinned to current version at the time the basebox was built (4.2.0). A mismatch between the guest additions and the VirtualBox version may result in strange behaviour, mostly affecting shared folders and networking. To update the guest, additions follow the instructions in the VirtualBox manual. -Using `vagrant ssh` is not required to connect to the box. Vagrant uses a regular ssh connection with a special, known keypair. To connect to the box using regular ssh command follow this procedure: - -* Download the default keypair from the [[git repository|https://github.com/mitchellh/vagrant/tree/master/keys/]] and place the private key in a convenient location. `~/.ssh/vagrant` is a suitable location on unix/linux/macos systems. -* Make sure that the key is user-readable only (0600 on unix-style systems) -* Add the following section to the ssh configfile -* use `ssh app-vagrant` to connect to the appserver -* Enable agent-forwarding so you can check out and update the github repositories - -```` -Host app-vagrant # or any other alias - Hostname 33.33.33.20 # ip of the box you want to connect to - User vagrant - PreferredAuthentications publickey - IdentityFile ~/.ssh/vagrant - ForwardAgent yes - StrictHostKeyChecking no - UserKnownHostsFile /dev/null -```` - -This is especially useful in conjunction with the iterm2 stored profiles feature. - -### GIT_* Environment Variables - -The ssh daemon in the box is configured to accept all environment variables starting with `GIT_*`. Setting the variables on the host server allows to send those variables to the environment in the devbox. The git command will use those variables to credit commits to the proper author. The following two bits of configuration are required: - -Add the variables to the shell of your choice, for example in .bashrc: - -```` -export GIT_AUTHOR_EMAIL= -export GIT_AUTHOR_NAME='' -export GIT_COMMITTER_EMAIL= -export GIT_COMMITTER_NAME='' -export GIT_EDITOR=/usr/bin/vim -```` - -Configure ssh to send the env variables to the guest system: - -```` -Host app-vagrant - SendEnv GIT_* -```` +## Vagrant -## Bugs, Fixes, Improvement +[Vagrant](http://vagrantup.com) is the scripting toolkit used to control all interaction with the devbox. A full guide on Vagrant can be found on the [Vagrant site](http://vagrantup.com). As a short primer, the following commands should be sufficient: -If you encounter a bug, please file a ticket. If you'd like to help, fork the repository, make your changes and send me a pull request. Please use feature-branches :). +* `vagrant up ` start the given box. If the box has not been initialized and created, this will download the basebox as required, bootstrap it and run the provisioner. Running `vagrant up` when the box is already running is a NOOP and has no effect. +* `vagrant halt ` stop the given box. Has no effect if the box is not running. May require an invocation using the `--force` flag (`vagrant halt --force `) if the box crashed, locked up or cannot be accessed via `vagrant ssh` +* `vagrant reload ` stop and start the given box. Runs the provisioner. +* `vagrant provision ` Runs the provisioner. +* `vagrant destroy ` destroys the given box. This is useful if for some reason the box has been damaged or to free disk space. Running `vagrant up` after running `vagrant destroy` bootstraps a new box. +* `vagrant ssh ` open an ssh connection to the given box. + +## Puppet -## Todo +Provisioning of the Virtual Machine is handled by [Puppet](http://puppetlabs.com). Take a look at the `raspberry_dev` module. -* all of this is still quite rough -* the path to qemu and scratchbox2 is currently not set up properly, add a 'export PATH="/home/vagrant/raspberry_pi_development/qemu/bin/:/home/vagrant/raspberry_pi_development/scratchbox2/bin:$PATH"' to the .bashrc -* improve on the readme -* add hostonly networking and nfs share -* add a second vm that has X +## Bugs +* Some programs such as aptitude crash with segfault when run in emulation mode. Updated qemu might fix this diff --git a/Vagrantfile b/Vagrantfile index e1dec46..c60e080 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -6,12 +6,12 @@ Vagrant::Config.run do |config| # options are documented and commented below. For a complete reference, # please see the online documentation at vagrantup.com. - config.vm.define :nox do |box| + config.vm.define :nox1 do |box| # Every Vagrant virtual environment requires a box to build off of. - box.vm.box = "ubuntu-10.04.3-server-amd64-asq" + box.vm.box = "precise64" # The url from where the 'config.vm.box' box will be fetched if it # doesn't already exist on the user's system. - box.vm.box_url = "http://asquera-share.s3.amazonaws.com/boxes/base/ubuntu-10.04.3-server-amd64-asq.box" + box.vm.box_url = "http://files.vagrantup.com/precise64.box" # Boot with a GUI so you can see the screen. (Default is headless) #box.vm.boot_mode = :gui @@ -22,9 +22,16 @@ Vagrant::Config.run do |config| puppet.manifests_path = "puppetmanifests" puppet.manifest_file = "raspberry-nox.pp" puppet.module_path = "modules" - puppet.options = "" + puppet.options = ["--verbose", "--debug"] end end +end +Vagrant.configure("2") do |config| + + config.vm.provider "virtualbox" do |v| + v.memory = 4096 + v.cpus = 4 + end end diff --git a/modules/boxes/manifests/devbox.pp b/modules/boxes/manifests/devbox.pp deleted file mode 100644 index a636607..0000000 --- a/modules/boxes/manifests/devbox.pp +++ /dev/null @@ -1,170 +0,0 @@ -class boxes::devbox { - Exec { path => [ "/bin/", "/sbin/" , "/usr/bin/", "/usr/sbin/", "/home/vagrant/raspberry_pi_development/scratchbox2/bin", "/home/vagrant/raspberry_pi_development/qemu/bin" ], timeout => 600 } - - include sysconfig - include sysconfig::sudoers - include apt - include puppet - include ssh::server - - user {"vagrant": - ensure => present, - home => "/home/vagrant" - } -> file {"/home/vagrant": - ensure => directory, - owner => vagrant - } - - user {"root": - ensure => present, - home => "/root" - } -> file {"/root": - ensure => directory, - owner => root - } - - ssh::user {"vagrant": - } - - ssh::user { "root": - home => "/root" - } - - package {"git-core": - ensure => present - } - - # scratchbox build requirements - package {["libsdl1.2-dev", "libncurses5", "libncurses5-dev", "autoconf", "fakeroot", "realpath", "libc6-i386", "libc6-dev-i386"]: - ensure => present - } - - file {"/home/vagrant/src": - ensure => directory, - owner => "vagrant", - group => "vagrant" - } - - file {"/home/vagrant/raspberry_pi_development": - ensure => directory, - owner => "vagrant", - group => "vagrant" - } - - exec {"download-arm-toolchain": - command => "curl https://sourcery.mentor.com/sgpp/lite/arm/portal/package8739/ppc/arm-none-gnueabi/arm-2011.03-41-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2 > /home/vagrant/src/arm-2011.03-41-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2", - creates => "/home/vagrant/src/arm-2011.03-41-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2", - require => File["/home/vagrant/src"], - user => vagrant, - group => vagrant - } - - exec {"unpack-arm-toolchain": - command => "tar xjvf /home/vagrant/src/arm-2011.03-41-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2 -C /home/vagrant/raspberry_pi_development", - creates => "/home/vagrant/raspberry_pi_development/arm-2011.03/", - subscribe => Exec["download-arm-toolchain"], - refreshonly => true, - require => File["/home/vagrant/raspberry_pi_development"], - user => vagrant, - group => vagrant - } - - exec {"download-fedora-rootfs": - command => "curl http://fedora.roving-it.com/rootfs-f14-minimal-RC1.tar.bz2 > /home/vagrant/src/rootfs-f14-minimal-RC1.tar.bz2", - creates => "/home/vagrant/src/rootfs-f14-minimal-RC1.tar.bz2", - require => File["/home/vagrant/src"], - user => vagrant, - group => vagrant - } - - file {"/home/vagrant/raspberry_pi_development/rootfs_f14": - ensure => "directory", - require => File["/home/vagrant/raspberry_pi_development"], - owner => vagrant, - group => vagrant - } - - exec {"unpack-fedora-rootfs": - command => "tar xjvpf /home/vagrant/src/rootfs-f14-minimal-RC1.tar.bz2 -C /home/vagrant/raspberry_pi_development/rootfs_f14", - # creates => "/home/vagrant/raspberry_pi_development/rootfs_f14", - subscribe => Exec["download-fedora-rootfs"], - refreshonly => true, - require => File["/home/vagrant/raspberry_pi_development/rootfs_f14"], - # this must be run as root, we'll chown later - } - - exec {"chown-fedora-rootfs": - command => "chown -R vagrant:vagrant /home/vagrant/raspberry_pi_development/rootfs_f14", - subscribe => Exec["unpack-fedora-rootfs"], - refreshonly => true - } - - exec {"download-scratchbox2": - command => "git clone -q git://gitorious.org/scratchbox2/scratchbox2.git /home/vagrant/src/scratchbox2", - creates => "/home/vagrant/src/scratchbox2", - require => File["/home/vagrant/src"], - user => vagrant, - group => vagrant - } - - exec {"autogen-scratchbox2": - command => "/home/vagrant/src/scratchbox2/autogen.sh", - cwd => "/home/vagrant/src/scratchbox2", - creates => "/home/vagrant/src/scratchbox2/configure", - user => vagrant, - group => vagrant, - subscribe => Exec["download-scratchbox2"], - refreshonly => true - } - - exec {"install-scratchbox2": - command => "make install prefix=/home/vagrant/raspberry_pi_development/scratchbox2", - cwd => "/home/vagrant/src/scratchbox2", - creates => "/home/vagrant/raspberry_pi_development/scratchbox2", - user => vagrant, - group => vagrant, - subscribe => Exec["autogen-scratchbox2"], - refreshonly => true - } - - exec {"download-qemu": - command => "git clone -q git://git.qemu.org/qemu.git /home/vagrant/src/qemu", - creates => "/home/vagrant/src/qemu", - require => File["/home/vagrant/src"], - user => vagrant, - group => vagrant - } - - exec {"configure-qemu": - command => "/home/vagrant/src/qemu/configure --prefix=/home/vagrant/raspberry_pi_development/qemu --target-list=arm-linux-user,arm-softmmu", - cwd => "/home/vagrant/src/qemu/", - creates => "/home/vagrant/src/qemu/config.log", - user => vagrant, - group => vagrant, - subscribe => Exec["download-qemu"], - refreshonly => true - } - - exec {"install-qemu": - command => "make install", - cwd => "/home/vagrant/src/qemu", - creates => "/home/vagrant/raspberry_pi_development/qemu", - user => vagrant, - group => vagrant, - subscribe => Exec["configure-qemu"], - refreshonly => true - } - - exec {"init-scratchbox2": - command => "sb2-init raspberry /home/vagrant/raspberry_pi_development/arm-2011.03/bin/arm-none-linux-gnueabi-gcc", - cwd => "/home/vagrant/raspberry_pi_development/rootfs_f14", - environment => "HOME=/home/vagrant", - creates => "/home/vagrant/.scratchbox2", - subscribe => Exec["install-scratchbox2"], - require => [Exec["install-qemu"], Exec["unpack-fedora-rootfs"]], - refreshonly => true, - user => vagrant, - group => vagrant, - } - -} \ No newline at end of file diff --git a/modules/raspberry_dev/files/etc/profile.d/raspberry-dev.sh b/modules/raspberry_dev/files/etc/profile.d/raspberry-dev.sh new file mode 100644 index 0000000..04c2fe3 --- /dev/null +++ b/modules/raspberry_dev/files/etc/profile.d/raspberry-dev.sh @@ -0,0 +1 @@ +PATH=$PATH:/opt/raspberry-dev/bin \ No newline at end of file diff --git a/modules/raspberry_dev/files/rootfs/etc/apt/sources.list b/modules/raspberry_dev/files/rootfs/etc/apt/sources.list new file mode 100644 index 0000000..3a0e4ca --- /dev/null +++ b/modules/raspberry_dev/files/rootfs/etc/apt/sources.list @@ -0,0 +1,2 @@ +deb http://archive.raspbian.org/raspbian/ jessie main contrib non-free rpi +deb-src http://archive.raspbian.org/raspbian/ jessie main contrib non-free rpi diff --git a/modules/raspberry_dev/files/rootfs/etc/puppet/modules/raspbian/manifests/init.pp b/modules/raspberry_dev/files/rootfs/etc/puppet/modules/raspbian/manifests/init.pp new file mode 100644 index 0000000..896544e --- /dev/null +++ b/modules/raspberry_dev/files/rootfs/etc/puppet/modules/raspbian/manifests/init.pp @@ -0,0 +1,10 @@ + class raspbian { + + package {['locales', 'dialog']: + ensure => installed + } + + package {['pkg-config', 'libglib2.0-dev']: + ensure => installed + } +} diff --git a/modules/raspberry_dev/manifests/config.pp b/modules/raspberry_dev/manifests/config.pp new file mode 100644 index 0000000..bdae630 --- /dev/null +++ b/modules/raspberry_dev/manifests/config.pp @@ -0,0 +1,58 @@ + +class raspberry_dev::config { + $tools_prefix = '/opt/raspberry-dev' + $debs_dir = '/opt/raspberry-dev/debs' + $bin_dir = '/opt/raspberry-dev/bin' + + $user = 'vagrant' + $sbox2_container_path = '/home/vagrant/raspberry-dev/rootfs' + $sbox2_container_name = 'raspberry' + + $arm_gcc_path = "${bin_dir}/arm-linux-gnueabihf-gcc" + $qemu_path = "${bin_dir}/qemu-arm" + + + file {['/home/vagrant/raspberry-dev', + '/home/vagrant/raspberry-dev/rootfs']: + ensure => directory, + owner => vagrant, + group => vagrant + } + + file {['/opt/', + '/opt/raspberry-dev', + '/opt/raspberry-dev/debs']: + ensure => directory, + } + + file {'/etc/profile.d/raspberry-dev.sh': + source => 'puppet:///modules/raspberry_dev/etc/profile.d/raspberry-dev.sh', + mode => '0755' + } + + user {'vagrant': + ensure => present, + home => '/home/vagrant' + } -> file {'/home/vagrant': + ensure => directory, + owner => vagrant, + group => vagrant + } + + + user {'root': + ensure => present, + home => '/root' + } -> file {'/root': + ensure => directory, + owner => root, + group => root + } + + ssh::user {'vagrant': + } + + ssh::user { 'root': + home => '/root' + } +} diff --git a/modules/raspberry_dev/manifests/init.pp b/modules/raspberry_dev/manifests/init.pp new file mode 100644 index 0000000..6fd97ab --- /dev/null +++ b/modules/raspberry_dev/manifests/init.pp @@ -0,0 +1,26 @@ +# - This is cobbled together from various sources, including: +# - +# - +# - +# - +# - (This is an decent introduction to ScratchBox2) + +class raspberry_dev { + Exec { path => ['/usr/local/bin/', '/bin/', '/sbin/', '/usr/bin/', + '/usr/sbin/', '/opt/vagrant_ruby/bin', + '/opt/raspberry-dev/bin'], + timeout => 600 + } + + include sysconfig + include sysconfig::sudoers + include ssh::server + include apt + + include raspberry_dev::packages + include raspberry_dev::config + include raspberry_dev::toolchain + include raspberry_dev::qemu + include raspberry_dev::scratchbox2 + include raspberry_dev::raspbian_chroot +} \ No newline at end of file diff --git a/modules/raspberry_dev/manifests/packages.pp b/modules/raspberry_dev/manifests/packages.pp new file mode 100644 index 0000000..74319ac --- /dev/null +++ b/modules/raspberry_dev/manifests/packages.pp @@ -0,0 +1,9 @@ +class raspberry_dev::packages { + $required_packages = ['libncurses5', 'fakeroot', 'debootstrap', 'curl', + 'libstdc++6:i386', 'zlib1g:i386', 'libc6-dev-i386', 'build-essential', 'git'] + + package {$required_packages: + ensure => installed, + require => Exec['apt-get update'] + } +} diff --git a/modules/raspberry_dev/manifests/qemu.pp b/modules/raspberry_dev/manifests/qemu.pp new file mode 100644 index 0000000..467758e --- /dev/null +++ b/modules/raspberry_dev/manifests/qemu.pp @@ -0,0 +1,15 @@ +class raspberry_dev::qemu { + $qemu_url = 'http://commondatastorage.googleapis.com/howling-fantods/raspberrypi/raspberry-qemu_1.3.0_amd64.deb' + $qemu_deb_filename = 'raspberry-qemu_1.3.0_amd64.deb' + + exec {'download-qemu': + command => "curl -L ${qemu_url} -o ${qemu_deb_filename}", + cwd => $raspberry_dev::config::debs_dir, + creates => "${raspberry_dev::config::debs_dir}/${qemu_deb_filename}" + + } -> package {'raspberry-qemu': + provider => dpkg, + source => "${raspberry_dev::config::debs_dir}/${qemu_deb_filename}", + ensure => installed + } +} \ No newline at end of file diff --git a/modules/raspberry_dev/manifests/raspbian_chroot.pp b/modules/raspberry_dev/manifests/raspbian_chroot.pp new file mode 100644 index 0000000..5cd3f70 --- /dev/null +++ b/modules/raspberry_dev/manifests/raspbian_chroot.pp @@ -0,0 +1,91 @@ +# Class: raspberry_dev::scratchbox2 +# +# +class raspberry_dev::raspbian_chroot { + $raspbian_mirror = 'http://archive.raspbian.org/raspbian/' + + $container_init_cmd = "sb2-init -n \ + -c ${raspberry_dev::config::qemu_path} \ + ${raspberry_dev::config::sbox2_container_name} \ + ${raspberry_dev::config::arm_gcc_path}" + + $bootstrap_cmd = + "fakeroot debootstrap --verbose --foreign --variant=scratchbox \ + --arch armhf jessie \ + ${raspberry_dev::config::sbox2_container_path} ${raspbian_mirror}" + + # without this, sbox2 sees HOME as "/root" for some reason, and all sb2 + # commands fail. + $sbox2_required_env_flags = ["HOME=/home/vagrant"] + + exec {'scratchbox2-init-container': + command => $container_init_cmd, + environment => $sbox2_required_env_flags, + cwd => $raspberry_dev::config::sbox2_container_path, + unless => "sudo -u vagrant sb2-config -l | grep \"^${raspberry_dev::config::sbox2_container_name}$\"", + user => vagrant, + group => vagrant, + + } -> exec {'raspbian-install-key': + command => 'curl http://archive.raspbian.org/raspbian.public.key | apt-key add -', + unless => 'apt-key list | grep "Raspberry Pi Debian"' + } -> exec {'fix-debootstrap-script': + command => 'ln -s /usr/share/debootstrap/scripts/sid /usr/share/debootstrap/scripts/jessie', + unless => 'ls /usr/share/debootstrap/scripts | grep jessie' + } -> exec {'debootstrap-first-stage': + command => $bootstrap_cmd, + environment => $sbox2_required_env_flags, + creates => "${raspberry_dev::config::sbox2_container_path}/var", + user => vagrant, + group => vagrant, + timeout => 1500, # 25 minutes + + } -> exec {'debootstrap-second-stage': + command => "sb2 -t raspberry -eR ./debootstrap/debootstrap --verbose --second-stage", + environment => $sbox2_required_env_flags, + cwd => $raspberry_dev::config::sbox2_container_path, + user => vagrant, + group => vagrant, + onlyif => "test -f \"${raspberry_dev::config::sbox2_container_path}/debootstrap/debootstrap\"", + # tries => 2 is set because in my experience, debootstrap fails the first + # time round, only to succeed on the second. Hmph. The error is: + # I: Configuring initramfs-tools... + # W: Failure while configuring required packages. + tries => 2, + timeout => 1500, # 25 minutes + + } -> file {"${raspberry_dev::config::sbox2_container_path}/etc/apt/sources.list": + source => "puppet:///modules/raspberry_dev/rootfs/etc/apt/sources.list", + ensure => present, + owner => vagrant, + group => vagrant + + } -> exec {'sandbox-apt-get-update': + command => "sb2 -t ${raspberry_dev::config::sbox2_container_name} -eR apt-get update", + environment => $sbox2_required_env_flags, + cwd => $raspberry_dev::config::sbox2_container_path, + user => vagrant, + group => vagrant, + + } -> exec {'sandbox-install-essentials': + command => "sb2 -t ${raspberry_dev::config::sbox2_container_name} -eR apt-get install puppet --assume-yes", + environment => $sbox2_required_env_flags, + cwd => $raspberry_dev::config::sbox2_container_path, + user => vagrant, + group => vagrant, + + } -> file {"${raspberry_dev::config::sbox2_container_path}/etc/puppet/modules/raspbian": + source => "puppet:///modules/raspberry_dev/rootfs/etc/puppet/modules/raspbian", + recurse => true, + ensure => present, + owner => vagrant, + group => vagrant + + } -> exec {'sandbox-provision': + command => "sb2 -t ${raspberry_dev::config::sbox2_container_name} -eR puppet apply -e \"include raspbian\"", + environment => $sbox2_required_env_flags, + cwd => $raspberry_dev::config::sbox2_container_path, + user => vagrant, + group => vagrant, + } +} diff --git a/modules/raspberry_dev/manifests/scratchbox2.pp b/modules/raspberry_dev/manifests/scratchbox2.pp new file mode 100644 index 0000000..c2e6aff --- /dev/null +++ b/modules/raspberry_dev/manifests/scratchbox2.pp @@ -0,0 +1,16 @@ +class raspberry_dev::scratchbox2 { + $sbox2_url = 'http://commondatastorage.googleapis.com/howling-fantods/raspberrypi/raspberry-scratchbox2_2.3.90_amd64.deb' + $sbox2_deb_filename = 'raspberry-scratchbox2_2.3.90_amd64.deb' + + exec {'download-sbox2': + command => "curl -L ${sbox2_url} -o ${sbox2_deb_filename}", + cwd => $raspberry_dev::config::debs_dir, + creates => "${raspberry_dev::config::debs_dir}/${sbox2_deb_filename}" + + } -> package {'raspberry-scratchbox2': + provider => dpkg, + source => "${raspberry_dev::config::debs_dir}/${sbox2_deb_filename}", + ensure => installed + + } +} \ No newline at end of file diff --git a/modules/raspberry_dev/manifests/toolchain.pp b/modules/raspberry_dev/manifests/toolchain.pp new file mode 100644 index 0000000..d9127ce --- /dev/null +++ b/modules/raspberry_dev/manifests/toolchain.pp @@ -0,0 +1,13 @@ +class raspberry_dev::toolchain { + $toolchain_url = 'https://github.com/raspberrypi/tools' + + exec {'download-toolchain': + command => "git clone ${toolchain_url}", + cwd => $raspberry_dev::config::debs_dir, + creates => "${raspberry_dev::config::debs_dir}/tools" + } -> exec {'install-toolchain': + command => "cp -r arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/* \ + ${raspberry_dev::config::tools_prefix}", + cwd => "${raspberry_dev::config::debs_dir}/tools" + } +} diff --git a/puppetmanifests/raspberry-nox.pp b/puppetmanifests/raspberry-nox.pp index e9fc85f..34279c2 100644 --- a/puppetmanifests/raspberry-nox.pp +++ b/puppetmanifests/raspberry-nox.pp @@ -1,2 +1,2 @@ -include boxes::devbox \ No newline at end of file +include raspberry_dev \ No newline at end of file