aboutsummaryrefslogtreecommitdiffstats
path: root/freedom-maker/mk_dreamplug_rootfs
diff options
context:
space:
mode:
Diffstat (limited to 'freedom-maker/mk_dreamplug_rootfs')
-rwxr-xr-xfreedom-maker/mk_dreamplug_rootfs179
1 files changed, 179 insertions, 0 deletions
diff --git a/freedom-maker/mk_dreamplug_rootfs b/freedom-maker/mk_dreamplug_rootfs
new file mode 100755
index 0000000..a70f032
--- /dev/null
+++ b/freedom-maker/mk_dreamplug_rootfs
@@ -0,0 +1,179 @@
+#!/bin/bash
+#
+# Copyright 2011 by Bdale Garbee <bdale@gag.com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+# based on work by <ivan@sanchezortega.es>, who released his script under
+# the following license terms:
+# ----------------------------------------------------------------------------
+# "THE BEER-WARE LICENSE" (Revision 42):
+# As long as you retain this notice you can do whatever you want with
+# this stuff. If we meet some day, and you think this stuff is worth it,
+# you can buy me a beer in return.
+# ----------------------------------------------------------------------------
+
+# mk_dreamplug_rootfs
+#
+# Runs multistrap and readies the resulting root filesystem to silently
+# complete package configuration on the first boot-up.
+
+# where to build images, etc
+basedir=`pwd`/build
+target=$basedir/dreamplug
+tmpdir=$basedir/tmp
+pkgcache=$tmpdir/aptcache
+
+mkdir -p $target
+mkdir -p $tmpdir
+mkdir -p $pkgcache
+
+hostname='freedombox'
+rootpassword='freedom'
+
+kernelimage=http://www.newit.co.uk/kernels/Dreamplug/Dreamplug-prerelease/uImage
+kernelmodules=http://www.newit.co.uk/kernels/Dreamplug/Dreamplug-prerelease/Modules.tar.gz
+
+if [ ! -f $tmpdir/uImage ]
+then
+ wget -c $kernelimage --output-document="$tmpdir/uImage"
+fi
+if [ ! -f $tmpdir/linux.tar.gz ]
+then
+ wget -c $kernelmodules --output-document="$tmpdir/linux.tar.gz"
+fi
+
+rm -rf $target/*
+
+mkdir -p $target/var/cache/apt/ && mount -o bind $pkgcache $target/var/cache/apt/
+
+echo "Multistrapping..."
+multistrap -f fbx-armel.conf --no-auth -d $target
+
+umount $target/var/cache/apt/
+mkdir $target/var/cache/apt/archives
+
+echo "Unpacking kernel modules..."
+mkdir -p $target/lib/modules/
+tar -C $target/lib/ -zxvf $tmpdir/linux.tar.gz | tail
+
+echo "copy uImage to target filesystem"
+mkdir -p $target/boot
+cp build/tmp/uImage $target/boot/uImage
+echo "copy copy2dream.sh script to target filesystem"
+cp bin/copy2dream.sh $target/boot/copy2dream.sh
+
+# Until udev is configured and run for the first time, dev nodes won't be created, but we need some basic ones for spawning a console (console) and creating RSA keys for SSH (urandom).
+echo "Creating basic device nodes"
+mknod $target/dev/console c 5 1
+mknod $target/dev/random c 1 8
+mknod $target/dev/urandom c 1 9
+mknod $target/dev/null c 1 3
+mknod $target/dev/ptmx c 5 2
+
+# Basic fstab & mtab..
+echo "Setting up basic fstab & mtab"
+echo "
+rootfs / rootfs relatime,rw 0 0
+proc /proc proc none 0 0
+sys /sys sysfs none 0 0
+none /dev/pts devpts defaults 0 0
+tmpfs /tmp tmpfs rw,nosuid,nodev 0 0
+" > $target/etc/fstab
+
+touch $target/etc/mtab
+
+# Set up hostname
+echo "Setting up hostname, /etc/network/interfaces, nameservers, persistent-net-generator rules"
+echo $hostname > $target/etc/hostname
+
+# Create /etc/network/interfaces
+echo "# This file describes the network interfaces available on your system
+# and how to activate them. For more information, see interfaces(5).
+
+# The loopback network interface
+auto lo
+iface lo inet loopback
+
+# The primary network interface
+allow-hotplug eth0
+iface eth0 inet dhcp
+
+allow-hotplug eth1
+iface eth1 inet dhcp
+ " > $target/etc/network/interfaces
+
+# Setup nameserver (use OpenDNS by default)
+echo "nameserver 208.67.222.222
+nameserver 208.67.220.220" > $target/etc/resolv.conf
+
+# Touch the net generator udev so that eth0 won't be reassigned in case the user
+# changes the MAC address - this may happen if you change the rootfs between plugs.
+touch $target/etc/udev/rules.d/75-persistent-net-generator.rules
+
+# generate configuration script
+
+echo "Create script to configure packages in qemu-user-static"
+
+echo "
+echo \"Preconfiguring dash - else dash and bash will be left in a broken state\"
+/var/lib/dpkg/info/dash.preinst install
+
+echo \"Configuring all packages\"
+export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true
+export LC_ALL=C LANGUAGE=C LANG=C
+dpkg --configure -a
+
+# Establish an initial root password
+echo \"Set root password to \"$rootpassword
+echo root:$rootpassword | /usr/sbin/chpasswd
+
+# By default, spawn a console on the serial port
+echo \"Adding a getty on the serial port\"
+echo \"T0:12345:respawn:/sbin/getty -L ttyS0 115200 vt100\" >> /etc/inittab
+
+echo \"Tweaks to reduce flash writes as per http://www.plugcomputer.org/plugwiki/index.php/Reduce_Flash_Writes\"
+echo \"
+# Reduce writes to flash drives
+vm.laptop_mode=5
+vm.swappiness=0
+vm.dirty_writeback_centisecs=1500
+vm.dirty_expire_centisecs=1500
+\" >> /etc/sysctl.conf
+
+echo \"Deleting this very same script\"
+rm -f /install.sh
+
+echo \"Syncing filesystem just in case something didn't get written\"
+sync
+
+echo \"End configuration progress by exiting from the chroot\"
+exit
+
+" > $target/install.sh
+
+chmod 755 $target/install.sh
+
+echo "Use qemu-user-static to perform first-boot configuration now"
+
+mkdir -p $target/usr/bin
+cp /usr/bin/qemu-arm-static $target/usr/bin
+chroot $target /install.sh
+rm $target/usr/bin/qemu-arm-static
+
+echo "Syncing..."
+sync
+
+echo "Finished. You may now copy the rootfs to the plug."