buildFilesystem.sh 6.8 KB

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