2021-09-16 06:42:05 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
#
|
|
|
|
|
# Kali Linux ARM build-script for Raspberry Pi Zero W (32-bit)
|
2021-10-12 22:10:32 +01:00
|
|
|
# Source: https://gitlab.com/kalilinux/build-scripts/kali-arm
|
2021-09-16 06:42:05 +01:00
|
|
|
#
|
2021-10-12 22:10:32 +01:00
|
|
|
# This is a supported device - which you can find pre-generated images on: https://www.kali.org/get-kali/
|
2021-09-16 06:42:05 +01:00
|
|
|
# More information: https://www.kali.org/docs/arm/raspberry-pi-zero-w/
|
|
|
|
|
#
|
|
|
|
|
|
2021-08-30 15:12:17 -05:00
|
|
|
# Hardware model
|
|
|
|
|
hw_model=${hw_model:-"rpi0w"}
|
2020-07-20 23:23:08 -05:00
|
|
|
# Architecture
|
|
|
|
|
architecture=${architecture:-"armel"}
|
2021-08-30 15:12:17 -05:00
|
|
|
# Variant name for image and dir build
|
2021-09-16 19:53:57 +01:00
|
|
|
variant=${variant:-"${architecture}"}
|
2021-08-30 15:12:17 -05:00
|
|
|
# Desktop manager (xfce, gnome, i3, kde, lxde, mate, e17 or none)
|
|
|
|
|
desktop=${desktop:-"xfce"}
|
|
|
|
|
|
2021-10-12 20:56:41 +00:00
|
|
|
# Load default base_image configs
|
|
|
|
|
source ./common.d/base_image.sh
|
2018-07-02 02:00:44 -05:00
|
|
|
|
2021-08-30 15:12:17 -05:00
|
|
|
# Third stage
|
2021-10-12 20:56:41 +00:00
|
|
|
cat <<EOF >> "${work_dir}"/third-stage
|
|
|
|
|
status_stage3 'Copy rpi services'
|
2021-08-30 15:12:17 -05:00
|
|
|
cp -p /bsp/services/rpi/*.service /etc/systemd/system/
|
|
|
|
|
|
2021-09-19 10:56:45 +01:00
|
|
|
status_stage3 'Script mode wlan monitor START/STOP'
|
2020-07-20 23:23:08 -05:00
|
|
|
install -m755 /bsp/scripts/monstart /usr/bin/
|
|
|
|
|
install -m755 /bsp/scripts/monstop /usr/bin/
|
2017-03-12 16:24:00 -05:00
|
|
|
|
2021-09-19 10:56:45 +01:00
|
|
|
status_stage3 'Install the kernel packages'
|
2019-01-30 18:46:21 -06:00
|
|
|
echo "deb http://http.re4son-kernel.com/re4son kali-pi main" > /etc/apt/sources.list.d/re4son.list
|
2021-08-30 15:12:17 -05:00
|
|
|
wget -qO /etc/apt/trusted.gpg.d/kali_pi-archive-keyring.gpg https://re4son-kernel.com/keys/http/kali_pi-archive-keyring.gpg
|
2020-08-02 00:14:21 -05:00
|
|
|
eatmydata apt-get update
|
2021-09-19 20:35:16 -05:00
|
|
|
eatmydata apt-get install -y ${re4son_pkgs}
|
2020-07-24 12:31:34 -05:00
|
|
|
|
2021-09-19 10:56:45 +01:00
|
|
|
status_stage3 'Copy script for handling wpa_supplicant file'
|
2021-09-06 21:04:54 -05:00
|
|
|
install -m755 /bsp/scripts/copy-user-wpasupplicant.sh /usr/bin/
|
2019-05-07 12:59:11 -05:00
|
|
|
|
2021-09-19 10:56:45 +01:00
|
|
|
status_stage3 'Enable copying of user wpa_supplicant.conf file'
|
2018-07-12 06:05:39 -05:00
|
|
|
systemctl enable copy-user-wpasupplicant
|
|
|
|
|
|
2021-09-19 10:56:45 +01:00
|
|
|
status_stage3 'Enabling ssh by putting ssh or ssh.txt file in /boot'
|
2018-07-12 06:05:39 -05:00
|
|
|
systemctl enable enable-ssh
|
|
|
|
|
|
2021-09-19 10:56:45 +01:00
|
|
|
status_stage3 'Disable haveged daemon'
|
2021-09-10 09:19:47 -05:00
|
|
|
systemctl disable haveged
|
|
|
|
|
|
2021-10-12 20:56:41 +00:00
|
|
|
status_stage3 'Enable login over serial (No password)'
|
|
|
|
|
echo "T0:23:respawn:/sbin/agetty -L ttyAMA0 115200 vt100" >> /etc/inittab
|
2017-03-12 16:24:00 -05:00
|
|
|
EOF
|
|
|
|
|
|
2020-07-20 23:23:08 -05:00
|
|
|
# Run third stage
|
2021-10-12 20:56:41 +00:00
|
|
|
include third_stage
|
2017-03-12 16:24:00 -05:00
|
|
|
|
2021-10-12 20:56:41 +00:00
|
|
|
# Configure Raspberry Pi firmware
|
2021-09-09 13:34:16 -05:00
|
|
|
include rpi_firmware
|
2021-10-12 20:56:41 +00:00
|
|
|
|
2020-07-20 23:23:08 -05:00
|
|
|
# Clean system
|
2021-08-30 15:12:17 -05:00
|
|
|
include clean_system
|
2021-09-17 16:47:51 +01:00
|
|
|
trap clean_build ERR SIGTERM SIGINT
|
2020-07-26 14:38:21 -05:00
|
|
|
|
2021-09-16 06:58:38 +01:00
|
|
|
# systemd doesn't seem to be generating the fstab properly for some people, so let's create one
|
2021-09-19 10:56:45 +01:00
|
|
|
status "/etc/fstab"
|
2021-09-19 20:03:59 +01:00
|
|
|
cat <<EOF > "${work_dir}"/etc/fstab
|
2017-03-12 16:24:00 -05:00
|
|
|
# <file system> <mount point> <type> <options> <dump> <pass>
|
|
|
|
|
proc /proc proc defaults 0 0
|
2021-09-21 09:58:18 -05:00
|
|
|
LABEL=BOOT /boot vfat defaults 0 2
|
2017-03-12 16:24:00 -05:00
|
|
|
EOF
|
|
|
|
|
|
2021-09-16 06:58:38 +01:00
|
|
|
# Calculate the space to create the image and create
|
2021-08-30 15:12:17 -05:00
|
|
|
make_image
|
2018-07-09 21:43:04 -05:00
|
|
|
|
2021-09-17 16:02:12 +01:00
|
|
|
# Create the disk partitions
|
2021-09-19 10:56:45 +01:00
|
|
|
status "Create the disk partitions"
|
2021-09-19 13:45:29 +01:00
|
|
|
parted -s "${image_dir}/${image_name}.img" mklabel msdos
|
|
|
|
|
parted -s "${image_dir}/${image_name}.img" mkpart primary fat32 1MiB "${bootsize}"MiB
|
|
|
|
|
parted -s -a minimal "${image_dir}/${image_name}.img" mkpart primary "$fstype" "${bootsize}"MiB 100%
|
2018-06-28 17:02:30 -05:00
|
|
|
|
|
|
|
|
# Set the partition variables
|
2021-09-19 13:45:29 +01:00
|
|
|
loopdevice=$(losetup --show -fP "${image_dir}/${image_name}.img")
|
2020-07-24 10:58:35 -05:00
|
|
|
bootp="${loopdevice}p1"
|
|
|
|
|
rootp="${loopdevice}p2"
|
2018-06-28 17:02:30 -05:00
|
|
|
|
|
|
|
|
# Create file systems
|
2021-09-19 10:56:45 +01:00
|
|
|
status "Formatting partitions"
|
2021-08-30 15:12:17 -05:00
|
|
|
mkfs.vfat -n BOOT -F 32 "${bootp}"
|
|
|
|
|
if [[ "$fstype" == "ext4" ]]; then
|
|
|
|
|
features="^64bit,^metadata_csum"
|
|
|
|
|
elif [[ "$fstype" == "ext3" ]]; then
|
|
|
|
|
features="^64bit"
|
2020-07-26 14:38:21 -05:00
|
|
|
fi
|
2021-08-30 15:12:17 -05:00
|
|
|
mkfs -O "$features" -t "$fstype" -L ROOTFS "${rootp}"
|
2018-06-28 17:02:30 -05:00
|
|
|
|
|
|
|
|
# Create the dirs for the partitions and mount them
|
2021-09-19 10:56:45 +01:00
|
|
|
status "Create the dirs for the partitions and mount them"
|
2021-09-19 10:11:39 +01:00
|
|
|
mkdir -p "${base_dir}"/root/
|
|
|
|
|
mount "${rootp}" "${base_dir}"/root
|
|
|
|
|
mkdir -p "${base_dir}"/root/boot
|
|
|
|
|
mount "${bootp}" "${base_dir}"/root/boot
|
2021-08-30 15:12:17 -05:00
|
|
|
|
2021-09-21 09:58:18 -05:00
|
|
|
# Create an fstab so that we don't mount / read-only
|
|
|
|
|
status "/etc/fstab"
|
|
|
|
|
UUID=$(blkid -s UUID -o value ${rootp})
|
|
|
|
|
echo "UUID=$UUID / $fstype errors=remount-ro 0 1" >> ${work_dir}/etc/fstab
|
|
|
|
|
|
2021-09-19 10:56:45 +01:00
|
|
|
status "Rsyncing rootfs into image file"
|
2021-09-19 10:11:39 +01:00
|
|
|
rsync -HPavz -q --exclude boot "${work_dir}"/ "${base_dir}"/root/
|
2021-10-12 20:56:41 +00:00
|
|
|
sync
|
|
|
|
|
|
2021-09-19 10:56:45 +01:00
|
|
|
status "Rsyncing rootfs into image file (/boot)"
|
2021-09-19 10:11:39 +01:00
|
|
|
rsync -rtx -q "${work_dir}"/boot "${base_dir}"/root
|
2020-07-20 23:23:08 -05:00
|
|
|
sync
|
2017-09-20 16:46:48 -05:00
|
|
|
|
2021-10-12 20:56:41 +00:00
|
|
|
# Load default finish_image configs
|
|
|
|
|
include finish_image
|