buildFilesystem.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. #Ensure Sudo
  15. if [ ! $UID = "0" ]
  16. then
  17. echo "Please run this script with sudo, or as root:"
  18. echo "sudo $0 $*"
  19. exit 1
  20. fi
  21. if [ -z "$1" ]
  22. then
  23. echo "No kernel version supplied"
  24. exit 1
  25. fi
  26. KVER=$1
  27. [ ! -d build ] && echo "No build folder found, is the kernel built?" && exit
  28. outmnt=$(mktemp -d -p `pwd`)
  29. outdev=/dev/loop5
  30. install_resources=resources/InstallResources
  31. build_resources=resources/BuildResources
  32. #A hacky way to ensure the loops are properly unmounted and the temp files are properly deleted.
  33. #Without this, a reboot is sometimes required to properly clean the loop devices and ensure a clean build
  34. cleanup() {
  35. set +e
  36. umount -l $outmnt > /dev/null 2>&1
  37. rmdir $outmnt > /dev/null 2>&1
  38. losetup -d $outdev > /dev/null 2>&1
  39. set +e
  40. umount -l $outmnt > /dev/null 2>&1
  41. rmdir $outmnt > /dev/null 2>&1
  42. losetup -d $outdev > /dev/null 2>&1
  43. }
  44. trap cleanup INT TERM EXIT
  45. create_image() {
  46. # it's a sparse file - that's how we fit a 16GB image inside a 3GB one
  47. dd if=/dev/zero of=$1 bs=$3 count=$4 conv=sparse
  48. parted --script $1 mklabel gpt
  49. cgpt create $1
  50. cgpt add -i 1 -t kernel -b 8192 -s 65536 -l Kernel -S 1 -T 5 -P 10 $1
  51. start=$((8192 + 65536))
  52. end=`cgpt show $1 | grep 'Sec GPT table' | awk '{print $1}'`
  53. size=$(($end - $start))
  54. cgpt add -i 2 -t data -b $start -s $size -l Root $1
  55. # $size is in 512 byte blocks while ext4 uses a block size of 1024 bytes
  56. losetup -P $2 $1
  57. mkfs.ext4 -F -b 1024 -m 0 -O ^has_journal ${2}p2 $(($size / 2))
  58. # mount the / partition
  59. mount -o noatime ${2}p2 $5
  60. }
  61. # create a 3GB image with the Chrome OS partition layout
  62. create_image PrawnOS-Alpha-c201-libre-2GB.img-BASE $outdev 50M 40 $outmnt
  63. # use default debootstrap mirror if none is specified
  64. if [ "$PRAWNOS_DEBOOTSTRAP_MIRROR" = "" ]
  65. then
  66. PRAWNOS_DEBOOTSTRAP_MIRROR=http://ftp.us.debian.org/debian
  67. fi
  68. # install Debian on it
  69. export DEBIAN_FRONTEND=noninteractive
  70. qemu-debootstrap --arch armhf stretch --include locales,init --keyring=$build_resources/debian-archive-keyring.gpg $outmnt $PRAWNOS_DEBOOTSTRAP_MIRROR
  71. chroot $outmnt passwd -d root
  72. #Place the config files and installer script and give them the proper permissions
  73. echo -n PrawnOS-Alpha > $outmnt/etc/hostname
  74. cp -R $install_resources/ $outmnt/InstallResources/
  75. cp scripts/InstallScripts/* $outmnt/InstallResources/
  76. cp scripts/InstallScripts/InstallToInternal.sh $outmnt/
  77. chmod +x $outmnt/*.sh
  78. #Copy in the test script
  79. cp scripts/InstallScripts/wifi-test.sh $outmnt/wifi-test.sh
  80. chmod +x $outmnt/wifi-test.sh
  81. #Setup the chroot for apt
  82. #This is what https://wiki.debian.org/EmDebian/CrossDebootstrap suggests
  83. cp /etc/hosts $outmnt/etc/
  84. cp $build_resources/sources.list $outmnt/etc/apt/sources.list
  85. #setup apt pinning
  86. cp $build_resources/apt-preferences $outmnt/etc/apt/preferences
  87. #Setup the locale
  88. cp $build_resources/locale.gen $outmnt/etc/locale.gen
  89. chroot $outmnt locale-gen
  90. #Install the base packages
  91. chroot $outmnt apt update
  92. 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
  93. #Cleanup to reduce install size
  94. chroot $outmnt apt-get autoremove --purge
  95. chroot $outmnt apt-get clean
  96. #Download support for libinput-gestures
  97. chroot $outmnt apt install -y libinput-tools xdotool build-essential
  98. #Package is copied into /InstallResources/packages
  99. #Download the packages to be installed by Install.sh:
  100. 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
  101. # #grab chromium from sid, since stretch and buster are broken
  102. # chroot $outmnt apt-get -t unstable install -d -y chromium
  103. # #grab firefox from buster, since stretch is broken
  104. chroot $outmnt apt-get -t testing install -d -y firefox-esr
  105. #Cleanup hosts
  106. rm -rf $outmnt/etc/hosts #This is what https://wiki.debian.org/EmDebian/CrossDebootstrap suggests
  107. echo -n "127.0.0.1 PrawnOS-Alpha" > $outmnt/etc/hosts
  108. umount -l $outmnt > /dev/null 2>&1
  109. rmdir $outmnt > /dev/null 2>&1
  110. losetup -d $outdev > /dev/null 2>&1
  111. echo "DONE!"
  112. trap - INT TERM EXIT