This breaks the un-converted scripts but that gives more reason to move them to the new way over the coming days.
304 lines
10 KiB
Bash
Executable File
304 lines
10 KiB
Bash
Executable File
#!/bin/bash -e
|
|
# This is the ODROID-XU3/XU4 Kali ARM 32 bit build script - http://www.kali.org/get-kali
|
|
# A trusted Kali Linux image created by Offensive Security - http://www.offensive-security.com
|
|
|
|
# shellcheck disable=SC2154
|
|
# Load general functions
|
|
# shellcheck source=/dev/null
|
|
source ./common.d/functions.sh
|
|
|
|
# Hardware model
|
|
hw_model=${hw_model:-"odroid-xu3"}
|
|
# Architecture
|
|
architecture=${architecture:-"armhf"}
|
|
# Variant name for image and dir build
|
|
variant=${variant:-"${architecture}"}
|
|
# Desktop manager (xfce, gnome, i3, kde, lxde, mate, e17 or none)
|
|
desktop=${desktop:-"xfce"}
|
|
|
|
# Load common variables
|
|
include variables
|
|
# Checks script enviroment
|
|
include check
|
|
# Packages build list
|
|
include packages
|
|
# Load automatic proxy configuration
|
|
include proxy_apt
|
|
# Execute initial debootstrap
|
|
debootstrap_exec http://http.kali.org/kali
|
|
# Enable eatmydata in compilation
|
|
include eatmydata
|
|
# debootstrap second stage
|
|
systemd-nspawn_exec eatmydata /debootstrap/debootstrap --second-stage
|
|
# Define sources.list
|
|
include sources.list
|
|
# APT options
|
|
include apt_options
|
|
# So X doesn't complain, we add kali to hosts
|
|
include hosts
|
|
# Set hostname
|
|
set_hostname "${hostname}"
|
|
# Network configs
|
|
include network
|
|
add_interface eth0
|
|
# Copy directory bsp into build dir.
|
|
cp -rp bsp "${work_dir}"
|
|
|
|
# Disable RESUME (suspend/resume is currently broken anyway!) which speeds up boot massively.
|
|
mkdir -p ${work_dir}/etc/initramfs-tools/conf.d/
|
|
cat << EOF > ${work_dir}/etc/initramfs-tools/conf.d/resume
|
|
RESUME=none
|
|
EOF
|
|
|
|
# Third stage
|
|
cat <<EOF >"${work_dir}"/third-stage
|
|
#!/bin/bash -e
|
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
eatmydata apt-get update
|
|
eatmydata apt-get -y install ${third_stage_pkgs}
|
|
|
|
eatmydata apt-get install -y ${packages} || eatmydata apt-get install -y --fix-broken
|
|
eatmydata apt-get install -y ${desktop_pkgs} ${extra} || eatmydata apt-get install -y --fix-broken
|
|
|
|
eatmydata apt-get -y --purge autoremove
|
|
|
|
# Linux console/Keyboard configuration
|
|
echo 'console-common console-data/keymap/policy select Select keymap from full list' | debconf-set-selections
|
|
echo 'console-common console-data/keymap/full select en-latin1-nodeadkeys' | debconf-set-selections
|
|
|
|
# Copy all services
|
|
cp -p /bsp/services/all/*.service /etc/systemd/system/
|
|
|
|
# Copy script rpi-resizerootfs
|
|
install -m755 /bsp/scripts/rpi-resizerootfs /usr/sbin/
|
|
|
|
# Enable rpi-resizerootfs first boot
|
|
systemctl enable rpi-resizerootfs
|
|
|
|
# Generate SSH host keys on first run
|
|
systemctl enable regenerate_ssh_host_keys
|
|
|
|
# Allow users to use NM over ssh
|
|
install -m644 /bsp/polkit/10-NetworkManager.pkla /var/lib/polkit-1/localauthority/50-local.d
|
|
|
|
cd /root
|
|
apt download -o APT::Sandbox::User=root ca-certificates 2>/dev/null
|
|
|
|
# Set a REGDOMAIN. This needs to be done or wireless doesn't work correctly on the RPi 3B+
|
|
sed -i -e 's/REGDOM.*/REGDOMAIN=00/g' /etc/default/crda
|
|
|
|
# Enable login over serial
|
|
echo "T0:23:respawn:/sbin/agetty -L ttySAC2 115200 vt100" >> /etc/inittab
|
|
|
|
# Try and make the console a bit nicer
|
|
# Set the terminus font for a bit nicer display.
|
|
sed -i -e 's/FONTFACE=.*/FONTFACE="Terminus"/' /etc/default/console-setup
|
|
sed -i -e 's/FONTSIZE=.*/FONTSIZE="6x12"/' /etc/default/console-setup
|
|
|
|
# Fix startup time from 5 minutes to 15 secs on raise interface wlan0
|
|
sed -i 's/^TimeoutStartSec=5min/TimeoutStartSec=15/g' "/usr/lib/systemd/system/networking.service"
|
|
|
|
cat << __EOF__ >> /etc/udev/links.conf
|
|
M ttySAC2 c 5 1
|
|
__EOF__
|
|
|
|
cat << _EOF_ >> /etc/securetty
|
|
ttySAC0
|
|
ttySAC1
|
|
ttySAC2
|
|
_EOF_
|
|
|
|
# Serial console settings.
|
|
# (Auto login on serial console)
|
|
#T1:12345:respawn:/sbin/agetty 115200 ttySAC2 vt100 >> /etc/inittab
|
|
# (No auto login)
|
|
#T1:12345:respawn:/bin/login -f root ttySAC2 /dev/ttySAC2 2>&1' >> /etc/inittab
|
|
# Make sure ttySACX is in root/etc/securetty so root can login on serial console below.
|
|
echo 'T1:12345:respawn:/bin/login -f root ttySAC2 /dev/ttySAC2 2>&1' >> /etc/inittab
|
|
|
|
# Enable runonce
|
|
install -m755 /bsp/scripts/runonce /usr/sbin/
|
|
cp -rf /bsp/runonce.d /etc
|
|
systemctl enable runonce
|
|
|
|
# Clean up dpkg.eatmydata
|
|
rm -f /usr/bin/dpkg
|
|
dpkg-divert --remove --rename /usr/bin/dpkg
|
|
EOF
|
|
|
|
# Run third stage
|
|
chmod 755 "${work_dir}"/third-stage
|
|
systemd-nspawn_exec /third-stage
|
|
|
|
# Choose a locale
|
|
set_locale "$locale"
|
|
# Clean system
|
|
include clean_system
|
|
# Define DNS server after last running systemd-nspawn.
|
|
echo "nameserver ${nameserver}" >"${work_dir}"/etc/resolv.conf
|
|
# Disable the use of http proxy in case it is enabled.
|
|
disable_proxy
|
|
# Mirror & suite replacement
|
|
restore_mirror
|
|
# Reload sources.list
|
|
#include sources.list
|
|
|
|
# Kernel section. If you want to use a custom kernel, or configuration, replace
|
|
# them in this section.
|
|
git clone --depth 1 https://github.com/hardkernel/linux.git -b odroidxu4-4.14.y ${work_dir}/usr/src/kernel
|
|
cd ${work_dir}/usr/src/kernel
|
|
git rev-parse HEAD > ${work_dir}/usr/src/kernel-at-commit
|
|
patch -p1 --no-backup-if-mismatch < ${current_dir}/patches/kali-wifi-injection-4.14.patch
|
|
patch -p1 --no-backup-if-mismatch < ${current_dir}/patches/0001-wireless-carl9170-Enable-sniffer-mode-promisc-flag-t.patch
|
|
touch .scmversion
|
|
export ARCH=arm
|
|
export CROSS_COMPILE=arm-linux-gnueabihf-
|
|
cp ${current_dir}/kernel-configs/odroid-xu3.config .config
|
|
cp ${current_dir}/kernel-configs/odroid-xu3.config ../odroid-xu3.config
|
|
make -j $(grep -c processor /proc/cpuinfo)
|
|
make modules_install INSTALL_MOD_PATH=${work_dir}
|
|
cp arch/arm/boot/zImage ${work_dir}/boot
|
|
cp arch/arm/boot/dts/exynos5422-odroidxu3.dtb ${work_dir}/boot
|
|
cp arch/arm/boot/dts/exynos5422-odroidxu3-lite.dtb ${work_dir}/boot
|
|
cp arch/arm/boot/dts/exynos5422-odroidxu4.dtb ${work_dir}/boot
|
|
cp arch/arm/boot/dts/exynos5422-odroidxu4-kvm.dtb ${work_dir}/boot
|
|
make mrproper
|
|
cp ${current_dir}/kernel-configs/odroid-xu3.config .config
|
|
cp ${current_dir}/kernel-configs/odroid-xu3.config ../odroid-xu3.config
|
|
cd "${basedir}"
|
|
|
|
# Fix up the symlink for building external modules
|
|
# kernver is used so we don't need to keep track of what the current compiled
|
|
# version is
|
|
kernver=$(ls ${work_dir}/lib/modules/)
|
|
cd ${work_dir}/lib/modules/${kernver}
|
|
rm build
|
|
rm source
|
|
ln -s /usr/src/kernel build
|
|
ln -s /usr/src/kernel source
|
|
|
|
cat << EOF > ${work_dir}/boot/boot.ini
|
|
ODROIDXU-UBOOT-CONFIG
|
|
|
|
# U-Boot Parameters
|
|
setenv initrd_high "0xffffffff"
|
|
setenv fdt_high "0xffffffff"
|
|
|
|
# Mac address configuration
|
|
setenv macaddr "00:1e:06:61:7a:39"
|
|
|
|
#------------------------------------------------------------------------------------------------------
|
|
# Basic Ubuntu Setup. Don't touch unless you know what you are doing.
|
|
# --------------------------------
|
|
setenv bootrootfs "console=tty1 console=ttySAC2,115200n8 root=/dev/mmcblk0p2 rootwait rootfstype=$fstype net.ifnames=0 rw"
|
|
|
|
# boot commands
|
|
# Uncomment the following if you use an initrd
|
|
#setenv bootcmd "fatload mmc 0:1 0x40008000 zImage; fatload mmc 0:1 0x42000000 uInitrd; fatload mmc 0:1 0x44000000 exynos5422-odroidxu3.dtb; bootz 0x40008000 0x42000000 0x44000000"
|
|
# Uncomment the following if you do NOT use an initrd
|
|
setenv bootcmd "fatload mmc 0:1 0x40008000 zImage; fatload mmc 0:1 0x42000000 uInitrd; fatload mmc 0:1 0x44000000 exynos5422-odroidxu3.dtb; bootz 0x40008000 - 0x44000000"
|
|
|
|
# --- Screen Configuration for HDMI --- #
|
|
# ---------------------------------------
|
|
# Uncomment only ONE line! Leave all commented for automatic selection.
|
|
# Uncomment only the setenv line!
|
|
# ---------------------------------------
|
|
# ODROID-VU forced resolution
|
|
# setenv videoconfig "video=HDMI-A-1:1280x800@60"
|
|
# -----------------------------------------------
|
|
# 1920x1080 (1080P) with monitor provided EDID information. (1080p-edid)
|
|
# setenv videoconfig "video=HDMI-A-1:1920x1080@60"
|
|
# -----------------------------------------------
|
|
# 1920x1080 (1080P) without monitor data using generic information (1080p-noedid)
|
|
# setenv videoconfig "drm_kms_helper.edid_firmware=edid/1920x1080.bin"
|
|
# -----------------------------------------------
|
|
# 1280x720 (720P) with monitor provided EDID information. (720p-edid)
|
|
# setenv videoconfig "video=HDMI-A-1:1280x720@60"
|
|
# -----------------------------------------------
|
|
# 1280x720 (720P) without monitor data using generic information (720p-noedid)
|
|
# setenv videoconfig "drm_kms_helper.edid_firmware=edid/1280x720.bin"
|
|
# -----------------------------------------------
|
|
# 1024x768 without monitor data using generic information
|
|
# setenv videoconfig "drm_kms_helper.edid_firmware=edid/1024x768.bin"
|
|
|
|
|
|
# final boot args
|
|
setenv bootargs "\${bootrootfs} \${videoconfig} smsc95xx.macaddr=\${macaddr}"
|
|
# drm.debug=0xff
|
|
# Boot the board
|
|
boot
|
|
EOF
|
|
|
|
|
|
cd ${current_dir}
|
|
|
|
# Calculate the space to create the image and create.
|
|
make_image
|
|
|
|
# Create the disk and partition it
|
|
echo "Creating image file ${imagename}.img"
|
|
parted -s ${current_dir}/${imagename}.img mklabel msdos
|
|
parted -s ${current_dir}/${imagename}.img mkpart primary fat32 4MiB ${bootsize}MiB
|
|
parted -s -a minimal ${current_dir}/${imagename}.img mkpart primary $fstype ${bootsize}MiB 100%
|
|
|
|
# Set the partition variables
|
|
loopdevice=$(losetup --show -fP "${current_dir}/${imagename}.img")
|
|
bootp="${loopdevice}p1"
|
|
rootp="${loopdevice}p2"
|
|
|
|
# Create file systems
|
|
log "Formating partitions" green
|
|
if [[ "$fstype" == "ext4" ]]; then
|
|
features="^64bit,^metadata_csum"
|
|
elif [[ "$fstype" == "ext3" ]]; then
|
|
features="^64bit"
|
|
fi
|
|
mkfs -O "$features" -t "$fstype" -L BOOT "${bootp}"
|
|
mkfs -O "$features" -t "$fstype" -L ROOTFS "${rootp}"
|
|
|
|
# Create the dirs for the partitions and mount them
|
|
mkdir -p "${basedir}"/root/
|
|
mount "${rootp}" "${basedir}"/root
|
|
mkdir -p "${basedir}"/root/boot
|
|
mount "${bootp}" "${basedir}"/root/boot
|
|
|
|
# We do this down here to get rid of the build system's resolv.conf after running through the build.
|
|
echo "nameserver ${nameserver}" >"${work_dir}"/etc/resolv.conf
|
|
|
|
# Create an fstab so that we don't mount / read-only.
|
|
UUID=$(blkid -s UUID -o value ${rootp})
|
|
echo "UUID=$UUID / $fstype errors=remount-ro 0 1" >> ${work_dir}/etc/fstab
|
|
|
|
log "Rsyncing rootfs into image file" green
|
|
rsync -HPavz -q "${work_dir}"/ "${basedir}"/root/
|
|
sync
|
|
|
|
# Write the signed u-boot binary to the image so that it will boot.
|
|
cd "${basedir}"
|
|
git clone https://github.com/hardkernel/u-boot.git -b odroidxu4-v2017.05
|
|
cd "${basedir}"/u-boot
|
|
make odroid-xu4_defconfig
|
|
make
|
|
cd sd_fuse
|
|
sh sd_fusing.sh ${loopdevice}
|
|
|
|
cd ${current_dir}
|
|
|
|
# Umount filesystem
|
|
umount -l "${rootp}"
|
|
|
|
# Check filesystem
|
|
e2fsck -y -f "$rootp"
|
|
|
|
# Remove loop devices
|
|
kpartx -dv "${loopdevice}"
|
|
losetup -d "${loopdevice}"
|
|
|
|
# Compress image compilation
|
|
include compress_img
|
|
|
|
# Clean up all the temporary build stuff and remove the directories.
|
|
# Comment this out to keep things around if you want to see what may have gone wrong.
|
|
clean_build
|