#!/bin/bash # If a command fails, make the whole script exit set -e # Use return code for any command errors in part of a pipe set -o pipefail # Bashism # Kali's default values KALI_DIST="kali-rolling" KALI_VERSION="" KALI_VARIANT="default" IMAGE_TYPE="live" TARGET_DIR="$(dirname $0)/images" TARGET_SUBDIR="" SUDO="sudo" VERBOSE="" DEBUG="" HOST_ARCH=$(dpkg --print-architecture) image_name() { case "$IMAGE_TYPE" in live) live_image_name ;; installer) installer_image_name ;; esac } live_image_name() { case "$KALI_ARCH" in i386|amd64|arm64) echo "live-image-$KALI_ARCH.hybrid.iso" ;; armel|armhf) echo "live-image-$KALI_ARCH.img" ;; esac } installer_image_name() { if [ "$KALI_VARIANT" = "netinst" ]; then echo "simple-cdd/images/kali-$KALI_VERSION-$KALI_ARCH-NETINST-1.iso" else echo "simple-cdd/images/kali-$KALI_VERSION-$KALI_ARCH-BD-1.iso" fi } target_image_name() { local arch=$1 IMAGE_NAME="$(image_name $arch)" IMAGE_EXT="${IMAGE_NAME##*.}" if [ "$IMAGE_EXT" = "$IMAGE_NAME" ]; then IMAGE_EXT="img" fi if [ "$IMAGE_TYPE" = "live" ]; then if [ "$KALI_VARIANT" = "default" ]; then echo "${TARGET_SUBDIR:+$TARGET_SUBDIR/}kali-linux-$KALI_VERSION-live-$KALI_ARCH.$IMAGE_EXT" else echo "${TARGET_SUBDIR:+$TARGET_SUBDIR/}kali-linux-$KALI_VERSION-live-$KALI_VARIANT-$KALI_ARCH.$IMAGE_EXT" fi else if [ "$KALI_VARIANT" = "default" ]; then echo "${TARGET_SUBDIR:+$TARGET_SUBDIR/}kali-linux-$KALI_VERSION-installer-$KALI_ARCH.$IMAGE_EXT" else echo "${TARGET_SUBDIR:+$TARGET_SUBDIR/}kali-linux-$KALI_VERSION-installer-$KALI_VARIANT-$KALI_ARCH.$IMAGE_EXT" fi fi } target_build_log() { TARGET_IMAGE_NAME=$(target_image_name $1) echo ${TARGET_IMAGE_NAME%.*}.log } default_version() { case "$1" in kali-*) echo "${1#kali-}" ;; *) echo "$1" ;; esac } failure() { echo "Build of $KALI_DIST/$KALI_VARIANT/$KALI_ARCH $IMAGE_TYPE image failed (see build.log for details)" >&2 echo "Log: $BUILD_LOG" >&2 exit 2 } run_and_log() { if [ -n "$VERBOSE" ] || [ -n "$DEBUG" ]; then echo "RUNNING: $@" >&2 "$@" 2>&1 | tee -a "$BUILD_LOG" else "$@" >>"$BUILD_LOG" 2>&1 fi return $? } debug() { if [ -n "$DEBUG" ]; then echo "DEBUG: $*" >&2 fi } clean() { debug "Cleaning" # Live run_and_log $SUDO lb clean --purge #run_and_log $SUDO umount -l $(pwd)/chroot/proc #run_and_log $SUDO umount -l $(pwd)/chroot/dev/pts #run_and_log $SUDO umount -l $(pwd)/chroot/sys #run_and_log $SUDO rm -rf $(pwd)/chroot #run_and_log $SUDO rm -rf $(pwd)/binary # Installer run_and_log $SUDO rm -rf "$(pwd)/simple-cdd/tmp" run_and_log $SUDO rm -rf "$(pwd)/simple-cdd/debian-cd" } print_help() { echo "Usage: $0 [