2018-06-21 18:33:30 +02:00
|
|
|
#!/bin/sh -xe
|
|
|
|
|
|
|
|
# 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-08-23 21:43:20 +02:00
|
|
|
KVER=4.17.2
|
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
|
|
|
|
|
2018-09-06 15:48:53 +02:00
|
|
|
[ ! -d build ] && echo "No build folder found, is the kernel built?" && exit
|
|
|
|
|
2018-06-21 18:33:30 +02:00
|
|
|
outmnt=$(mktemp -d -p `pwd`)
|
|
|
|
|
2018-07-11 00:32:08 +02:00
|
|
|
outdev=/dev/loop4
|
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.
|
2018-08-24 22:05:17 +02:00
|
|
|
#Without this, a reboot is sometimes required to properly clean the loop devices and ensure a clean build
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
create_image() {
|
|
|
|
# it's a sparse file - that's how we fit a 16GB image inside a 2GB one
|
|
|
|
dd if=/dev/zero of=$1 bs=$3 count=$4 conv=sparse
|
|
|
|
parted --script $1 mklabel gpt
|
|
|
|
cgpt create $1
|
|
|
|
cgpt add -i 1 -t kernel -b 8192 -s 65536 -l Kernel -S 1 -T 5 -P 10 $1
|
|
|
|
start=$((8192 + 65536))
|
|
|
|
end=`cgpt show $1 | grep 'Sec GPT table' | awk '{print $1}'`
|
|
|
|
size=$(($end - $start))
|
|
|
|
cgpt add -i 2 -t data -b $start -s $size -l Root $1
|
|
|
|
# $size is in 512 byte blocks while ext4 uses a block size of 1024 bytes
|
|
|
|
losetup -P $2 $1
|
|
|
|
mkfs.ext4 -F -b 1024 -m 0 -O ^has_journal ${2}p2 $(($size / 2))
|
|
|
|
|
|
|
|
# mount the / partition
|
|
|
|
mount -o noatime ${2}p2 $5
|
|
|
|
}
|
|
|
|
|
|
|
|
# create a 2GB image with the Chrome OS partition layout
|
2018-09-06 01:35:33 +02:00
|
|
|
create_image PrawnOS-Alpha-c201-libre-2GB.img $outdev 50M 40 $outmnt
|
2018-06-21 18:33:30 +02:00
|
|
|
|
|
|
|
# install Debian on it
|
2018-06-28 02:46:28 +02:00
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
2018-10-23 03:50:25 +02:00
|
|
|
qemu-debootstrap --arch armhf stretch --include locales,init --keyring=$build_resources/debian-archive-keyring.gpg $outmnt http://ftp.us.debian.org/debian
|
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
|
2018-09-06 01:35:33 +02:00
|
|
|
echo -n PrawnOS-Alpha > $outmnt/etc/hostname
|
|
|
|
cp -R $install_resources/ $outmnt/InstallResources/
|
|
|
|
cp scripts/InstallScripts/* $outmnt/InstallResources/
|
|
|
|
cp scripts/InstallScripts/InstallToInternal.sh $outmnt/
|
|
|
|
chmod +x $outmnt/*.sh
|
2018-08-24 22:05:17 +02:00
|
|
|
|
|
|
|
#Setup the chroot for apt
|
|
|
|
#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
|
2018-08-24 22:05:17 +02:00
|
|
|
|
|
|
|
#Setup the locale
|
2018-10-02 04:01:08 +02:00
|
|
|
chroot $outmnt echo en_US.UTF-8 UTF-8 > /etc/locale.gen
|
|
|
|
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
|
2018-10-24 01:04:18 +02:00
|
|
|
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
|
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-20 17:10:47 +02:00
|
|
|
#Download the packages to be installed by Install.sh:
|
2018-10-30 20:02:41 +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-tools plank network-manager-gnome network-manager-openvpn network-manager-openvpn-gnome dtrx emacs25 accountsservice firefox-esr
|
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
|
|
|
|
|
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
|
2018-09-06 01:35:33 +02:00
|
|
|
echo -n "127.0.0.1 PrawnOS-Alpha" > $outmnt/etc/hosts
|
2018-06-28 02:46:28 +02:00
|
|
|
|
2018-06-21 18:33:30 +02:00
|
|
|
# put the kernel in the kernel partition, modules in /lib/modules and AR9271
|
|
|
|
# firmware in /lib/firmware
|
2018-09-06 01:35:33 +02:00
|
|
|
dd if=build/linux-$KVER/vmlinux.kpart of=${outdev}p1 conv=notrunc
|
|
|
|
make -C build/linux-$KVER ARCH=arm INSTALL_MOD_PATH=$outmnt modules_install
|
2018-06-21 18:33:30 +02:00
|
|
|
rm -f $outmnt/lib/modules/3.14.0/{build,source}
|
2018-09-06 01:35:33 +02:00
|
|
|
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
|
2018-09-23 00:29:45 +02:00
|
|
|
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
|
2018-06-21 18:33:30 +02:00
|
|
|
|
2018-09-20 17:10:47 +02:00
|
|
|
#Install the regulatory.db files
|
|
|
|
install -m 644 $build_resources/regdb/wireless-regdb-2018.09.07/regulatory.db* $outmnt/lib/firmware/
|
2018-06-21 18:33:30 +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
|