buildDebianFs.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/bin/sh -xe
  2. # Build fs, image
  3. KVER=4.17.2
  4. #Ensure Sudo
  5. if [ ! $UID = "0" ]
  6. then
  7. echo "Please run this script with sudo, or as root:"
  8. echo "sudo $0 $*"
  9. exit 1
  10. fi
  11. outmnt=$(mktemp -d -p `pwd`)
  12. outdev=/dev/loop4
  13. install_resources=resources/InstallResources
  14. build_resources=resources/BuildResources
  15. #A hacky way to ensure the loops are properly unmounted and the temp files are properly deleted.
  16. #Without this, a reboot is sometimes required to properly clean the loop devices and ensure a clean build
  17. cleanup() {
  18. set +e
  19. umount -l $outmnt > /dev/null 2>&1
  20. rmdir $outmnt > /dev/null 2>&1
  21. losetup -d $outdev > /dev/null 2>&1
  22. set +e
  23. umount -l $outmnt > /dev/null 2>&1
  24. rmdir $outmnt > /dev/null 2>&1
  25. losetup -d $outdev > /dev/null 2>&1
  26. }
  27. trap cleanup INT TERM EXIT
  28. create_image() {
  29. # it's a sparse file - that's how we fit a 16GB image inside a 2GB one
  30. dd if=/dev/zero of=$1 bs=$3 count=$4 conv=sparse
  31. parted --script $1 mklabel gpt
  32. cgpt create $1
  33. cgpt add -i 1 -t kernel -b 8192 -s 65536 -l Kernel -S 1 -T 5 -P 10 $1
  34. start=$((8192 + 65536))
  35. end=`cgpt show $1 | grep 'Sec GPT table' | awk '{print $1}'`
  36. size=$(($end - $start))
  37. cgpt add -i 2 -t data -b $start -s $size -l Root $1
  38. # $size is in 512 byte blocks while ext4 uses a block size of 1024 bytes
  39. losetup -P $2 $1
  40. mkfs.ext4 -F -b 1024 -m 0 -O ^has_journal ${2}p2 $(($size / 2))
  41. # mount the / partition
  42. mount -o noatime ${2}p2 $5
  43. }
  44. # create a 2GB image with the Chrome OS partition layout
  45. create_image PrawnOS-Alpha-c201-libre-2GB.img $outdev 50M 40 $outmnt
  46. # install Debian on it
  47. export LC_ALL="en_US.UTF-8" #Change this as necessary if not US
  48. export DEBIAN_FRONTEND=noninteractive
  49. qemu-debootstrap --arch armhf stretch --include locales,init $outmnt http://deb.debian.org/debian
  50. chroot $outmnt passwd -d root
  51. #Place the config files and installer script and give them the proper permissions
  52. echo -n PrawnOS-Alpha > $outmnt/etc/hostname
  53. cp -R $install_resources/ $outmnt/InstallResources/
  54. cp scripts/InstallScripts/* $outmnt/InstallResources/
  55. cp scripts/InstallScripts/InstallToInternal.sh $outmnt/
  56. chmod +x $outmnt/*.sh
  57. install -D -m 644 $build_resources/80disable-recommends $outmnt/etc/apt/apt.conf.d/80disable-recommends #This should fix the issue of crda being installed but unconfigured causing regulatory.db firmware loading errors in dmesg
  58. #Setup the chroot for apt
  59. #This is what https://wiki.debian.org/EmDebian/CrossDebootstrap suggests
  60. cp /etc/hosts $outmnt/etc/
  61. cp $build_resources/sources.list $outmount/etc/apt/sources.list
  62. #Setup the locale
  63. cp /etc/locale.gen $outmnt/etc/
  64. #Install the base packages
  65. chroot $outmnt apt update
  66. chroot $outmnt apt install -y initscripts udev kmod net-tools inetutils-ping traceroute iproute2 isc-dhcp-client wpasupplicant iw alsa-utils cgpt vim-tiny less psmisc netcat-openbsd ca-certificates bzip2 xz-utils ifupdown nano apt-utils python python-urwid
  67. #Cleanup to reduce install size
  68. chroot $outmnt apt-get autoremove --purge
  69. chroot $outmnt apt-get clean
  70. #Download the packages to be installed by Install.sh: TODO: potentially dpkg-reconfigure locales?
  71. chroot $outmnt apt-get install -y -d xorg acpi-support lightdm tasksel dpkg librsvg2-common xorg xserver-xorg-input-libinput alsa-utils anacron avahi-daemon eject iw libnss-mdns xdg-utils lxqt wicd-daemon wicd wicd-curses wicd-gtk xserver-xorg-input-synaptics crda
  72. #Cleanup hosts
  73. rm -rf $outmnt/etc/hosts #This is what https://wiki.debian.org/EmDebian/CrossDebootstrap suggests
  74. echo -n "127.0.0.1 PrawnOS-Alpha" > $outmnt/etc/hosts
  75. # put the kernel in the kernel partition, modules in /lib/modules and AR9271
  76. # firmware in /lib/firmware
  77. dd if=build/linux-$KVER/vmlinux.kpart of=${outdev}p1 conv=notrunc
  78. make -C build/linux-$KVER ARCH=arm INSTALL_MOD_PATH=$outmnt modules_install
  79. rm -f $outmnt/lib/modules/3.14.0/{build,source}
  80. install -D -m 644 build/open-ath9k-htc-firmware/target_firmware/htc_9271.fw $outmnt/lib/firmware/ath9k_htc/htc_9271-1.4.0.fw
  81. echo "DONE!"
  82. cleanup