aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2015-09-26 11:11:48 -0300
committerSilvio Rhatto <rhatto@riseup.net>2015-09-26 11:11:48 -0300
commit52ecfc3590fc33bff702ec1478ac61378639c849 (patch)
tree0718a796369176fee284e74c2415531174b55971
parentf5ddf7507d440bf3642777d159a0a60ff55d0c5b (diff)
downloadhydra-52ecfc3590fc33bff702ec1478ac61378639c849.tar.gz
hydra-52ecfc3590fc33bff702ec1478ac61378639c849.tar.bz2
Provision: raspberry pi script
-rw-r--r--lib/hydra/functions2
-rw-r--r--lib/hydra/provision45
-rwxr-xr-xshare/hydractl/provision39
-rwxr-xr-xshare/hydractl/provision-raspi113
4 files changed, 165 insertions, 34 deletions
diff --git a/lib/hydra/functions b/lib/hydra/functions
index e6cf4a0..84590e5 100644
--- a/lib/hydra/functions
+++ b/lib/hydra/functions
@@ -10,6 +10,8 @@ source $APP_BASE/lib/hydra/usage
source $APP_BASE/lib/hydra/action
source $APP_BASE/lib/hydra/backup
source $APP_BASE/lib/hydra/config
+source $APP_BASE/lib/hydra/deploy
+source $APP_BASE/lib/hydra/provision
source $APP_BASE/lib/hydra/tmpfile
# Setup environment
diff --git a/lib/hydra/provision b/lib/hydra/provision
new file mode 100644
index 0000000..5c85e04
--- /dev/null
+++ b/lib/hydra/provision
@@ -0,0 +1,45 @@
+#!/bin/bash
+
+# Load provision configuration
+function hydra_provision_load_config {
+if [ ! -z "$1" ]; then
+ if [ -f "$1" ]; then
+ echo "Using configuration from file $1..."
+ source "$1"
+ elif [ -f "$1.conf" ]; then
+ echo "Using configuration from file $1.conf..."
+ source "$1.conf"
+ elif [ -f "$HYDRA_FOLDER/config/provision/$1" ]; then
+ echo "Using configuration from $HYDRA_FOLDER/config/provision/$1..."
+ source "$HYDRA_FOLDER/config/provision/$1"
+ elif [ -f "$HYDRA_FOLDER/config/provision/$1.conf" ]; then
+ echo "Using configuration from $HYDRA_FOLDER/config/provision/$1.conf..."
+ source "$HYDRA_FOLDER/config/provision/$1.conf"
+ elif [ -f "$APP_BASE/share/config/provision/$1" ]; then
+ echo "Using configuration from $APP_BASE/share/config/provision/$1..."
+ source "$APP_BASE/share/config/provision/$1"
+ elif [ -f "$APP_BASE/share/config/provision/$1.conf" ]; then
+ echo "Using configuration from $APP_BASE/share/config/provision/$1.conf..."
+ source "$APP_BASE/share/config/provision/$1.conf"
+ else
+ echo "Profile not found: $1"
+ exit 1
+ fi
+fi
+}
+
+# Networking.
+function hydra_provision_networking {
+ echo "Doing a basic network config..."
+ cat <<-EOF | $SUDO tee $WORK/etc/network/interfaces > /dev/null
+auto eth0
+allow-hotplug eth0
+iface eth0 inet dhcp
+EOF
+}
+
+function hydra_provision_fingerprints {
+ echo "OpenSSH fingerprints:"
+ hydra_sudo_run chroot $WORK ssh-keygen -l -f /etc/ssh/ssh_host_dsa_key.pub
+ hydra_sudo_run chroot $WORK ssh-keygen -l -f /etc/ssh/ssh_host_rsa_key.pub
+}
diff --git a/share/hydractl/provision b/share/hydractl/provision
index f214e0f..79c88cc 100755
--- a/share/hydractl/provision
+++ b/share/hydractl/provision
@@ -111,31 +111,8 @@ function hydra_provision_config {
hydra_user_config mirror http://http.debian.net/debian/ "Debian mirror"
}
-# Setup.
-if [ ! -z "$1" ]; then
- if [ -f "$1" ]; then
- echo "Using configuration from file $1..."
- source "$1"
- elif [ -f "$1.conf" ]; then
- echo "Using configuration from file $1.conf..."
- source "$1.conf"
- elif [ -f "$HYDRA_FOLDER/config/provision/$1" ]; then
- echo "Using configuration from $HYDRA_FOLDER/config/provision/$1..."
- source "$HYDRA_FOLDER/config/provision/$1"
- elif [ -f "$HYDRA_FOLDER/config/provision/$1.conf" ]; then
- echo "Using configuration from $HYDRA_FOLDER/config/provision/$1.conf..."
- source "$HYDRA_FOLDER/config/provision/$1.conf"
- elif [ -f "$APP_BASE/share/config/provision/$1" ]; then
- echo "Using configuration from $APP_BASE/share/config/provision/$1..."
- source "$APP_BASE/share/config/provision/$1"
- elif [ -f "$APP_BASE/share/config/provision/$1.conf" ]; then
- echo "Using configuration from $APP_BASE/share/config/provision/$1.conf..."
- source "$APP_BASE/share/config/provision/$1.conf"
- else
- echo "Profile not found: $1"
- exit 1
- fi
-fi
+# Load configuration
+hydra_provision_load_config
# Parameters
WORK="/tmp/debootstrap"
@@ -434,12 +411,7 @@ echo "Installing basic utilities..."
hydra_sudo_run chroot $WORK apt-get install screen cron lsb-release openssl -y
# Networking.
-echo "Doing a basic network config..."
-cat <<-EOF | $SUDO tee $WORK/etc/network/interfaces > /dev/null
-auto eth0
-allow-hotplug eth0
-iface eth0 inet dhcp
-EOF
+hydra_provision_networking
# Ssh.
echo "Installing OpenSSH daemon..."
@@ -452,9 +424,8 @@ hydra_sudo_run chroot $WORK apt-get install sudo -y
echo "Choose a root password."
hydra_sudo_run chroot $WORK passwd root
-echo "OpenSSH fingerprints:"
-hydra_sudo_run chroot $WORK ssh-keygen -l -f /etc/ssh/ssh_host_dsa_key.pub
-hydra_sudo_run chroot $WORK ssh-keygen -l -f /etc/ssh/ssh_host_rsa_key.pub
+# Fingerprints
+hydra_provision_fingerprints
cat <<-EOF
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