2020-05-09 11:00:02 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -x
|
|
|
|
set -e
|
2018-06-21 18:33:30 +02:00
|
|
|
|
|
|
|
# Build fs, image
|
|
|
|
|
|
|
|
|
2018-10-11 22:09:25 +02:00
|
|
|
# This file is part of PrawnOS (http://www.prawnos.com)
|
|
|
|
# Copyright (c) 2018 Hal Emmerich <hal@halemmerich.com>
|
|
|
|
|
|
|
|
# PrawnOS is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License version 2
|
|
|
|
# as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
# PrawnOS is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with PrawnOS. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
2018-06-21 18:33:30 +02:00
|
|
|
|
2018-08-24 22:05:17 +02:00
|
|
|
#Ensure Sudo
|
2018-09-06 01:35:33 +02:00
|
|
|
if [ ! $UID = "0" ]
|
|
|
|
then
|
|
|
|
echo "Please run this script with sudo, or as root:"
|
2018-08-24 22:05:17 +02:00
|
|
|
echo "sudo $0 $*"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-02-27 20:20:11 +01:00
|
|
|
if [ -z "$1" ]
|
|
|
|
then
|
|
|
|
echo "No kernel version supplied"
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-01-11 21:56:45 +01:00
|
|
|
if [ -z "$2" ]
|
|
|
|
then
|
|
|
|
echo "No debian suite supplied"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ -z "$3" ]
|
|
|
|
then
|
|
|
|
echo "No base file system image filename supplied"
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-02-27 20:20:11 +01:00
|
|
|
KVER=$1
|
2020-01-11 21:56:45 +01:00
|
|
|
DEBIAN_SUITE=$2
|
|
|
|
BASE=$3
|
2019-02-27 20:20:11 +01:00
|
|
|
|
2018-06-21 18:33:30 +02:00
|
|
|
outmnt=$(mktemp -d -p `pwd`)
|
|
|
|
|
2019-02-27 20:20:11 +01:00
|
|
|
outdev=/dev/loop5
|
2018-09-06 01:35:33 +02:00
|
|
|
|
|
|
|
install_resources=resources/InstallResources
|
|
|
|
build_resources=resources/BuildResources
|
2018-06-21 18:33:30 +02:00
|
|
|
|
|
|
|
#A hacky way to ensure the loops are properly unmounted and the temp files are properly deleted.
|
2019-10-13 00:39:17 +02:00
|
|
|
#Without this, a reboot is sometimes required to properly clean the loop devices and ensure a clean build
|
2018-08-24 22:05:17 +02:00
|
|
|
cleanup() {
|
|
|
|
set +e
|
2018-06-21 18:33:30 +02:00
|
|
|
|
2018-08-24 22:05:17 +02:00
|
|
|
umount -l $outmnt > /dev/null 2>&1
|
|
|
|
rmdir $outmnt > /dev/null 2>&1
|
|
|
|
losetup -d $outdev > /dev/null 2>&1
|
2018-06-21 18:33:30 +02:00
|
|
|
|
|
|
|
set +e
|
|
|
|
|
|
|
|
umount -l $outmnt > /dev/null 2>&1
|
|
|
|
rmdir $outmnt > /dev/null 2>&1
|
|
|
|
losetup -d $outdev > /dev/null 2>&1
|
|
|
|
}
|
|
|
|
|
2018-08-24 22:05:17 +02:00
|
|
|
trap cleanup INT TERM EXIT
|
2018-06-21 18:33:30 +02:00
|
|
|
|
2019-10-06 20:13:33 +02:00
|
|
|
#layout the partitons and write filesystem information
|
2018-06-21 18:33:30 +02:00
|
|
|
create_image() {
|
|
|
|
dd if=/dev/zero of=$1 bs=$3 count=$4 conv=sparse
|
|
|
|
parted --script $1 mklabel gpt
|
|
|
|
cgpt create $1
|
2019-10-06 20:13:33 +02:00
|
|
|
kernel_start=8192
|
|
|
|
kernel_size=65536
|
|
|
|
cgpt add -i 1 -t kernel -b $kernel_start -s $kernel_size -l Kernel -S 1 -T 5 -P 10 $1
|
|
|
|
#Now the main filesystem
|
2019-10-13 00:39:17 +02:00
|
|
|
root_start=$(($kernel_start + $kernel_size))
|
2018-06-21 18:33:30 +02:00
|
|
|
end=`cgpt show $1 | grep 'Sec GPT table' | awk '{print $1}'`
|
2019-10-06 20:13:33 +02:00
|
|
|
root_size=$(($end - $root_start))
|
2019-10-15 15:51:16 +02:00
|
|
|
cgpt add -i 2 -t data -b $root_start -s $root_size -l Root $1
|
|
|
|
# $root_size is in 512 byte blocks while ext4 uses a block size of 1024 bytes
|
2018-06-21 18:33:30 +02:00
|
|
|
losetup -P $2 $1
|
2019-10-15 15:51:16 +02:00
|
|
|
mkfs.ext4 -F -b 1024 ${2}p2 $(($root_size / 2))
|
2018-06-21 18:33:30 +02:00
|
|
|
|
|
|
|
# mount the / partition
|
2019-10-13 00:39:17 +02:00
|
|
|
mount -o noatime ${2}p2 $5
|
2018-06-21 18:33:30 +02:00
|
|
|
}
|
|
|
|
|
2020-04-01 08:13:20 +02:00
|
|
|
build_install_crossystem() {
|
|
|
|
# install crossystem
|
|
|
|
apt install -y vboot-utils
|
|
|
|
|
|
|
|
#install clang and pre-reqs
|
|
|
|
apt install -y clang uuid-dev meson pkg-config cmake libcmocka-dev cargo
|
|
|
|
|
|
|
|
flashmap_src=/root/flashmap
|
|
|
|
mosys_src=/root/mosys
|
|
|
|
mkdir $flashmap_src
|
|
|
|
mkdir $mosys_src
|
|
|
|
#clone flashmap, need to build libfmap
|
|
|
|
git clone https://github.com/dhendrix/flashmap.git /root/flashmap
|
|
|
|
cd $flashmap_src && make all
|
|
|
|
cd $flashmap_src && make install
|
|
|
|
ldconfig
|
|
|
|
|
|
|
|
#clone mosys. Later releases start depending on the minijail library which we would have to build, and that we don't care about anyway on linux
|
|
|
|
git clone https://chromium.googlesource.com/chromiumos/platform/mosys /root/mosys
|
|
|
|
cd $mosys_src && git checkout release-R69-10895.B
|
|
|
|
|
|
|
|
mkdir $mosys_src/build
|
|
|
|
# compile the c parts
|
|
|
|
cd $mosys_src && CFLAGS="-Wno-error" CC=clang meson -Darch=arm $mosys_src/build
|
|
|
|
cd $mosys_src && ninja -C $mosys_src/build
|
|
|
|
|
|
|
|
# install mosys so crossystem can access it. It EXPECTS it to be right here and fails otherwise...
|
|
|
|
mkdir -p /usr/sbin/
|
|
|
|
cp --verbose $mosys_src/build/mosys /usr/sbin/
|
|
|
|
|
|
|
|
# cleanup the source
|
|
|
|
rm -rf $flashmap_src
|
|
|
|
rm -rf $mosys_src
|
|
|
|
|
|
|
|
# cleanup the unnecessary build packages, need the noninteractive flag as -y is not enough to avoid prompting users on remove for some reason
|
|
|
|
DEBIAN_FRONTEND=noninteractive apt-get purge -y --auto-remove clang meson libcmocka-dev cargo cmake pkg-config
|
|
|
|
}
|
|
|
|
|
2019-05-23 00:50:16 +02:00
|
|
|
# create a 2GB image with the Chrome OS partition layout
|
2020-01-11 21:56:45 +01:00
|
|
|
create_image $BASE $outdev 50M 40 $outmnt
|
2018-06-21 18:33:30 +02:00
|
|
|
|
2018-12-01 17:33:00 +01:00
|
|
|
# use default debootstrap mirror if none is specified
|
|
|
|
if [ "$PRAWNOS_DEBOOTSTRAP_MIRROR" = "" ]
|
|
|
|
then
|
|
|
|
PRAWNOS_DEBOOTSTRAP_MIRROR=http://ftp.us.debian.org/debian
|
|
|
|
fi
|
|
|
|
|
2018-06-21 18:33:30 +02:00
|
|
|
# install Debian on it
|
2018-06-28 02:46:28 +02:00
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
2020-01-11 21:56:45 +01:00
|
|
|
qemu-debootstrap --arch armhf $DEBIAN_SUITE --include locales,init --keyring=$build_resources/debian-archive-keyring.gpg $outmnt $PRAWNOS_DEBOOTSTRAP_MIRROR
|
2018-06-21 18:33:30 +02:00
|
|
|
chroot $outmnt passwd -d root
|
2018-08-24 22:05:17 +02:00
|
|
|
|
2018-10-02 04:01:08 +02:00
|
|
|
|
2018-08-24 22:05:17 +02:00
|
|
|
#Place the config files and installer script and give them the proper permissions
|
2020-01-11 21:58:19 +01:00
|
|
|
echo -n PrawnOS > $outmnt/etc/hostname
|
2018-09-06 01:35:33 +02:00
|
|
|
cp -R $install_resources/ $outmnt/InstallResources/
|
2019-05-23 00:50:16 +02:00
|
|
|
# and the icons for the lockscreen and app menu
|
2019-05-23 23:47:16 +02:00
|
|
|
mkdir $outmnt/InstallResources/icons/
|
|
|
|
cp $build_resources/logo/icons/icon-small.png $outmnt/InstallResources/icons/
|
|
|
|
cp $build_resources/logo/icons/ascii/* $outmnt/InstallResources/icons/
|
2018-09-06 01:35:33 +02:00
|
|
|
cp scripts/InstallScripts/* $outmnt/InstallResources/
|
2019-10-20 23:53:13 +02:00
|
|
|
cp scripts/InstallScripts/InstallPrawnOS.sh $outmnt/
|
2018-09-06 01:35:33 +02:00
|
|
|
chmod +x $outmnt/*.sh
|
2018-08-24 22:05:17 +02:00
|
|
|
|
2019-08-22 03:07:29 +02:00
|
|
|
#Setup the chroot for apt
|
2018-08-24 22:05:17 +02:00
|
|
|
#This is what https://wiki.debian.org/EmDebian/CrossDebootstrap suggests
|
|
|
|
cp /etc/hosts $outmnt/etc/
|
2018-10-03 18:39:10 +02:00
|
|
|
cp $build_resources/sources.list $outmnt/etc/apt/sources.list
|
2020-01-11 21:56:45 +01:00
|
|
|
sed -i -e "s/suite/$DEBIAN_SUITE/g" $outmnt/etc/apt/sources.list
|
|
|
|
if [ "$DEBIAN_SUITE" != "sid" ]
|
2019-06-07 19:05:58 +02:00
|
|
|
then
|
|
|
|
# sid doesn't have updates or security; they're present for all other suites
|
|
|
|
cat $build_resources/updates.list >> $outmnt/etc/apt/sources.list
|
2020-01-11 21:56:45 +01:00
|
|
|
sed -i -e "s/suite/$DEBIAN_SUITE/g" $outmnt/etc/apt/sources.list
|
2019-06-07 19:05:58 +02:00
|
|
|
# sid doesn't have backports; it's present for all other suites
|
|
|
|
cp $build_resources/backports.list $outmnt/etc/apt/sources.list.d/
|
2020-01-11 21:56:45 +01:00
|
|
|
sed -i -e "s/suite/$DEBIAN_SUITE/g" $outmnt/etc/apt/sources.list.d/backports.list
|
2019-06-07 19:05:58 +02:00
|
|
|
#setup apt pinning
|
|
|
|
cp $build_resources/backports.pref $outmnt/etc/apt/preferences.d/
|
2020-01-11 21:56:45 +01:00
|
|
|
sed -i -e "s/suite/$DEBIAN_SUITE/g" $outmnt/etc/apt/preferences.d/backports.pref
|
2019-10-07 04:57:19 +02:00
|
|
|
# Install sid (unstable) as an additional source for bleeding edge packages.
|
|
|
|
cp $build_resources/sid.list $outmnt/etc/apt/sources.list.d/
|
2019-06-07 19:05:58 +02:00
|
|
|
#setup apt pinning
|
2019-10-07 04:57:19 +02:00
|
|
|
cp $build_resources/sid.pref $outmnt/etc/apt/preferences.d/
|
2019-06-07 19:05:58 +02:00
|
|
|
fi
|
2020-01-11 21:56:45 +01:00
|
|
|
if [ "$DEBIAN_SUITE" = "buster" ]
|
2019-06-07 19:05:58 +02:00
|
|
|
then
|
2019-10-07 04:57:19 +02:00
|
|
|
# Install bullseye (testing) as an additional source
|
|
|
|
cp $build_resources/bullseye.list $outmnt/etc/apt/sources.list.d/
|
2019-06-07 19:05:58 +02:00
|
|
|
#setup apt pinning
|
2019-10-07 04:57:19 +02:00
|
|
|
cp $build_resources/bullseye.pref $outmnt/etc/apt/preferences.d/
|
2019-06-07 19:05:58 +02:00
|
|
|
fi
|
2018-08-24 22:05:17 +02:00
|
|
|
|
|
|
|
#Setup the locale
|
2019-01-10 20:43:03 +01:00
|
|
|
cp $build_resources/locale.gen $outmnt/etc/locale.gen
|
2018-10-02 04:01:08 +02:00
|
|
|
chroot $outmnt locale-gen
|
2018-08-24 22:05:17 +02:00
|
|
|
|
|
|
|
#Install the base packages
|
2018-06-21 18:33:30 +02:00
|
|
|
chroot $outmnt apt update
|
2020-03-31 05:09:27 +02:00
|
|
|
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 vim
|
2019-09-18 03:50:27 +02:00
|
|
|
|
2020-04-01 08:13:20 +02:00
|
|
|
#build and install crossystem/mosys, funky way to call the bash function inside the chroot
|
|
|
|
export -f build_install_crossystem
|
|
|
|
chroot $outmnt /bin/bash -ec "build_install_crossystem"
|
|
|
|
|
2019-05-23 07:19:32 +02:00
|
|
|
#add the live-boot fstab
|
|
|
|
cp -f $build_resources/external_fstab $outmnt/etc/fstab
|
2020-04-01 08:13:20 +02:00
|
|
|
chmod 644 $outmnt/etc/fstab
|
2019-05-23 07:19:32 +02:00
|
|
|
|
2018-08-24 22:05:17 +02:00
|
|
|
#Cleanup to reduce install size
|
2018-06-21 18:33:30 +02:00
|
|
|
chroot $outmnt apt-get autoremove --purge
|
|
|
|
chroot $outmnt apt-get clean
|
2018-08-24 22:05:17 +02:00
|
|
|
|
2018-09-22 06:12:52 +02:00
|
|
|
#Download support for libinput-gestures
|
|
|
|
chroot $outmnt apt install -y libinput-tools xdotool build-essential
|
|
|
|
#Package is copied into /InstallResources/packages
|
|
|
|
|
2020-01-11 23:37:14 +01:00
|
|
|
chroot $outmnt apt-get install -y -t testing -d xsecurelock
|
2019-01-10 20:43:03 +01:00
|
|
|
|
|
|
|
#Download the packages to be installed by Install.sh:
|
2019-12-03 03:39:48 +01:00
|
|
|
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
|
2019-05-22 03:00:07 +02:00
|
|
|
|
2019-10-09 07:03:45 +02:00
|
|
|
chroot $outmnt apt-get install -d -y firefox-esr
|
2019-05-22 03:00:07 +02:00
|
|
|
# grab chromium as well, since sound is still broken in firefox for some media
|
2019-01-10 20:43:03 +01:00
|
|
|
|
2018-08-24 22:05:17 +02:00
|
|
|
#Cleanup hosts
|
|
|
|
rm -rf $outmnt/etc/hosts #This is what https://wiki.debian.org/EmDebian/CrossDebootstrap suggests
|
2020-01-16 01:10:55 +01:00
|
|
|
echo -n "127.0.0.1 PrawnOS" > $outmnt/etc/hosts
|
2018-06-28 02:46:28 +02:00
|
|
|
|
2018-09-13 03:38:20 +02:00
|
|
|
umount -l $outmnt > /dev/null 2>&1
|
|
|
|
rmdir $outmnt > /dev/null 2>&1
|
|
|
|
losetup -d $outdev > /dev/null 2>&1
|
|
|
|
echo "DONE!"
|
|
|
|
trap - INT TERM EXIT
|