Update and fix gateworks-newport.sh

This commit is contained in:
Arszilla
2022-08-22 20:25:01 +03:00
parent c8b70e9098
commit 4e37edced4

View File

@@ -9,8 +9,10 @@
# Hardware model
hw_model=${hw_model:-"gateworks-newport"}
# Architecture
architecture=${architecture:-"arm64"}
# Desktop manager (xfce, gnome, i3, kde, lxde, mate, e17 or none)
desktop=${desktop:-"xfce"}
@@ -22,7 +24,7 @@ basic_network
add_interface eth0
# Third stage
cat <<EOF >> "${work_dir}"/third-stage
cat <<EOF >>"${work_dir}"/third-stage
status_stage3 'Ensure mkimage is available'
eatmydata apt-get install -y u-boot-tools
@@ -51,32 +53,38 @@ cd "${base_dir}/"
status "Kernel stuff"
git clone --depth 1 -b v5.4.45-newport https://github.com/gateworks/linux-newport ${work_dir}/usr/src/kernel
cd ${work_dir}/usr/src/kernel
# Don't change the version because of our patches
touch .scmversion
export ARCH=arm64
export CROSS_COMPILE=aarch64-linux-gnu-
patch -p1 < ${repo_dir}/patches/kali-wifi-injection-5.4.patch
patch -p1 < ${repo_dir}/patches/0001-wireless-carl9170-Enable-sniffer-mode-promisc-flag-t.patch
patch -p1 <${repo_dir}/patches/kali-wifi-injection-5.4.patch
patch -p1 <${repo_dir}/patches/0001-wireless-carl9170-Enable-sniffer-mode-promisc-flag-t.patch
cp ${repo_dir}/kernel-configs/gateworks-newport-5.4.45.config .config
cp ${repo_dir}/kernel-configs/gateworks-newport-5.4.45.config ${work_dir}/usr/src/gateworks-newport-5.4.45.config
#build
make -j $(grep -c processor /proc/cpuinfo)
# install compressed kernel in a kernel.itb
# Install compressed kernel in a kernel.itb
mkimage -f auto -A arm64 -O linux -T kernel -C gzip -n "Newport Kali Kernel" -a 20080000 -e 20080000 -d arch/arm64/boot/Image.gz kernel.itb
cp kernel.itb ${work_dir}/boot
# install kernel modules
# Install kernel modules
make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=${work_dir} modules_install
make INSTALL_HDR_PATH=${work_dir}/usr headers_install
# cryptodev-linux build/install
git clone --depth 1 https://github.com/cryptodev-linux/cryptodev-linux ${work_dir}/usr/src/cryptodev-linux
cd ${work_dir}/usr/src
make -C cryptodev-linux KERNEL_DIR=${work_dir}/usr/src/kernel
make -C cryptodev-linux KERNEL_DIR=${work_dir}/usr/src/kernel DESTDIR=${work_dir} INSTALL_MOD_PATH=${work_dir} install
# wireguard-linux-compat build/install
git clone --depth 1 https://git.zx2c4.com/wireguard-linux-compat ${work_dir}/usr/src/wireguard-linux-compat
make -C ${work_dir}/usr/src/kernel M=../wireguard-linux-compat/src modules
make -C ${work_dir}/usr/src/kernel M=../wireguard-linux-compat/src INSTALL_MOD_PATH=${work_dir} modules_install
# cleanup
# Cleanup
cd ${work_dir}/usr/src/kernel
make mrproper
@@ -88,20 +96,21 @@ rm ${work_dir}/boot/newport.script
# reboot script
status "Reboot script"
cat << EOF > ${work_dir}/lib/systemd/system-shutdown/gsc-poweroff
cat <<EOF >${work_dir}/lib/systemd/system-shutdown/gsc-poweroff
#!/usr/bin/env bash
# use GSC to power cycle the system
echo 2 > /sys/bus/i2c/devices/0-0020/powerdown
done
EOF
chmod +x ${work_dir}/lib/systemd/system-shutdown/gsc-poweroff
cd "${repo_dir}/"
# Calculate the space to create the image
root_size=$(du -s -B1 ${work_dir} --exclude=${work_dir}/boot | cut -f1)
root_extra=$((${root_size}/1024/1000*5*1024/5))
raw_size=$(($((${free_space}*1024))+${root_extra}))
root_extra=$((${root_size} / 1024 / 1000 * 5 * 1024 / 5))
raw_size=$(($((${free_space} * 1024)) + ${root_extra}))
# Weird Boot Partition
status "Creating image file ${image_name}.img"
@@ -113,18 +122,23 @@ echo ", +" | sfdisk -N 2 "${image_dir}/${image_name}.img"
# Set the partition variables
make_loop
# Create file systems
mkfs_partitions
# Make fstab.
make_fstab
# Create the dirs for the partitions and mount them
status "Create the dirs for the partitions and mount them"
mkdir -p "${base_dir}"/root
if [[ $fstype == ext4 ]]; then
mount -t ext4 -o noatime,data=writeback,barrier=0 "${rootp}" "${base_dir}"/root
mount -t ext4 -o noatime,data=writeback,barrier=0 "${rootp}" "${base_dir}"/root
else
mount "${rootp}" "${base_dir}"/root
mount "${rootp}" "${base_dir}"/root
fi
status "Rsyncing rootfs into image file"