|
|
|
@ -6,6 +6,7 @@ set -o pipefail # Bashism
|
|
|
|
|
KALI_DIST="kali-rolling"
|
|
|
|
|
KALI_VERSION=""
|
|
|
|
|
KALI_VARIANT="default"
|
|
|
|
|
IMAGE_TYPE="live"
|
|
|
|
|
TARGET_DIR="$(dirname $0)/images"
|
|
|
|
|
TARGET_SUBDIR=""
|
|
|
|
|
SUDO="sudo"
|
|
|
|
@ -13,17 +14,34 @@ VERBOSE=""
|
|
|
|
|
HOST_ARCH=$(dpkg --print-architecture)
|
|
|
|
|
|
|
|
|
|
image_name() {
|
|
|
|
|
local arch=$1
|
|
|
|
|
case "$IMAGE_TYPE" in
|
|
|
|
|
live)
|
|
|
|
|
live_image_name
|
|
|
|
|
;;
|
|
|
|
|
installer)
|
|
|
|
|
installer_image_name
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case "$arch" in
|
|
|
|
|
live_image_name() {
|
|
|
|
|
case "$KALI_ARCH" in
|
|
|
|
|
i386|amd64)
|
|
|
|
|
IMAGE_TEMPLATE="live-image-ARCH.hybrid.iso"
|
|
|
|
|
echo "live-image-$KALI_ARCH.hybrid.iso"
|
|
|
|
|
;;
|
|
|
|
|
armel|armhf)
|
|
|
|
|
IMAGE_TEMPLATE="live-image-ARCH.img"
|
|
|
|
|
echo "live-image-$KALI_ARCH.img"
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
echo $IMAGE_TEMPLATE | sed -e "s/ARCH/$arch/"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
installer_image_name() {
|
|
|
|
|
if [ "$KALI_VARIANT" = "default" ]; then
|
|
|
|
|
echo "simple-cdd/images/kali-$KALI_VERSION-$KALI_ARCH-DVD-1.iso"
|
|
|
|
|
else
|
|
|
|
|
echo "simple-cdd/images/kali-$KALI_VERSION-$KALI_ARCH-NETINST-1.iso"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
target_image_name() {
|
|
|
|
@ -34,10 +52,18 @@ target_image_name() {
|
|
|
|
|
if [ "$IMAGE_EXT" = "$IMAGE_NAME" ]; then
|
|
|
|
|
IMAGE_EXT="img"
|
|
|
|
|
fi
|
|
|
|
|
if [ "$KALI_VARIANT" = "default" ]; then
|
|
|
|
|
echo "${TARGET_SUBDIR:+$TARGET_SUBDIR/}kali-linux-$KALI_VERSION-$KALI_ARCH.$IMAGE_EXT"
|
|
|
|
|
if [ "$IMAGE_TYPE" = "live" ]; then
|
|
|
|
|
if [ "$KALI_VARIANT" = "default" ]; then
|
|
|
|
|
echo "${TARGET_SUBDIR:+$TARGET_SUBDIR/}kali-linux-$KALI_VERSION-$KALI_ARCH.$IMAGE_EXT"
|
|
|
|
|
else
|
|
|
|
|
echo "${TARGET_SUBDIR:+$TARGET_SUBDIR/}kali-linux-$KALI_VERSION-$KALI_VARIANT-$KALI_ARCH.$IMAGE_EXT"
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
echo "${TARGET_SUBDIR:+$TARGET_SUBDIR/}kali-linux-$KALI_VERSION-$KALI_VARIANT-$KALI_ARCH.$IMAGE_EXT"
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -58,18 +84,15 @@ default_version() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
failure() {
|
|
|
|
|
# Cleanup update-kali-menu that might stay around so that the
|
|
|
|
|
# build chroot can be properly unmounted
|
|
|
|
|
$SUDO pkill -f update-kali-menu || true
|
|
|
|
|
echo "Build of $KALI_DIST/$KALI_VARIANT/$KALI_ARCH live image failed (see build.log for details)" >&2
|
|
|
|
|
echo "Build of $KALI_DIST/$KALI_VARIANT/$KALI_ARCH $IMAGE_TYPE image failed (see build.log for details)" >&2
|
|
|
|
|
exit 2
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
run_and_log() {
|
|
|
|
|
if [ -n "$VERBOSE" ]; then
|
|
|
|
|
"$@" 2>&1 | tee -a build.log
|
|
|
|
|
"$@" 2>&1 | tee -a $BUILD_LOG
|
|
|
|
|
else
|
|
|
|
|
"$@" >>build.log 2>&1
|
|
|
|
|
"$@" >>$BUILD_LOG 2>&1
|
|
|
|
|
fi
|
|
|
|
|
return $?
|
|
|
|
|
}
|
|
|
|
@ -77,7 +100,7 @@ run_and_log() {
|
|
|
|
|
. $(dirname $0)/.getopt.sh
|
|
|
|
|
|
|
|
|
|
# Parsing command line options
|
|
|
|
|
temp=$(getopt -o "$BUILD_OPTS_SHORT" -l "$BUILD_OPTS_LONG,get-image-path" -- "$@")
|
|
|
|
|
temp=$(getopt -o "$BUILD_OPTS_SHORT" -l "$BUILD_OPTS_LONG,get-image-path,installer,no-clean" -- "$@")
|
|
|
|
|
eval set -- "$temp"
|
|
|
|
|
while true; do
|
|
|
|
|
case "$1" in
|
|
|
|
@ -86,10 +109,12 @@ while true; do
|
|
|
|
|
-a|--arch) KALI_ARCH="$2"; shift 2; ;;
|
|
|
|
|
-v|--verbose) VERBOSE="1"; shift 1; ;;
|
|
|
|
|
-s|--salt) shift; ;;
|
|
|
|
|
--installer) IMAGE_TYPE="installer"; shift 1 ;;
|
|
|
|
|
--variant) KALI_VARIANT="$2"; shift 2; ;;
|
|
|
|
|
--version) KALI_VERSION="$2"; shift 2; ;;
|
|
|
|
|
--subdir) TARGET_SUBDIR="$2"; shift 2; ;;
|
|
|
|
|
--get-image-path) ACTION="get-image-path"; shift 1; ;;
|
|
|
|
|
--no-clean) NO_CLEAN="1"; shift 1 ;;
|
|
|
|
|
--) shift; break; ;;
|
|
|
|
|
*) echo "ERROR: Invalid command-line option: $1" >&2; exit 1; ;;
|
|
|
|
|
esac
|
|
|
|
@ -118,6 +143,7 @@ fi
|
|
|
|
|
|
|
|
|
|
# Build parameters for lb config
|
|
|
|
|
KALI_CONFIG_OPTS="--distribution $KALI_DIST -- --variant $KALI_VARIANT"
|
|
|
|
|
CODENAME=$KALI_DIST # for simple-cdd/debian-cd
|
|
|
|
|
if [ -n "$OPT_pu" ]; then
|
|
|
|
|
KALI_CONFIG_OPTS="$KALI_CONFIG_OPTS --proposed-updates"
|
|
|
|
|
KALI_DIST="$KALI_DIST+pu"
|
|
|
|
@ -126,24 +152,33 @@ fi
|
|
|
|
|
# Set sane PATH (cron seems to lack /sbin/ dirs)
|
|
|
|
|
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
|
|
|
|
|
|
|
|
|
# Either we use a git checkout of live-build
|
|
|
|
|
# export LIVE_BUILD=/srv/cdimage.kali.org/live/live-build
|
|
|
|
|
|
|
|
|
|
# Or we ensure we have proper version installed
|
|
|
|
|
ver_live_build=$(dpkg-query -f '${Version}' -W live-build)
|
|
|
|
|
if dpkg --compare-versions "$ver_live_build" lt 1:20151215kali1; then
|
|
|
|
|
echo "ERROR: You need live-build (>= 1:20151215kali1), you have $ver_live_build" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
case "$IMAGE_TYPE" in
|
|
|
|
|
live)
|
|
|
|
|
ver_live_build=$(dpkg-query -f '${Version}' -W live-build)
|
|
|
|
|
if dpkg --compare-versions "$ver_live_build" lt 1:20151215kali1; then
|
|
|
|
|
echo "ERROR: You need live-build (>= 1:20151215kali1), you have $ver_live_build" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
ver_debootstrap=$(dpkg-query -f '${Version}' -W debootstrap)
|
|
|
|
|
if dpkg --compare-versions "$ver_debootstrap" lt "1.0.97"; then
|
|
|
|
|
echo "ERROR: You need debootstrap (>= 1.0.97), you have $ver_debootstrap" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
;;
|
|
|
|
|
installer)
|
|
|
|
|
ver_debian_cd=$(dpkg-query -f '${Version}' -W debian-cd)
|
|
|
|
|
if dpkg --compare-versions "$ver_debian_cd" lt 3.1.28~kali1; then
|
|
|
|
|
echo "ERROR: You need debian-cd (>= 3.1.28~kali1), you have $ver_debian_cd" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
ver_simple_cdd=$(dpkg-query -f '${Version}' -W simple-cdd)
|
|
|
|
|
if dpkg --compare-versions "$ver_simple_cdd" lt 0.6.8~kali1; then
|
|
|
|
|
echo "ERROR: You need simple-cdd (>= 0.6.8~kali1), you have $ver_simple_cdd" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Check we have a good debootstrap
|
|
|
|
|
ver_debootstrap=$(dpkg-query -f '${Version}' -W debootstrap)
|
|
|
|
|
if dpkg --compare-versions "$ver_debootstrap" lt "1.0.97"; then
|
|
|
|
|
if ! echo "$ver_debootstrap" | grep -q kali; then
|
|
|
|
|
echo "ERROR: You need debootstrap >= 1.0.97 (or a Kali patched debootstrap). Your current version: $ver_debootstrap" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
# We need root rights at some point
|
|
|
|
|
if [ "$(whoami)" != "root" ]; then
|
|
|
|
@ -165,15 +200,67 @@ mkdir -p $TARGET_DIR/$TARGET_SUBDIR
|
|
|
|
|
|
|
|
|
|
IMAGE_NAME="$(image_name $KALI_ARCH)"
|
|
|
|
|
set +e
|
|
|
|
|
: > build.log
|
|
|
|
|
run_and_log $SUDO lb clean --purge
|
|
|
|
|
[ $? -eq 0 ] || failure
|
|
|
|
|
run_and_log lb config -a $KALI_ARCH $KALI_CONFIG_OPTS "$@"
|
|
|
|
|
[ $? -eq 0 ] || failure
|
|
|
|
|
run_and_log $SUDO lb build
|
|
|
|
|
if [ $? -ne 0 ] || [ ! -e $IMAGE_NAME ]; then
|
|
|
|
|
failure
|
|
|
|
|
fi
|
|
|
|
|
BUILD_LOG=$(pwd)/build.log
|
|
|
|
|
: > $BUILD_LOG
|
|
|
|
|
|
|
|
|
|
case "$IMAGE_TYPE" in
|
|
|
|
|
live)
|
|
|
|
|
if [ "$NO_CLEAN" = "" ]; then
|
|
|
|
|
run_and_log $SUDO lb clean --purge
|
|
|
|
|
fi
|
|
|
|
|
[ $? -eq 0 ] || failure
|
|
|
|
|
run_and_log lb config -a $KALI_ARCH $KALI_CONFIG_OPTS "$@"
|
|
|
|
|
[ $? -eq 0 ] || failure
|
|
|
|
|
run_and_log $SUDO lb build
|
|
|
|
|
if [ $? -ne 0 ] || [ ! -e $IMAGE_NAME ]; then
|
|
|
|
|
failure
|
|
|
|
|
fi
|
|
|
|
|
;;
|
|
|
|
|
installer)
|
|
|
|
|
if [ "$NO_CLEAN" = "" ]; then
|
|
|
|
|
run_and_log $SUDO rm -rf simple-cdd/tmp
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Override some debian-cd environment variables
|
|
|
|
|
export ARCHES=$KALI_ARCH
|
|
|
|
|
export ARCH=$KALI_ARCH
|
|
|
|
|
export DEBVERSION=$KALI_VERSION
|
|
|
|
|
|
|
|
|
|
if [ "$KALI_VARIANT" = "netinst" ]; then
|
|
|
|
|
export DISKTYPE="NETINST"
|
|
|
|
|
else
|
|
|
|
|
export DISKTYPE="DVD"
|
|
|
|
|
fi
|
|
|
|
|
if [ -e .mirror ]; then
|
|
|
|
|
kali_mirror=$(cat .mirror)
|
|
|
|
|
else
|
|
|
|
|
kali_mirror=http://archive.kali.org/kali/
|
|
|
|
|
fi
|
|
|
|
|
if ! echo "$kali_mirror" | grep -q '/$'; then
|
|
|
|
|
kali_mirror="$kali_mirror/"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Configure the kali profile with the packages we want
|
|
|
|
|
grep -v '^#' kali-config/variant-$KALI_VARIANT/package-lists/kali.list.chroot \
|
|
|
|
|
>simple-cdd/profiles/kali.downloads
|
|
|
|
|
|
|
|
|
|
# Run simple-cdd
|
|
|
|
|
cd simple-cdd
|
|
|
|
|
run_and_log build-simple-cdd \
|
|
|
|
|
--verbose \
|
|
|
|
|
--debug \
|
|
|
|
|
--force-root \
|
|
|
|
|
--conf simple-cdd.conf \
|
|
|
|
|
--dist $CODENAME \
|
|
|
|
|
--debian-mirror $kali_mirror
|
|
|
|
|
res=$?
|
|
|
|
|
cd ..
|
|
|
|
|
if [ $res -ne 0 ] || [ ! -e $IMAGE_NAME ]; then
|
|
|
|
|
failure
|
|
|
|
|
fi
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
mv -f $IMAGE_NAME $TARGET_DIR/$(target_image_name $KALI_ARCH)
|
|
|
|
|
mv -f build.log $TARGET_DIR/$(target_build_log $KALI_ARCH)
|
|
|
|
|
mv -f $BUILD_LOG $TARGET_DIR/$(target_build_log $KALI_ARCH)
|
|
|
|
|