Files
arm-kali/raspberry-pi.sh

112 lines
3.1 KiB
Bash
Raw Permalink Normal View History

2021-09-16 06:42:05 +01:00
#!/usr/bin/env bash
#
# Kali Linux ARM build-script for Raspberry Pi 2/3/4/400 (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-2/
#
2021-08-30 15:11:28 -05:00
# Hardware model
hw_model=${hw_model:-"raspberry-pi"}
2022-08-22 23:02:18 +03:00
2020-07-20 17:05:34 -05:00
# Architecture
architecture=${architecture:-"armhf"}
2022-08-22 23:02:18 +03:00
2021-08-30 15:11:28 -05:00
# Desktop manager (xfce, gnome, i3, kde, lxde, mate, e17 or none)
desktop=${desktop:-"xfce"}
# Load default base_image configs
source ./common.d/base_image.sh
2021-08-30 15:11:28 -05:00
# Network configs
2021-11-06 15:45:57 +01:00
basic_network
2021-08-30 15:11:28 -05:00
add_interface eth0
2020-07-20 17:05:34 -05:00
# Third stage
cat <<EOF >> "${work_dir}"/third-stage
status_stage3 'Copy rpi services'
2020-07-26 22:59:48 -05:00
cp -p /bsp/services/rpi/*.service /etc/systemd/system/
2020-07-20 17:05:34 -05:00
2021-09-19 10:56:45 +01:00
status_stage3 'Script mode wlan monitor START/STOP'
2022-01-27 18:51:18 +00:00
install -m755 /bsp/scripts/{monstart,monstop} /usr/bin/
2020-07-20 17:05:34 -05:00
2021-09-19 10:56:45 +01:00
status_stage3 'Install the kernel packages'
2021-08-30 15:11:28 -05:00
echo "deb http://http.re4son-kernel.com/re4son kali-pi main" > /etc/apt/sources.list.d/re4son.list
wget -O /etc/apt/trusted.gpg.d/kali_pi-archive-keyring.gpg https://re4son-kernel.com/keys/http/kali_pi-archive-keyring.gpg
2021-08-30 15:11:28 -05:00
eatmydata apt-get update
eatmydata apt-get install -y ${re4son_pkgs}
2021-09-19 10:56:45 +01:00
status_stage3 'Copy script for handling wpa_supplicant file'
install -m755 /bsp/scripts/copy-user-wpasupplicant.sh /usr/bin/
2021-09-19 10:56:45 +01:00
status_stage3 'Enable copying of user wpa_supplicant.conf file'
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'
systemctl enable enable-ssh
2018-06-20 10:37:31 -04:00
2021-09-19 10:56:45 +01:00
status_stage3 'Disable haveged daemon'
systemctl disable haveged
status_stage3 'Fixup wireless-regdb signature'
update-alternatives --set regulatory.db /lib/firmware/regulatory.db-upstream
status_stage3 'Enable hciuart and bluetooth'
systemctl enable hciuart
systemctl enable bluetooth
EOF
2020-07-20 17:05:34 -05:00
# Run third stage
include third_stage
2020-07-20 17:05:34 -05:00
# Clean system
2021-08-30 15:11:28 -05:00
include clean_system
2021-09-16 06:58:38 +01:00
# Calculate the space to create the image and create
2021-08-30 15:11:28 -05:00
make_image
# 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%
# Set the partition variables
2021-11-07 10:55:31 +01:00
make_loop
2022-08-22 23:02:18 +03:00
# Create file systems
2021-11-07 10:55:31 +01:00
mkfs_partitions
2022-08-22 23:02:18 +03:00
2022-01-27 18:51:18 +00:00
# Make fstab
2021-11-04 15:55:40 +01:00
make_fstab
2022-08-22 23:02:18 +03:00
2022-01-27 18:51:18 +00:00
# Configure Raspberry Pi firmware (before rsync)
2021-11-04 15:55:40 +01:00
include rpi_firmware
# 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"
mkdir -p "${base_dir}"/root/
2022-08-22 23:02:18 +03:00
if [[ $fstype == ext4 ]]; then
2022-08-22 23:02:18 +03:00
mount -t ext4 -o noatime,data=writeback,barrier=0 "${rootp}" "${base_dir}"/root
else
2022-08-22 23:02:18 +03:00
mount "${rootp}" "${base_dir}"/root
fi
2022-08-22 23:02:18 +03:00
mkdir -p "${base_dir}"/root/boot
mount "${bootp}" "${base_dir}"/root/boot
2021-08-30 15:11:28 -05:00
2021-09-19 10:56:45 +01:00
status "Rsyncing rootfs into image file"
rsync -HPavz -q --exclude boot "${work_dir}"/ "${base_dir}"/root/
sync
2022-01-27 18:51:18 +00:00
status "Rsyncing boot into image file (/boot)"
rsync -rtx -q "${work_dir}"/boot "${base_dir}"/root
2020-07-20 17:05:34 -05:00
sync
# Load default finish_image configs
include finish_image