#!/bin/bash # # System installer, Raspberry Pi version. # Based on https://wiki.debian.org/MatthiasSchmitz#Building_own_Debian_image_for_Raspberry_Pi # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public # License along with this program. If not, see # . # Load. source $APP_BASE/lib/hydra/functions || exit 1 hydra_config_load # Make sure there is provision config. function hydra_provision_config { hydra_user_config device /dev/mmcblk0 "Destination device" hydra_user_config hostname machine "Hostname" hydra_user_config domain example.org "Domain" hydra_user_config arch armhf "System arch" hydra_user_config version stretch "Distro version" hydra_user_config mirror https://deb.debian.org/debian/ "Debian mirror" # Check arch if [ "$arch" != "armel" ] && [ "$arch" != "armhf" ]; then echo "You probably want to run provision instead of provision-raspi" exit 1 fi } # Load configuration hydra_provision_config_load $1 # Parameters WORK="/media/mmc" CHROOT="hydra_sudo_run chroot $WORK" CMDLINE="dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait" RPI_URL="https://raw.githubusercontent.com/Hexxeh/rpi-update/master/rpi-update" # Get config parameters. hydra_provision_config # Check for requirements. for req in debootstrap parted qemu-user-static; do hydra_install_package $req done # Partitioning hydra_sudo_run parted -s -- $device mklabel msdos hydra_sudo_run parted -s -- $device unit MB mkpart primary fat32 1 100 hydra_sudo_run parted -s -- $device unit MB mkpart primary ext2 101 -1 hydra_sudo_run parted -s -- $device set 1 boot on hydra_sudo_run mkdir -p $WORK # Create filesystems hydra_sudo_run mkdosfs -F32 "$device"p1 hydra_sudo_run mkfs.ext4 "$device"p2 hydra_sudo_run mount "$device"p2 $WORK # Bootstrap the system hydra_sudo_run debootstrap --force-check-gpg --foreign --arch=$arch $version $WORK $mirror hydra_sudo_run cp /usr/bin/qemu-arm-static $WORK/usr/bin/ $CHROOT /debootstrap/debootstrap --second-stage # Apt configuration echo "deb $mirror $version main contrib non-free" | hydra_sudo_run tee $WORK/etc/apt/sources.list > /dev/null echo "deb http://security.debian.org/debian-security $version-security main contrib non-free" | hydra_sudo_run tee -a $WORK/etc/apt/sources.list > /dev/null # Basic packages $CHROOT apt-get update $CHROOT apt-get install -y locales && $CHROOT dpkg-reconfigure locales $CHROOT apt-get install -y screen cron lsb-release openssl openssh-server less ntp curl # Hostname echo $hostname.$domain | hydra_sudo_run tee $WORK/etc/hostname > /dev/null # Temporary root password $CHROOT passwd # USB wifi stick support $CHROOT apt-get install -y wpasupplicant firmware-ralink hydra_sudo_run chmod 0600 $WORK/etc/network/interfaces # Modules echo "vchiq" | hydra_sudo_run tee -a $WORK/etc/modules > /dev/null echo "snd_bcm2835" | hydra_sudo_run tee -a $WORK/etc/modules > /dev/null # Fstab echo "Doing a basic network config..." cat <<-EOF | hydra_sudo_run tee $WORK/etc/fstab > /dev/null proc /proc proc defaults 0 0 /dev/mmcblk0p1 /boot vfat defaults 0 2 /dev/mmcblk0p2 / ext4 defaults,noatime 0 1 EOF # Inittab echo "T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100" | hydra_sudo_run tee -a $WORK/etc/inittab > /dev/null # Networking hydra_provision_networking # Boot setup hydra_sudo_run mount "$device"p1 /$WORK/boot/ echo $CMDLINE | hydra_sudo_run tee $WORK/boot/cmdline.txt > /dev/null $CHROOT apt-get install -y git-core binutils ca-certificates $CHROOT wget $RPI_URL -O /usr/bin/rpi-update $CHROOT chmod +x /usr/bin/rpi-update $CHROOT touch /boot/start.elf $CHROOT mkdir -p /lib/modules $CHROOT rpi-update # Fingerprints hydra_provision_fingerprints # Teardown hydra_sudo_run umount $WORK/boot hydra_sudo_run umount $WORK