aboutsummaryrefslogtreecommitdiff
path: root/share/hydractl/provision-raspi
diff options
context:
space:
mode:
Diffstat (limited to 'share/hydractl/provision-raspi')
-rwxr-xr-xshare/hydractl/provision-raspi113
1 files changed, 113 insertions, 0 deletions
diff --git a/share/hydractl/provision-raspi b/share/hydractl/provision-raspi
new file mode 100755
index 0000000..640616f
--- /dev/null
+++ b/share/hydractl/provision-raspi
@@ -0,0 +1,113 @@
+#!/bin/bash
+#
+# System installer, Raspberry Pi version.
+#
+# 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
+# <http://www.gnu.org/licenses/>.
+
+# 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 interactive y "Interactive mode? (y/n)"
+ 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 armel "System arch"
+ hydra_user_config version jessie "Distro version"
+ hydra_user_config mirror http://http.debian.net/debian/ "Debian mirror"
+}
+
+# Load configuration
+hydra_provision_load_config
+
+# 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="http://goo.gl/1BOfJ"
+
+# Get config parameters.
+hydra_provision_config
+
+# Partitioning
+# TODO automated
+hydra_sudo_run cfdisk $device # bootable VFAT (0B) and linux partitions
+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 --foreign --arch=$arch $version $WORK
+hydra_sudo_run cp /usr/bin/qemu-arm-static $WORK/usr/bin/
+$CHROOT /debootstrap/debootstrap --second-stage
+
+# Apt configuration
+echo "deb http://http.debian.net/debian/ $version main contrib non-free" | hydra_sudo_run tee $WORK/etc/apt/sources.list
+echo "deb http://security.debian.org/ $version/updates main contrib non-free" | hydra_sudo_run tee -a $WORK/etc/apt/sources.list
+
+# 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
+
+# Hostname
+echo $hostname.$domain | hydra_sudo_run tee $WORK/etc/hostname
+
+# Temporary root password
+$CHROOT passwd
+
+# USB stick support
+$CHROOT apt-get install -y wpasupplicant firmware-ralink # para conexao usando stick usb
+hydra_sudo_run chmod 0600 $WORK/etc/network/interfaces
+
+# Modules
+echo "vchiq" | hydra_sudo_run tee -a $WORK/etc/modules
+echo "snd_bcm2835" | hydra_sudo_run tee -a $WORK/etc/modules
+
+# 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
+
+# Networking
+hydra_provision_networking
+
+# Boot setup
+hydra_sudo_run mount "$device"p1 /$WORK/boot/
+echo $CMDLINE | hydra_sudo_run tee $WORK/boot/cmdline.txt
+$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