#!/usr/bin/env bash # # Kali Linux ARM build-script for Banana Pi (32-bit) # https://gitlab.com/kalilinux/build-scripts/kali-arm # # This is a supported device - which you can find pre-generated images for # More information: https://www.kali.org/docs/arm/banana-pi/ # # Stop on error set -e # shellcheck disable=SC2154 # Load general functions # shellcheck source=/dev/null source ./common.d/functions.sh # Hardware model hw_model=${hw_model:-"banana-pi"} # 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 environment 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 log "Copy directory bsp into build dir" green cp -rp bsp "${work_dir}" # Third stage cat <"${work_dir}"/third-stage #!/usr/bin/env bash set -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/ cp -p /bsp/services/rpi/*.service /etc/systemd/system/ # Install the kernel packages eatmydata apt-get install -y linux-image-armmp u-boot-menu u-boot-sunxi # Regenerated the shared-mime-info database on the first boot # since it fails to do so properly in a chroot systemctl enable smi-hack # 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 # Enable copying of user wpa_supplicant.conf file systemctl enable copy-user-wpasupplicant # Enable... enabling ssh by putting ssh or ssh.txt file in /boot systemctl enable enable-ssh # 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 ttyAMA0 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" # 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 0755 "${work_dir}"/third-stage log "Run third stage" green 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 8.8.8.8" >"${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 # Create an fstab so that we don't mount / read-only log "/etc/fstab" green UUID=$(blkid -s UUID -o value ${rootp}) echo "UUID=$UUID / $fstype errors=remount-ro 0 1" >> ${work_dir}/etc/fstab # Calculate the space to create the image and create make_image # Enable the serial console log "serial console" green echo "T1:12345:respawn:/sbin/agetty -L ttyS0 115200 vt100" >> ${work_dir}/etc/inittab # Load the ethernet module since it doesn't load automatically at boot echo "sunxi_emac" >> ${work_dir}/etc/modules mkdir -p ${work_dir}/etc/X11/xorg.conf.d/ cp "${basedir}"/../bsp/xorg/20-fbdev.conf ${work_dir}/etc/X11/xorg.conf.d/ # Build system will insert it's root filesystem into the extlinux.conf file so # we sed it out, this only affects build time, not upgrading the kernel on the # device itself sed -i -e 's/append.*/append console=ttyS0,115200 console=tty1 root=\/dev\/mmcblk0p1 rootwait panic=10 rw rootfstype=$fstype net.ifnames=0/g' ${work_dir}/boot/extlinux/extlinux.conf parted -s ${current_dir}/${imagename}.img mklabel msdos parted -s -a minimal ${current_dir}/${imagename}.img mkpart primary $fstype 4MiB 100% # Set the partition variables loopdevice=$(losetup -f --show ${current_dir}/${imagename}.img) device=$(kpartx -va ${loopdevice} | sed 's/.*\(loop[0-9]\+\)p.*/\1/g' | head -1) sleep 5 device="/dev/mapper/${device}" rootp=${device}p1 if [[ $fstype == ext4 ]]; then features="-O ^64bit,^metadata_csum" elif [[ $fstype == ext3 ]]; then features="-O ^64bit" fi mkfs -O "$features" -t "$fstype" -L ROOTFS "${rootp}" # Create the dirs for the partitions and mount them log "Create the dirs for the partitions and mount them" green mkdir -p ${basedir}/root mount ${rootp} ${basedir}/root # Create an fstab so that we don't mount / read-only log "/etc/fstab" green UUID=$(blkid -s UUID -o value ${rootp}) echo "UUID=$UUID / $fstype errors=remount-ro 0 1" >> ${work_dir}/etc/fstab echo "Rsyncing rootfs to image file" rsync -HPavz -q ${work_dir}/ ${basedir}/root/ sync # Umount filesystem log "Umount filesystem" green umount -l ${rootp} dd if=${work_dir}/usr/lib/u-boot/Bananapi/u-boot-sunxi-with-spl.bin of=${loopdevice} bs=1024 seek=8 e2fsck -y -f "$rootp" # Remove loop devices log "Remove loop devices" green 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