aboutsummaryrefslogtreecommitdiff
path: root/share/hydractl/provision-raspi
blob: 78e6bd3d0fdb0807817bff4388e53f7be646ba86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/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
# <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   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"

  # 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 --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/ $version/updates 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