#!/bin/sh
# edit_squashfs.sh - edit the contents of an Ubuntu Mobile image
# Copyright (C) 2008 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2,
# as published by the Free Software Foundation.
#
# 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 .
#
#
# script to spawn a chroot inside ubuntu mobile squashfs files for
# modifications and package installations. Make sure to have enough free
# space in the vfat image, if you need more than available, use the
# grow_image.sh script from this script collection
#
# Requires: squashfs-tools
#
# Authors: Oliver Grawert
# Emmet Hickory
REQS="squashfs-tools uboot-mkimage"
for req in $REQS; do
if [ -z "$(dpkg -l $req 2>/dev/null|grep ^ii)" ];then
echo "Dependency error, need the following packages installed : $REQS"
exit 0
fi
done
if [ -z $1 ];then
echo 'i need a path to an imagefile as first argument'
exit 0
fi
if [ -z $2 ];then
echo 'i need a path to kernel .deb as the second argument'
exit 0
fi
mkdir /tmp/image
mkdir /tmp/squashfs
mkdir /tmp/tmpfs
mkdir /tmp/mergemount
sudo modprobe aufs
sudo mount -o loop,offset=512 $1 /tmp/image
sudo mount -o loop -t squashfs /tmp/image/casper/filesystem.squashfs /tmp/squashfs
sudo mount -t tmpfs tmpfs /tmp/tmpfs
sudo mount -t aufs -o dirs=/tmp/tmpfs:/tmp/squashfs=ro none /tmp/mergemount
sudo chroot /tmp/mergemount mount -t proc proc /proc
sudo chroot /tmp/mergemount mount -t sysfs sysfs /sys
sudo chroot /tmp/mergemount mkdir -p /dev/pts
sudo chroot /tmp/mergemount mount -t devpts devpts -o noexec,nosuid,gid=5,mode=620 /dev/pts
sudo cp /etc/resolv.conf /tmp/mergemount/etc/
sudo cp $2 /tmp/mergemount/tmp
LANG=C sudo chroot /tmp/mergemount dpkg -i /tmp/*.deb
sudo rm -f /tmp/mergemount/tmp/*.deb
LANG=C sudo chroot /tmp/mergemount su - apt-get clean
sudo chroot /tmp/mergemount rm /etc/resolv.conf
sudo chroot /tmp/mergemount umount /proc
sudo chroot /tmp/mergemount umount /sys
sudo chroot /tmp/mergemount umount /dev/pts
sudo chroot /tmp/mergemount rm -rf /dev/pts
mkdir /tmp/kernel
sudo cp /tmp/mergemount/boot/vmlinuz /tmp/kernel
sudo cp /tmp/mergemount/boot/initrd.img /tmp/kernel
echo -n 'do you want to build a squashfs with the changes ? (y/n) '
read yesno
if [ -z $yesno ];then
yesno='n'
fi
if [ $yesno = 'y' ];then
sudo mksquashfs /tmp/mergemount /tmp/filesystem.squashfs
fi
sudo umount /tmp/mergemount
sudo umount /tmp/tmpfs
sudo umount /tmp/squashfs
if [ $yesno = 'y' ];then
sudo cp /tmp/filesystem.squashfs /tmp/image/casper/
mkimage -A arm -O linux -C none -T kernel -a 0x80008000 -e 0x80008000 -d /tmp/kernel/vmlinuz /tmp/kernel/uImage
mkimage -A arm -O linux -C gzip -T ramdisk -a 0x0 -e 0x0 -d /tmp/kernel/initrd.img /tmp/kernel/uInitrd
sudo cp /tmp/kernel/uImage /tmp/kernel/uInitrd /tmp/image/casper
fi
sudo umount /tmp/image
sudo rm -rf /tmp/image /tmp/tmpfs /tmp/squashfs /tmp/mergemount /tmp/filesystem.squashfs /tmp/kernel