Last active
April 16, 2016 10:22
-
-
Save mdaffin/d0ba20785d8fc5f3de91 to your computer and use it in GitHub Desktop.
A set of scripts to automate formatting/installing and configuring a raspberry pi sd card.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
error() { | |
local parent_lineno="$1" | |
local code="${3:-1}" | |
echo "Error on or near line ${parent_lineno}; exiting with status ${code}" | |
exit "${code}" | |
} | |
trap 'error ${LINENO}' ERR | |
if [ -t 1 ] ; then echo terminal; fi | |
hostname=${1-} | |
[ -z "${hostname}" ] && ( echo "hostname not set"; exit 1 ) | |
username=${2-} | |
[ -z "${username}" ] && ( echo "username not set"; exit 1 ) | |
password=${3-} | |
[ -z "${password}" ] && ( echo "password not set"; exit 1 ) | |
ssid=${4-} | |
[ -z "${ssid}" ] && ( echo "wifi ssid not set"; exit 1 ) | |
wifi_password=${5-} | |
[ -z "${wifi_password}" ] && ( echo "wifi password not set"; exit 1 ) | |
# configure hostname | |
echo ${hostname} > /etc/hostname | |
# install some useful packages | |
pacman -Syu --noconfirm vim bash-completion | |
# rename default user | |
sed -i "s/alarm/${username}/g" /etc/passwd /etc/group /etc/shadow | |
mv /home/alarm "/home/${username}" | |
echo -e "${password}\n${password}" | passwd "${username}" | |
# enable sudo for user | |
pacman -S --noconfirm sudo | |
echo '%wheel ALL=(ALL) ALL' >> /etc/sudoers.d/wheel | |
# lock root account (you can still use `sudo -i` to get a root shell) | |
passwd -l root | |
# setup zsh | |
pacman -Syu --noconfirm zsh grml-zsh-config | |
chsh -s /usr/bin/zsh root | |
chsh -s /usr/bin/zsh "${username}" | |
cp /etc/skel/.zshrc /root/ | |
cp /etc/skel/.zshrc "/home/${username}/" | |
# enable camera | |
sed -i 's/gpu_mem=.*/gpu_mem=128/' /boot/config.txt | |
grep 'start_file=start_x.elf' /boot/config.txt >/dev/null || echo 'start_file=start_x.elf' >> /boot/config.txt | |
grep 'fixup_file=fixup_x.dat' /boot/config.txt >/dev/null || echo 'fixup_file=fixup_x.dat' >> /boot/config.txt | |
# setup networking | |
pacman -S --noconfirm wpa_supplicant wpa_actiond ifplugd crda dialog | |
ln -sf /usr/lib/systemd/system/[email protected] /etc/systemd/system/multi-user.target.wants/[email protected] | |
ln -sf /usr/lib/systemd/system/[email protected] /etc/systemd/system/multi-user.target.wants/[email protected] | |
cat <<EOF >"/etc/netctl/wlan0-${ssid}" | |
Description='Automatically generated profile by install script' | |
Interface=wlan0 | |
Connection=wireless | |
Security=wpa | |
ESSID="${ssid}" | |
IP=dhcp | |
Key="${wifi_password}" | |
EOF | |
# enable zero-conf dns | |
pacman -S --noconfirm avahi nss-mdns | |
sed -i '/^hosts: /s/files dns/files mdns dns/' /etc/nsswitch.conf | |
ln -sf /usr/lib/systemd/system/avahi-daemon.service /etc/systemd/system/multi-user.target.wants/avahi-daemon.service | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Copyright (c) 2015 Michael Daffin | |
# 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: | |
# The above copyright notice and this permission notice shall be included in all | |
# copies or substantial portions of the Software. | |
# 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. | |
set -uo pipefail | |
trap 's=$?; echo "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR | |
IFS=$'\n\t' | |
usage() { | |
echo "Usage: $0 FILE SIZE SCRIPT [SCRIPT_ARGUMENTS]" | |
exit 1 | |
} | |
file="${1-}" | |
size="${2-}" | |
script="${3-}" | |
[ -z "${file}" ] && usage | |
[ -z "${size}" ] && usage | |
[ -z "${script}" ] && usage | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
shift 3 | |
cleanup() { | |
[ -n "${loop_dev}" ] && losetup --detach "${loop_dev}" | |
} | |
trap cleanup EXIT | |
fallocate -l "${size}" "${file}" | |
loop_dev=$(losetup --find --show "${file}") | |
${DIR}/rpi-alarm-install "${loop_dev}" "${script}" $@ <&0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Copyright (c) 2015 Michael Daffin | |
# | |
# 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: | |
# | |
# The above copyright notice and this permission notice shall be included in all | |
# copies or substantial portions of the Software. | |
# | |
# 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. | |
set -uo pipefail | |
trap 's=$?; echo "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR | |
IFS=$'\n\t' | |
usage() { | |
echo "Usage: $0 <DEVICE> [rpi1] <INSTALL_SCRIPT>" | |
exit 1 | |
} | |
device="${1-}" | |
[ -z "${device}" ] && usage | |
shift | |
rpi_url="http://archlinuxarm.org/os/ArchLinuxARM-rpi-2-latest.tar.gz" | |
rpi_tar="ArchLinuxARM-rpi-2-latest.tar.gz" | |
if [[ "${1-}" == "rpi1" ]]; then | |
rpi_url="http://archlinuxarm.org/os/ArchLinuxARM-rpi-latest.tar.gz" | |
rpi_tar="ArchLinuxARM-rpi-latest.tar.gz" | |
shift | |
fi | |
script="${1-}" | |
[ -z "${script}" ] && usage | |
shift | |
[ ! -f "${rpi_tar}" ] && wget "${rpi_url}" | |
mount="$(mktemp -d)" | |
cleanup() { | |
if [[ -d "${mount}" ]]; then | |
${DIR}/rpi-unmount "${mount}" || true | |
rmdir "${mount}" || true | |
fi | |
} | |
trap cleanup EXIT | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
${DIR}/rpi-format-sd "${device}" | |
${DIR}/rpi-mount "${device}" "${mount}" | |
tar -xpf "${rpi_tar}" -C ${mount} 2> >(grep -v "Ignoring unknown extended header keyword") | |
cp "${script}" "${mount}/tmp/${script}" | |
chmod +x "${mount}/tmp/${script}" | |
${DIR}/rpi-chroot "${mount}" "/tmp/${script}" $@ <&0 | |
rm "${mount}/tmp/${script}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Copyright (c) 2015 Michael Daffin | |
# 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: | |
# The above copyright notice and this permission notice shall be included in all | |
# copies or substantial portions of the Software. | |
# 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. | |
set -uo pipefail | |
trap 's=$?; echo "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR | |
IFS=$'\n\t' | |
root_dir="${1-}" | |
shift | |
[[ -n "${root_dir}" ]] || { echo "Usage: $0 NEW_ROOT [COMMAND]"; exit 1; } | |
[[ -d "${root_dir}" ]] || { echo "${root_dir} does not exist"; exit 1; } | |
cleanup() { | |
umount ${root_dir}/dev | |
umount ${root_dir}/proc | |
umount ${root_dir}/sys | |
[ "${real_device}" = true ] || umount ${root_dir} | |
} | |
trap cleanup EXIT | |
if mountpoint ${root_dir} >/dev/null; then | |
real_device=true | |
else | |
real_device=false | |
fi | |
[ "${real_device}" = true ] || mount -o bind ${root_dir} ${root_dir} | |
mount -t proc none ${root_dir}/proc | |
mount -t sysfs none ${root_dir}/sys | |
mount -o bind /dev ${root_dir}/dev | |
rm ${root_dir}/etc/resolv.conf | |
cp /etc/resolv.conf ${root_dir}/etc/resolv.conf | |
cp /usr/bin/qemu-arm-static ${root_dir}/usr/bin/ | |
chroot ${root_dir} $@ <&0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Copyright (c) 2015 Michael Daffin | |
# 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: | |
# The above copyright notice and this permission notice shall be included in all | |
# copies or substantial portions of the Software. | |
# 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. | |
set -uo pipefail | |
trap 's=$?; echo "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR | |
IFS=$'\n\t' | |
device="${1-}" | |
[ -z "${device}" ] && { echo "Usage: $0 DEVICE"; exit 1; } | |
parted --script ${device} mklabel msdos | |
parted --script ${device} mkpart primary fat32 0% 100M | |
parted --script ${device} mkpart primary ext4 100M 100% | |
bootdev=$(ls "${device}"*1) | |
rootdev=$(ls "${device}"*2) | |
mkfs.vfat -F32 "${bootdev}" >/dev/null | |
mkfs.ext4 -F "${rootdev}" >/dev/null | |
echo "bootdev=${bootdev}" | |
echo "rootdev=${rootdev}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Copyright (c) 2015 Michael Daffin | |
# 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: | |
# The above copyright notice and this permission notice shall be included in all | |
# copies or substantial portions of the Software. | |
# 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. | |
set -uo pipefail | |
trap 's=$?; echo "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR | |
IFS=$'\n\t' | |
usage() { | |
echo "Usage: $0 DEVICE MOUNT_POINT" | |
exit 1 | |
} | |
device="${1-}" | |
mount="${2-}" | |
[ -z "${device}" ] && usage | |
[ -z "${mount}" ] && usage | |
[ ! -d "${mount}" ] && mkdir "${mount}" | |
bootdev=$(ls "${device}"*1) | |
rootdev=$(ls "${device}"*2) | |
echo "${rootdev}" | |
echo "${bootdev}" | |
mount "${rootdev}" "${mount}" | |
[ ! -d "${mount}/boot" ] && mkdir "${mount}/boot" | |
mount "${bootdev}" "${mount}/boot" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Copyright (c) 2015 Michael Daffin | |
# 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: | |
# The above copyright notice and this permission notice shall be included in all | |
# copies or substantial portions of the Software. | |
# 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. | |
set -uo pipefail | |
trap 's=$?; echo "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR | |
IFS=$'\n\t' | |
mount="${1-}" | |
[ -z "${mount}" ] && { echo "Usage: $0 MOUNT_POINT"; exit 1; } | |
umount "${mount}/boot" | |
umount "${mount}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
Vagrant.configure(2) do |config| | |
config.vm.box = "ubuntu/trusty64" | |
config.vm.provision "shell", inline: <<-SHELL | |
apt-get update -y | |
apt-get install -y qemu qemu-user-static binfmt-support | |
SHELL | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment