2015-02-01 04:30:16 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Copyright (c) 2015, Cosmin Gorgovan <cosmin at linux-geek dot org>
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions are met:
|
|
|
|
#
|
|
|
|
# 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
# list of conditions and the following disclaimer.
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
# this list of conditions and the following disclaimer in the documentation
|
|
|
|
# and/or other materials provided with the distribution.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
print_usage() {
|
|
|
|
echo "Usage: build_rootfs.sh [OPTIONS]"
|
|
|
|
echo "Valid options: "
|
|
|
|
echo " --skip-deps-check don't check if dependencies are installed"
|
|
|
|
echo " --help prints this message"
|
|
|
|
}
|
|
|
|
|
|
|
|
check_dependencies() {
|
|
|
|
dpkg -s debian-archive-keyring debootstrap > /dev/null
|
|
|
|
if [ $? -ne 0 ] ; then
|
|
|
|
echo
|
|
|
|
echo "Error: Some dependencies appear to be missing. Aborting."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
parse_args() {
|
|
|
|
for arg in "$@"; do
|
|
|
|
case $arg in
|
|
|
|
--skip-deps-check)
|
|
|
|
dep_check=false
|
|
|
|
;;
|
|
|
|
--help)
|
|
|
|
print_usage
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unrecognized option $arg"
|
|
|
|
echo
|
|
|
|
print_usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
config_rootfs() {
|
|
|
|
echo
|
2016-01-05 14:54:00 +00:00
|
|
|
echo "Configuring the newly built rootfs..."
|
2015-02-01 04:30:16 +00:00
|
|
|
|
|
|
|
echo "okreader" > ./rootfs/etc/hostname
|
|
|
|
echo -e "127.0.0.1 localhost okreader\n" > ./rootfs/etc/hosts
|
|
|
|
echo -e "nameserver 8.8.8.8\nnameserver 8.8.4.4\n" > ./rootfs/etc/resolv.conf
|
2015-02-10 22:41:27 +00:00
|
|
|
|
|
|
|
# replace the framebuffer terminals with an uart terminal
|
|
|
|
mv ./rootfs/etc/inittab ./rootfs/etc/inittab.default
|
|
|
|
sed -r 's/^[0-9]+:[0-9]+:respawn/# &/' ./rootfs/etc/inittab.default > rootfs/etc/inittab
|
2015-02-01 04:30:16 +00:00
|
|
|
echo -e "\nT0:23:respawn:/sbin/getty -L ttymxc0 115200 vt100\n" >> ./rootfs/etc/inittab
|
2016-01-05 14:54:00 +00:00
|
|
|
|
2015-02-01 04:30:16 +00:00
|
|
|
mkdir ./rootfs/mnt/onboard
|
2016-01-05 10:20:29 +00:00
|
|
|
mkdir ./rootfs/mnt/external
|
|
|
|
cp files/fstab rootfs/etc/
|
|
|
|
chown root:root rootfs/etc/fstab
|
|
|
|
chmod 644 rootfs/etc/fstab
|
2015-02-01 04:30:16 +00:00
|
|
|
|
|
|
|
echo "Configuration done."
|
|
|
|
}
|
|
|
|
|
2016-01-05 11:20:45 +00:00
|
|
|
install_packages() {
|
|
|
|
cp src/linux-okreader-modules_2.6.35.3-1_armhf.deb rootfs/
|
|
|
|
cp src/firmware-okreader_1.0-1_armhf.deb rootfs/
|
2016-01-05 14:58:58 +00:00
|
|
|
cp src/koreader_2016.01-4_armhf.deb rootfs/
|
2016-01-06 11:33:43 +00:00
|
|
|
cp src/kobo_hwconfig/kobo-hwconfig_1.0-1_armhf.deb rootfs/
|
2016-01-05 11:20:45 +00:00
|
|
|
|
|
|
|
chroot rootfs/ bash -c "dpkg -i /*.deb"
|
|
|
|
|
|
|
|
rm rootfs/*.deb
|
|
|
|
}
|
|
|
|
|
2015-02-01 04:30:16 +00:00
|
|
|
clean_up_rootfs() {
|
|
|
|
echo "Cleaning up..."
|
|
|
|
|
|
|
|
# SSH keys must be unique for each device. Run dpkg-reconfigure openssh-server on the device.
|
|
|
|
rm ./rootfs/etc/ssh/ssh_host*key*
|
|
|
|
|
|
|
|
# Remove cached packages and documentation to reduce the size of the FS
|
|
|
|
rm ./rootfs/var/cache/apt/archives/*.deb
|
|
|
|
rm -R ./rootfs/usr/share/man/*
|
|
|
|
rm -R ./rootfs/usr/share/info/*
|
|
|
|
rm -R ./rootfs/usr/share/doc/*
|
|
|
|
rm -R ./rootfs/var/log/*
|
|
|
|
|
|
|
|
echo "Cleanup done."
|
|
|
|
}
|
|
|
|
|
|
|
|
build_rootfs() {
|
|
|
|
debootstrap --arch=armhf --variant=minbase \
|
2015-02-02 19:26:24 +00:00
|
|
|
--include=net-tools,wireless-tools,wpasupplicant,kmod,udev,openssh-server,iputils-ping,ifupdown,vim-tiny,dhcpcd \
|
2015-02-01 04:30:16 +00:00
|
|
|
wheezy ./rootfs http://http.debian.net/debian/
|
|
|
|
|
|
|
|
if [ $? -ne 0 ] ; then
|
|
|
|
echo
|
|
|
|
echo "Error: Debootstrap seems to have failed. Aborting."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
config_rootfs
|
2016-01-05 11:20:45 +00:00
|
|
|
install_packages
|
2015-02-01 04:30:16 +00:00
|
|
|
clean_up_rootfs
|
|
|
|
}
|
|
|
|
|
|
|
|
dep_check=true
|
|
|
|
|
|
|
|
parse_args $@
|
|
|
|
|
|
|
|
if [[ $EUID -ne 0 ]]; then
|
|
|
|
echo "Error: This script must be run as root. Aborting."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if $dep_check ; then
|
|
|
|
check_dependencies
|
|
|
|
fi
|
|
|
|
|
|
|
|
build_rootfs
|
|
|
|
|