buildDebianFs.sh 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #!/bin/sh -xe
  2. # Build fs, image
  3. # This file is part of PrawnOS (http://www.prawnos.com)
  4. # Copyright (c) 2018 Hal Emmerich <hal@halemmerich.com>
  5. # PrawnOS is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License version 2
  7. # as published by the Free Software Foundation.
  8. # PrawnOS is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with PrawnOS. If not, see <https://www.gnu.org/licenses/>.
  14. KVER=4.17.19
  15. #Ensure Sudo
  16. if [ ! $UID = "0" ]
  17. then
  18. echo "Please run this script with sudo, or as root:"
  19. echo "sudo $0 $*"
  20. exit 1
  21. fi
  22. [ ! -d build ] && echo "No build folder found, is the kernel built?" && exit
  23. outmnt=$(mktemp -d -p `pwd`)
  24. outdev=/dev/loop4
  25. install_resources=resources/InstallResources
  26. build_resources=resources/BuildResources
  27. #A hacky way to ensure the loops are properly unmounted and the temp files are properly deleted.
  28. #Without this, a reboot is sometimes required to properly clean the loop devices and ensure a clean build
  29. cleanup() {
  30. set +e
  31. umount -l $outmnt > /dev/null 2>&1
  32. rmdir $outmnt > /dev/null 2>&1
  33. losetup -d $outdev > /dev/null 2>&1
  34. set +e
  35. umount -l $outmnt > /dev/null 2>&1
  36. rmdir $outmnt > /dev/null 2>&1
  37. losetup -d $outdev > /dev/null 2>&1
  38. }
  39. trap cleanup INT TERM EXIT
  40. create_image() {
  41. # it's a sparse file - that's how we fit a 16GB image inside a 3GB one
  42. dd if=/dev/zero of=$1 bs=$3 count=$4 conv=sparse
  43. parted --script $1 mklabel gpt
  44. cgpt create $1
  45. cgpt add -i 1 -t kernel -b 8192 -s 65536 -l Kernel -S 1 -T 5 -P 10 $1
  46. start=$((8192 + 65536))
  47. end=`cgpt show $1 | grep 'Sec GPT table' | awk '{print $1}'`
  48. size=$(($end - $start))
  49. cgpt add -i 2 -t data -b $start -s $size -l Root $1
  50. # $size is in 512 byte blocks while ext4 uses a block size of 1024 bytes
  51. losetup -P $2 $1
  52. mkfs.ext4 -F -b 1024 -m 0 -O ^has_journal ${2}p2 $(($size / 2))
  53. # mount the / partition
  54. mount -o noatime ${2}p2 $5
  55. }
  56. # create a 3GB image with the Chrome OS partition layout
  57. create_image PrawnOS-Alpha-c201-libre-2GB.img $outdev 50M 40 $outmnt
  58. # install Debian on it
  59. export DEBIAN_FRONTEND=noninteractive
  60. qemu-debootstrap --arch armhf stretch --include locales,init --keyring=$build_resources/debian-archive-keyring.gpg $outmnt http://ftp.us.debian.org/debian
  61. chroot $outmnt passwd -d root
  62. #Place the config files and installer script and give them the proper permissions
  63. echo -n PrawnOS-Alpha > $outmnt/etc/hostname
  64. cp -R $install_resources/ $outmnt/InstallResources/
  65. cp scripts/InstallScripts/* $outmnt/InstallResources/
  66. cp scripts/InstallScripts/InstallToInternal.sh $outmnt/
  67. chmod +x $outmnt/*.sh
  68. #Setup the chroot for apt
  69. #This is what https://wiki.debian.org/EmDebian/CrossDebootstrap suggests
  70. cp /etc/hosts $outmnt/etc/
  71. cp $build_resources/sources.list $outmnt/etc/apt/sources.list
  72. #setup apt pinning
  73. cp $build_resources/apt-preferences $outmnt/etc/apt/preferences
  74. #Setup the locale
  75. cp $build_resources/locale.gen $outmnt/etc/locale.gen
  76. chroot $outmnt locale-gen
  77. #Install the base packages
  78. chroot $outmnt apt update
  79. 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 git kpartx gdisk parted rsync
  80. #Cleanup to reduce install size
  81. chroot $outmnt apt-get autoremove --purge
  82. chroot $outmnt apt-get clean
  83. #Download support for libinput-gestures
  84. chroot $outmnt apt install -y libinput-tools xdotool build-essential
  85. #Package is copied into /InstallResources/packages
  86. #Download the packages to be installed by Install.sh:
  87. 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 crda xfce4 dbus-user-session system-config-printer tango-icon-theme xfce4-power-manager xfce4-terminal xfce4-goodies mousepad vlc libutempter0 xterm numix-gtk-theme dconf-cli dconf-editor plank network-manager-gnome network-manager-openvpn network-manager-openvpn-gnome dtrx emacs25 accountsservice sudo pavucontrol-qt
  88. # #grab chromium from sid, since stretch and buster are broken
  89. # chroot $outmnt apt-get -t unstable install -d -y chromium
  90. # #grab firefox from buster, since stretch is broken
  91. chroot $outmnt apt-get -t testing install -d -y firefox-esr
  92. #Cleanup hosts
  93. rm -rf $outmnt/etc/hosts #This is what https://wiki.debian.org/EmDebian/CrossDebootstrap suggests
  94. echo -n "127.0.0.1 PrawnOS-Alpha" > $outmnt/etc/hosts
  95. # put the kernel in the kernel partition, modules in /lib/modules and AR9271
  96. # firmware in /lib/firmware
  97. dd if=build/linux-$KVER/vmlinux.kpart of=${outdev}p1 conv=notrunc
  98. make -C build/linux-$KVER ARCH=arm INSTALL_MOD_PATH=$outmnt modules_install
  99. rm -f $outmnt/lib/modules/3.14.0/{build,source}
  100. 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
  101. install -D -m 644 build/open-ath9k-htc-firmware/target_firmware/htc_7010.fw $outmnt/lib/firmware/ath9k_htc/htc_7010-1.4.0.fw
  102. umount -l $outmnt > /dev/null 2>&1
  103. rmdir $outmnt > /dev/null 2>&1
  104. losetup -d $outdev > /dev/null 2>&1
  105. echo "DONE!"
  106. trap - INT TERM EXIT