Free/libre software for Kobo ebook readers
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

145 lines
4.2 KiB

  1. #!/bin/bash
  2. # Copyright (c) 2015, Cosmin Gorgovan <cosmin at linux-geek dot org>
  3. # All rights reserved.
  4. #
  5. # Redistribution and use in source and binary forms, with or without
  6. # modification, are permitted provided that the following conditions are met:
  7. #
  8. # 1. Redistributions of source code must retain the above copyright notice, this
  9. # list of conditions and the following disclaimer.
  10. # 2. Redistributions in binary form must reproduce the above copyright notice,
  11. # this list of conditions and the following disclaimer in the documentation
  12. # and/or other materials provided with the distribution.
  13. #
  14. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  18. # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. print_usage() {
  25. echo "Usage: build_rootfs.sh [OPTIONS]"
  26. echo "Valid options: "
  27. echo " --skip-deps-check don't check if dependencies are installed"
  28. echo " --help prints this message"
  29. }
  30. check_dependencies() {
  31. dpkg -s debian-archive-keyring debootstrap > /dev/null
  32. if [ $? -ne 0 ] ; then
  33. echo
  34. echo "Error: Some dependencies appear to be missing. Aborting."
  35. exit 1
  36. fi
  37. }
  38. parse_args() {
  39. for arg in "$@"; do
  40. case $arg in
  41. --skip-deps-check)
  42. dep_check=false
  43. ;;
  44. --help)
  45. print_usage
  46. exit 0
  47. ;;
  48. *)
  49. echo "Unrecognized option $arg"
  50. echo
  51. print_usage
  52. exit 1
  53. ;;
  54. esac
  55. done
  56. }
  57. config_rootfs() {
  58. echo
  59. echo "Configuring the newly built rootfs..."
  60. echo "okreader" > ./rootfs/etc/hostname
  61. echo -e "127.0.0.1 localhost okreader\n" > ./rootfs/etc/hosts
  62. echo -e "nameserver 8.8.8.8\nnameserver 8.8.4.4\n" > ./rootfs/etc/resolv.conf
  63. # replace the framebuffer terminals with an uart terminal
  64. mv ./rootfs/etc/inittab ./rootfs/etc/inittab.default
  65. sed -r 's/^[0-9]+:[0-9]+:respawn/# &/' ./rootfs/etc/inittab.default > rootfs/etc/inittab
  66. echo -e "\nT0:23:respawn:/sbin/getty -L ttymxc0 115200 vt100\n" >> ./rootfs/etc/inittab
  67. mkdir ./rootfs/mnt/onboard
  68. mkdir ./rootfs/mnt/external
  69. cp files/fstab rootfs/etc/
  70. cp files/rc.local rootfs/etc/
  71. chown root:root rootfs/etc/fstab rootfs/etc/rc.local
  72. chmod 644 rootfs/etc/fstab
  73. chmod 755 rootfs/etc/rc.local
  74. echo "Configuration done."
  75. }
  76. install_packages() {
  77. cp src/linux-okreader-modules_2.6.35.3-1_armhf.deb rootfs/
  78. cp src/firmware-okreader_1.0-2_armhf.deb rootfs/
  79. cp src/koreader_2018.06-1_armhf.deb rootfs/
  80. cp src/kobo_hwconfig/kobo-hwconfig_1.0-1_armhf.deb rootfs/
  81. chroot rootfs/ bash -c "dpkg -i /*.deb"
  82. rm rootfs/*.deb
  83. }
  84. clean_up_rootfs() {
  85. echo "Cleaning up..."
  86. # SSH keys must be unique for each device. Run dpkg-reconfigure openssh-server on the device.
  87. rm ./rootfs/etc/ssh/ssh_host*key*
  88. # Remove cached packages and documentation to reduce the size of the FS
  89. rm ./rootfs/var/cache/apt/archives/*.deb
  90. rm -R ./rootfs/usr/share/man/*
  91. rm -R ./rootfs/usr/share/info/*
  92. rm -R ./rootfs/usr/share/doc/*
  93. rm -R ./rootfs/var/log/*
  94. echo "Cleanup done."
  95. }
  96. build_rootfs() {
  97. debootstrap --arch=armhf --variant=minbase \
  98. --include=net-tools,wireless-tools,wpasupplicant,kmod,udev,openssh-server,iputils-ping,ifupdown,vim-tiny,dhcpcd,ntpdate \
  99. wheezy ./rootfs http://http.debian.net/debian/
  100. if [ $? -ne 0 ] ; then
  101. echo
  102. echo "Error: Debootstrap seems to have failed. Aborting."
  103. exit 1
  104. fi
  105. config_rootfs
  106. install_packages
  107. clean_up_rootfs
  108. }
  109. dep_check=true
  110. parse_args $@
  111. if [[ $EUID -ne 0 ]]; then
  112. echo "Error: This script must be run as root. Aborting."
  113. exit 1
  114. fi
  115. if $dep_check ; then
  116. check_dependencies
  117. fi
  118. build_rootfs