buildFilesystem.sh 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. outmnt=$(mktemp -d -p `pwd`)
  28. outdev=/dev/loop5
  29. install_resources=resources/InstallResources
  30. build_resources=resources/BuildResources
  31. #A hacky way to ensure the loops are properly unmounted and the temp files are properly deleted.
  32. #Without this, a reboot is sometimes required to properly clean the loop devices and ensure a clean build
  33. cleanup() {
  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. set +e
  39. umount -l $outmnt > /dev/null 2>&1
  40. rmdir $outmnt > /dev/null 2>&1
  41. losetup -d $outdev > /dev/null 2>&1
  42. }
  43. trap cleanup INT TERM EXIT
  44. #layout the partitons and write filesystem information
  45. create_image() {
  46. dd if=/dev/zero of=$1 bs=$3 count=$4 conv=sparse
  47. parted --script $1 mklabel gpt
  48. cgpt create $1
  49. kernel_start=8192
  50. kernel_size=65536
  51. cgpt add -i 1 -t kernel -b $kernel_start -s $kernel_size -l Kernel -S 1 -T 5 -P 10 $1
  52. #Now the main filesystem
  53. root_start=$(($kernel_start + $kernel_size))
  54. end=`cgpt show $1 | grep 'Sec GPT table' | awk '{print $1}'`
  55. root_size=$(($end - $root_start))
  56. cgpt add -i 2 -t data -b $root_start -s $root_size -l Root $1
  57. # $root_size is in 512 byte blocks while ext4 uses a block size of 1024 bytes
  58. losetup -P $2 $1
  59. mkfs.ext4 -F -b 1024 ${2}p2 $(($root_size / 2))
  60. # mount the / partition
  61. mount -o noatime ${2}p2 $5
  62. }
  63. # use buster if no suite is specified
  64. if [ "$PRAWNOS_SUITE" = "" ]
  65. then
  66. PRAWNOS_SUITE=buster
  67. fi
  68. # create a 2GB image with the Chrome OS partition layout
  69. create_image PrawnOS-${PRAWNOS_SUITE}-Alpha-c201-libre-2GB.img-BASE $outdev 50M 40 $outmnt
  70. # use default debootstrap mirror if none is specified
  71. if [ "$PRAWNOS_DEBOOTSTRAP_MIRROR" = "" ]
  72. then
  73. PRAWNOS_DEBOOTSTRAP_MIRROR=http://ftp.us.debian.org/debian
  74. fi
  75. # install Debian on it
  76. export DEBIAN_FRONTEND=noninteractive
  77. qemu-debootstrap --arch armhf $PRAWNOS_SUITE --include locales,init --keyring=$build_resources/debian-archive-keyring.gpg $outmnt $PRAWNOS_DEBOOTSTRAP_MIRROR
  78. chroot $outmnt passwd -d root
  79. #Place the config files and installer script and give them the proper permissions
  80. echo -n PrawnOS-Alpha > $outmnt/etc/hostname
  81. cp -R $install_resources/ $outmnt/InstallResources/
  82. # and the icons for the lockscreen and app menu
  83. mkdir $outmnt/InstallResources/icons/
  84. cp $build_resources/logo/icons/icon-small.png $outmnt/InstallResources/icons/
  85. cp $build_resources/logo/icons/ascii/* $outmnt/InstallResources/icons/
  86. cp scripts/InstallScripts/* $outmnt/InstallResources/
  87. cp scripts/InstallScripts/InstallPrawnOS.sh $outmnt/
  88. chmod +x $outmnt/*.sh
  89. #Setup the chroot for apt
  90. #This is what https://wiki.debian.org/EmDebian/CrossDebootstrap suggests
  91. cp /etc/hosts $outmnt/etc/
  92. cp $build_resources/sources.list $outmnt/etc/apt/sources.list
  93. sed -i -e "s/suite/$PRAWNOS_SUITE/g" $outmnt/etc/apt/sources.list
  94. if [ "$PRAWNOS_SUITE" != "sid" ]
  95. then
  96. # sid doesn't have updates or security; they're present for all other suites
  97. cat $build_resources/updates.list >> $outmnt/etc/apt/sources.list
  98. sed -i -e "s/suite/$PRAWNOS_SUITE/g" $outmnt/etc/apt/sources.list
  99. # sid doesn't have backports; it's present for all other suites
  100. cp $build_resources/backports.list $outmnt/etc/apt/sources.list.d/
  101. sed -i -e "s/suite/$PRAWNOS_SUITE/g" $outmnt/etc/apt/sources.list.d/backports.list
  102. #setup apt pinning
  103. cp $build_resources/backports.pref $outmnt/etc/apt/preferences.d/
  104. sed -i -e "s/suite/$PRAWNOS_SUITE/g" $outmnt/etc/apt/preferences.d/backports.pref
  105. # Install sid (unstable) as an additional source for bleeding edge packages.
  106. cp $build_resources/sid.list $outmnt/etc/apt/sources.list.d/
  107. #setup apt pinning
  108. cp $build_resources/sid.pref $outmnt/etc/apt/preferences.d/
  109. fi
  110. if [ "$PRAWNOS_SUITE" = "buster" ]
  111. then
  112. # Install bullseye (testing) as an additional source
  113. cp $build_resources/bullseye.list $outmnt/etc/apt/sources.list.d/
  114. #setup apt pinning
  115. cp $build_resources/bullseye.pref $outmnt/etc/apt/preferences.d/
  116. fi
  117. #Setup the locale
  118. cp $build_resources/locale.gen $outmnt/etc/locale.gen
  119. chroot $outmnt locale-gen
  120. #Install the base packages
  121. chroot $outmnt apt update
  122. chroot $outmnt apt install -y 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 busybox-static cryptsetup
  123. #add the live-boot fstab
  124. cp -f $build_resources/external_fstab $outmnt/etc/fstab
  125. chmod 644 /etc/fstab
  126. #disable ertm for csr8510 bluetooth, issue #117
  127. echo "options bluetooth disable_ertm=Y" > $outmnt/etc/modprobe.d/bluetooth.conf
  128. #Cleanup to reduce install size
  129. chroot $outmnt apt-get autoremove --purge
  130. chroot $outmnt apt-get clean
  131. #Download support for libinput-gestures
  132. chroot $outmnt apt install -y libinput-tools xdotool build-essential
  133. #Package is copied into /InstallResources/packages
  134. chroot $outmnt apt-get install -y -t unstable -d xsecurelock
  135. #Download the packages to be installed by Install.sh:
  136. 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 emacs accountsservice sudo pavucontrol-qt papirus-icon-theme
  137. chroot $outmnt apt-get install -d -y firefox-esr
  138. # grab chromium as well, since sound is still broken in firefox for some media
  139. chroot $outmnt apt-get install -d -y chromium
  140. #Cleanup hosts
  141. rm -rf $outmnt/etc/hosts #This is what https://wiki.debian.org/EmDebian/CrossDebootstrap suggests
  142. echo -n "127.0.0.1 PrawnOS-Alpha" > $outmnt/etc/hosts
  143. umount -l $outmnt > /dev/null 2>&1
  144. rmdir $outmnt > /dev/null 2>&1
  145. losetup -d $outdev > /dev/null 2>&1
  146. echo "DONE!"
  147. trap - INT TERM EXIT