Update and fix bash syntax of archived scripts
This commit is contained in:
@@ -9,26 +9,31 @@
|
||||
|
||||
echo "This script is now deprecated" >&2
|
||||
echo "The kernel is too old to run systemd" >&2
|
||||
|
||||
sleep 5s
|
||||
|
||||
set -e
|
||||
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
echo "This script must be run as root"
|
||||
exit 1
|
||||
echo "This script must be run as root"
|
||||
exit 1
|
||||
|
||||
fi
|
||||
|
||||
if [[ $# -eq 0 ]] ; then
|
||||
if [[ $# -eq 0 ]]; then
|
||||
echo "Please pass version number, e.g. $0 1.0.1"
|
||||
exit 0
|
||||
|
||||
fi
|
||||
|
||||
basedir=`pwd`/efikamx-$1
|
||||
basedir=$(pwd)/efikamx-$1
|
||||
|
||||
# Custom hostname variable
|
||||
hostname=${2:-kali}
|
||||
|
||||
# Custom image file name variable - MUST NOT include .img at the end.
|
||||
imagename=${3:-kali-linux-$1-efikamx}
|
||||
|
||||
# Size of image in megabytes (Default is 7000=7GB)
|
||||
size=7000
|
||||
|
||||
@@ -38,10 +43,12 @@ machine=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1)
|
||||
# Make sure that the cross compiler can be found in the path before we do
|
||||
# anything else, that way the builds don't fail half way through.
|
||||
export CROSS_COMPILE=arm-linux-gnueabihf-
|
||||
if [ $(compgen -c $CROSS_COMPILE | wc -l) -eq 0 ] ; then
|
||||
if [ $(compgen -c $CROSS_COMPILE | wc -l) -eq 0 ]; then
|
||||
echo "Missing cross compiler. Set up PATH according to the README"
|
||||
exit 1
|
||||
|
||||
fi
|
||||
|
||||
# Unset CROSS_COMPILE so that if there is any native compiling needed it doesn't
|
||||
# get cross compiled.
|
||||
unset CROSS_COMPILE
|
||||
@@ -64,6 +71,7 @@ extras="iceweasel wpasupplicant"
|
||||
|
||||
export packages="${arm} ${base} ${services} ${extras}"
|
||||
export architecture="armhf"
|
||||
|
||||
# If you have your own preferred mirrors, set them here.
|
||||
# You may want to leave security.kali.org alone, but if you trust your local
|
||||
# mirror, feel free to change this as well.
|
||||
@@ -86,15 +94,15 @@ cp /usr/bin/qemu-arm-static kali-${architecture}/usr/bin/
|
||||
LANG=C systemd-nspawn -M ${machine} -D kali-${architecture} /debootstrap/debootstrap --second-stage
|
||||
|
||||
mkdir -p kali-${architecture}/etc/apt/
|
||||
cat << EOF > kali-${architecture}/etc/apt/sources.list
|
||||
|
||||
cat <<EOF >kali-${architecture}/etc/apt/sources.list
|
||||
deb http://${mirror}/kali moto main contrib non-free
|
||||
EOF
|
||||
|
||||
|
||||
echo "${hostname}" > kali-${architecture}/etc/hostname
|
||||
echo "${hostname}" >kali-${architecture}/etc/hostname
|
||||
|
||||
# So X doesn't complain, we add kali to hosts
|
||||
cat << EOF > kali-${architecture}/etc/hosts
|
||||
cat <<EOF >kali-${architecture}/etc/hosts
|
||||
127.0.0.1 ${hostname} localhost
|
||||
::1 localhost ip6-localhost ip6-loopback
|
||||
fe00::0 ip6-localnet
|
||||
@@ -104,7 +112,8 @@ ff02::2 ip6-allrouters
|
||||
EOF
|
||||
|
||||
mkdir -p kali-${architecture}/etc/network/
|
||||
cat << EOF > kali-${architecture}/etc/network/interfaces
|
||||
|
||||
cat <<EOF >kali-${architecture}/etc/network/interfaces
|
||||
auto lo
|
||||
iface lo inet loopback
|
||||
|
||||
@@ -112,7 +121,7 @@ auto eth0
|
||||
iface eth0 inet dhcp
|
||||
EOF
|
||||
|
||||
cat << EOF > kali-${architecture}/etc/resolv.conf
|
||||
cat <<EOF >kali-${architecture}/etc/resolv.conf
|
||||
nameserver 8.8.8.8
|
||||
EOF
|
||||
|
||||
@@ -124,12 +133,12 @@ export DEBIAN_FRONTEND=noninteractive
|
||||
#mount -o bind /dev/ kali-${architecture}/dev/
|
||||
#mount -o bind /dev/pts kali-${architecture}/dev/pts
|
||||
|
||||
cat << EOF > kali-${architecture}/debconf.set
|
||||
cat <<EOF >kali-${architecture}/debconf.set
|
||||
console-common console-data/keymap/policy select Select keymap from full list
|
||||
console-common console-data/keymap/full select en-latin1-nodeadkeys
|
||||
EOF
|
||||
|
||||
cat << EOF > kali-${architecture}/third-stage
|
||||
cat <<EOF >kali-${architecture}/third-stage
|
||||
#!/bin/bash
|
||||
set -e
|
||||
dpkg-divert --add --local --divert /usr/sbin/invoke-rc.d.chroot --rename /usr/sbin/invoke-rc.d
|
||||
@@ -167,9 +176,10 @@ rm -f /third-stage
|
||||
EOF
|
||||
|
||||
chmod 755 kali-${architecture}/third-stage
|
||||
|
||||
LANG=C systemd-nspawn -M ${machine} -D kali-${architecture} /third-stage
|
||||
|
||||
cat << EOF > kali-${architecture}/cleanup
|
||||
cat <<EOF >kali-${architecture}/cleanup
|
||||
#!/bin/bash
|
||||
rm -rf /root/.bash_history
|
||||
apt-get update
|
||||
@@ -183,6 +193,7 @@ rm -f /usr/bin/qemu*
|
||||
EOF
|
||||
|
||||
chmod 755 kali-${architecture}/cleanup
|
||||
|
||||
LANG=C systemd-nspawn -M ${machine} -D kali-${architecture} /cleanup
|
||||
|
||||
#umount kali-${architecture}/proc/sys/fs/binfmt_misc
|
||||
@@ -198,11 +209,11 @@ LANG=C systemd-nspawn -M ${machine} -D kali-${architecture} /cleanup
|
||||
echo 'T1:12345:respawn:/sbin/agetty 115200 ttymxc0 vt100' >> \
|
||||
"${basedir}"/kali-${architecture}/etc/inittab
|
||||
|
||||
cat << EOF >> "${basedir}"/kali-${architecture}/etc/udev/links.conf
|
||||
cat <<EOF >>"${basedir}"/kali-${architecture}/etc/udev/links.conf
|
||||
M ttymxc0 c 5 1
|
||||
EOF
|
||||
|
||||
cat << EOF >> "${basedir}"/kali-${architecture}/etc/securetty
|
||||
cat <<EOF >>"${basedir}"/kali-${architecture}/etc/securetty
|
||||
ttymxc0
|
||||
EOF
|
||||
|
||||
@@ -211,7 +222,7 @@ EOF
|
||||
# udev won't start and we have no devices, including keyboard/usb support.
|
||||
sed -i -e "s/2.6.3\[0-1\]/2.6.30/g" "${basedir}"/kali-${architecture}/etc/init.d/udev
|
||||
|
||||
cat << EOF > "${basedir}"/kali-${architecture}/etc/apt/sources.list
|
||||
cat <<EOF >"${basedir}"/kali-${architecture}/etc/apt/sources.list
|
||||
deb http://old.kali.org/kali moto main non-free contrib
|
||||
deb-src http://old.kali.org/kali moto main non-free contrib
|
||||
EOF
|
||||
@@ -222,19 +233,26 @@ EOF
|
||||
# Kernel section. If you want to use a custom kernel, or configuration, replace
|
||||
# them in this section.
|
||||
git clone --depth 1 https://github.com/genesi/linux-legacy "${basedir}"/kali-${architecture}/usr/src/kernel
|
||||
|
||||
cd "${basedir}"/kali-${architecture}/usr/src/kernel
|
||||
|
||||
touch .scmversion
|
||||
|
||||
export ARCH=arm
|
||||
export CROSS_COMPILE=arm-linux-gnueabihf-
|
||||
patch -p1 --no-backup-if-mismatch < "${basedir}"/../patches/mac80211.patch
|
||||
|
||||
patch -p1 --no-backup-if-mismatch <"${basedir}"/../patches/mac80211.patch
|
||||
|
||||
make mx51_efikamx_defconfig
|
||||
make -j $(grep -c processor /proc/cpuinfo) uImage modules
|
||||
make modules_install INSTALL_MOD_PATH="${basedir}"/kali-${architecture}
|
||||
|
||||
cp arch/arm/boot/uImage "${basedir}"/kali-${architecture}/boot
|
||||
|
||||
cd "${basedir}"
|
||||
|
||||
# Create boot.txt file
|
||||
cat << EOF > "${basedir}"/kali-${architecture}/boot/boot.script
|
||||
cat <<EOF >"${basedir}"/kali-${architecture}/boot/boot.script
|
||||
setenv ramdisk uInitrd;
|
||||
setenv kernel uImage;
|
||||
setenv bootargs console=tty1 root=/dev/mmcblk0p2 rootwait rootfstype=ext3 rw quiet;
|
||||
@@ -256,16 +274,21 @@ cd "${basedir}"
|
||||
|
||||
# Create the disk and partition it
|
||||
echo "Creating image file for ${imagename}.img"
|
||||
|
||||
dd if=/dev/zero of="${basedir}"/${imagename}.img bs=1M count=${size}
|
||||
|
||||
parted ${imagename}.img --script -- mklabel msdos
|
||||
parted ${imagename}.img --script -- mkpart primary ext2 4096s 266239s
|
||||
parted ${imagename}.img --script -- mkpart primary ext3 266240s 100%
|
||||
|
||||
# Set the partition variables
|
||||
loopdevice=`losetup -f --show "${basedir}"/${imagename}.img`
|
||||
device=`kpartx -va ${loopdevice} | sed 's/.*\(loop[0-9]\+\)p.*/\1/g' | head -1`
|
||||
loopdevice=$(losetup -f --show "${basedir}"/${imagename}.img)
|
||||
|
||||
device=$(kpartx -va ${loopdevice} | sed 's/.*\(loop[0-9]\+\)p.*/\1/g' | head -1)
|
||||
device="/dev/mapper/${device}"
|
||||
|
||||
bootp=${device}p1
|
||||
|
||||
rootp=${device}p2
|
||||
|
||||
# Create file systems
|
||||
@@ -274,13 +297,15 @@ mkfs.ext3 ${rootp}
|
||||
|
||||
# Create the dirs for the partitions and mount them
|
||||
mkdir -p "${basedir}"/root
|
||||
|
||||
mount ${rootp} "${basedir}"/root
|
||||
|
||||
mkdir -p "${basedir}"/root/boot
|
||||
|
||||
mount ${bootp} "${basedir}"/root/boot
|
||||
|
||||
|
||||
# We do this down here to get rid of the build system's resolv.conf after running through the build.
|
||||
cat << EOF > kali-${architecture}/etc/resolv.conf
|
||||
cat <<EOF >kali-${architecture}/etc/resolv.conf
|
||||
nameserver 8.8.8.8
|
||||
EOF
|
||||
|
||||
@@ -295,11 +320,12 @@ kpartx -dv ${loopdevice}
|
||||
losetup -d ${loopdevice}
|
||||
|
||||
# Don't pixz on 32bit, there isn't enough memory to compress the images.
|
||||
MACHINE_TYPE=`uname -m`
|
||||
MACHINE_TYPE=$(uname -m)
|
||||
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
|
||||
echo "Compressing ${imagename}.img"
|
||||
pixz "${basedir}"/${imagename}.img "${basedir}"/../${imagename}.img.xz
|
||||
rm "${basedir}"/${imagename}.img
|
||||
echo "Compressing ${imagename}.img"
|
||||
pixz "${basedir}"/${imagename}.img "${basedir}"/../${imagename}.img.xz
|
||||
rm "${basedir}"/${imagename}.img
|
||||
|
||||
fi
|
||||
|
||||
# Clean up all the temporary build stuff and remove the directories.
|
||||
|
||||
@@ -18,32 +18,47 @@ set -e
|
||||
if [ "$debug" = true ]; then
|
||||
exec > >(tee -a -i "${0%.*}.log") 2>&1
|
||||
set -x
|
||||
|
||||
fi
|
||||
|
||||
# Architecture
|
||||
architecture=${architecture:-"armhf"}
|
||||
|
||||
# Generate a random machine name to be used.
|
||||
machine=$(tr -cd 'A-Za-z0-9' < /dev/urandom | head -c16 ; echo)
|
||||
machine=$(
|
||||
tr -cd 'A-Za-z0-9' </dev/urandom | head -c16
|
||||
echo
|
||||
)
|
||||
|
||||
# Custom hostname variable
|
||||
hostname=${2:-kali}
|
||||
|
||||
# Custom image file name variable - MUST NOT include .img at the end.
|
||||
imagename=${3:-kali-linux-$1-kalitap}
|
||||
|
||||
# Suite to use, valid options are:
|
||||
# kali-rolling, kali-dev, kali-bleeding-edge, kali-dev-only, kali-experimental, kali-last-snapshot
|
||||
suite=${suite:-"kali-rolling"}
|
||||
|
||||
# Free space rootfs in MiB
|
||||
free_space="300"
|
||||
|
||||
# /boot partition in MiB
|
||||
bootsize="128"
|
||||
|
||||
# Select compression, xz or none
|
||||
compress="xz"
|
||||
|
||||
# Choose filesystem format to format ( ext3 or ext4 )
|
||||
fstype="ext3"
|
||||
|
||||
# If you have your own preferred mirrors, set them here.
|
||||
mirror=${mirror:-"http://http.kali.org/kali"}
|
||||
# Gitlab url Kali repository
|
||||
|
||||
# Gitlab URL Kali repository
|
||||
kaligit="https://gitlab.com/kalilinux"
|
||||
# Github raw url
|
||||
|
||||
# Github raw URL
|
||||
githubraw="https://raw.githubusercontent.com"
|
||||
|
||||
# Check EUID=0 you can run any binary as root.
|
||||
@@ -51,12 +66,14 @@ if [[ $EUID -ne 0 ]]; then
|
||||
echo "This script must be run as root or have super user permissions"
|
||||
echo "Use: sudo $0 ${1:-2.0} ${2:-kali}"
|
||||
exit 1
|
||||
|
||||
fi
|
||||
|
||||
# Pass version number
|
||||
if [[ $# -eq 0 ]] ; then
|
||||
if [[ $# -eq 0 ]]; then
|
||||
echo "Please pass version number, e.g. $0 2.0, and (if you want) a hostname, default is kali"
|
||||
exit 0
|
||||
|
||||
fi
|
||||
|
||||
# Check exist bsp directory.
|
||||
@@ -64,12 +81,15 @@ if [ ! -e "bsp" ]; then
|
||||
echo "Error: missing bsp directory structure"
|
||||
echo "Please clone the full repository ${kaligit}/build-scripts/kali-arm"
|
||||
exit 255
|
||||
|
||||
fi
|
||||
|
||||
# Current directory
|
||||
repo_dir="$(pwd)"
|
||||
|
||||
# Base directory
|
||||
basedir=${repo_dir}/kalitap-"$1"
|
||||
|
||||
# Working directory
|
||||
work_dir="${basedir}/kali-${architecture}"
|
||||
|
||||
@@ -77,12 +97,15 @@ work_dir="${basedir}/kali-${architecture}"
|
||||
if [ -e "${basedir}" ]; then
|
||||
echo "${basedir} directory exists, will not continue"
|
||||
exit 1
|
||||
|
||||
elif [[ ${repo_dir} =~ [[:space:]] ]]; then
|
||||
echo "The directory "\"${repo_dir}"\" contains whitespace. Not supported."
|
||||
exit 1
|
||||
|
||||
else
|
||||
echo "The basedir thinks it is: ${basedir}"
|
||||
mkdir -p ${basedir}
|
||||
|
||||
fi
|
||||
|
||||
components="main,contrib,non-free"
|
||||
@@ -100,48 +123,54 @@ packages="${arm} ${base} ${services}"
|
||||
# apt_cacher=off
|
||||
# By default the proxy settings are local, but you can define an external proxy.
|
||||
# proxy_url="http://external.intranet.local"
|
||||
apt_cacher=${apt_cacher:-"$(lsof -i :3142|cut -d ' ' -f3 | uniq | sed '/^\s*$/d')"}
|
||||
apt_cacher=${apt_cacher:-"$(lsof -i :3142 | cut -d ' ' -f3 | uniq | sed '/^\s*$/d')"}
|
||||
|
||||
if [ -n "$proxy_url" ]; then
|
||||
export http_proxy=$proxy_url
|
||||
elif [ "$apt_cacher" = "apt-cacher-ng" ] ; then
|
||||
|
||||
elif [ "$apt_cacher" = "apt-cacher-ng" ]; then
|
||||
if [ -z "$proxy_url" ]; then
|
||||
proxy_url=${proxy_url:-"http://127.0.0.1:3142/"}
|
||||
export http_proxy=$proxy_url
|
||||
|
||||
fi
|
||||
fi
|
||||
|
||||
# Detect architecture
|
||||
if [[ "${architecture}" == "arm64" ]]; then
|
||||
qemu_bin="/usr/bin/qemu-aarch64-static"
|
||||
lib_arch="aarch64-linux-gnu"
|
||||
qemu_bin="/usr/bin/qemu-aarch64-static"
|
||||
lib_arch="aarch64-linux-gnu"
|
||||
|
||||
elif [[ "${architecture}" == "armhf" ]]; then
|
||||
qemu_bin="/usr/bin/qemu-arm-static"
|
||||
lib_arch="arm-linux-gnueabihf"
|
||||
qemu_bin="/usr/bin/qemu-arm-static"
|
||||
lib_arch="arm-linux-gnueabihf"
|
||||
|
||||
elif [[ "${architecture}" == "armel" ]]; then
|
||||
qemu_bin="/usr/bin/qemu-arm-static"
|
||||
lib_arch="arm-linux-gnueabi"
|
||||
qemu_bin="/usr/bin/qemu-arm-static"
|
||||
lib_arch="arm-linux-gnueabi"
|
||||
fi
|
||||
|
||||
# create the rootfs - not much to modify here, except maybe throw in some more packages if you want.
|
||||
# Create the rootfs - not much to modify here, except maybe throw in some more packages if you want.
|
||||
eatmydata debootstrap --foreign --keyring=/usr/share/keyrings/kali-archive-keyring.gpg --include=kali-archive-keyring,eatmydata \
|
||||
--components=${components} --arch ${architecture} ${suite} ${work_dir} http://http.kali.org/kali
|
||||
|
||||
# systemd-nspawn enviroment
|
||||
systemd-nspawn_exec(){
|
||||
systemd-nspawn_exec() {
|
||||
LANG=C systemd-nspawn -q --bind-ro ${qemu_bin} -M ${machine} -D ${work_dir} "$@"
|
||||
}
|
||||
|
||||
# We need to manually extract eatmydata to use it for the second stage.
|
||||
for archive in ${work_dir}/var/cache/apt/archives/*eatmydata*.deb; do
|
||||
dpkg-deb --fsys-tarfile "$archive" > ${work_dir}/eatmydata
|
||||
dpkg-deb --fsys-tarfile "$archive" >${work_dir}/eatmydata
|
||||
tar -xkf ${work_dir}/eatmydata -C ${work_dir}
|
||||
rm -f ${work_dir}/eatmydata
|
||||
|
||||
done
|
||||
|
||||
# Prepare dpkg to use eatmydata
|
||||
systemd-nspawn_exec dpkg-divert --divert /usr/bin/dpkg-eatmydata --rename --add /usr/bin/dpkg
|
||||
|
||||
cat > ${work_dir}/usr/bin/dpkg << EOF
|
||||
cat >${work_dir}/usr/bin/dpkg <<EOF
|
||||
#!/bin/sh
|
||||
if [ -e /usr/lib/${lib_arch}/libeatmydata.so ]; then
|
||||
[ -n "\${LD_PRELOAD}" ] && LD_PRELOAD="\$LD_PRELOAD:"
|
||||
@@ -159,14 +188,14 @@ chmod 755 ${work_dir}/usr/bin/dpkg
|
||||
# debootstrap second stage
|
||||
systemd-nspawn_exec eatmydata /debootstrap/debootstrap --second-stage
|
||||
|
||||
cat << EOF > ${work_dir}/etc/apt/sources.list
|
||||
cat <<EOF >${work_dir}/etc/apt/sources.list
|
||||
deb ${mirror} ${suite} ${components//,/ }
|
||||
#deb-src ${mirror} ${suite} ${components//,/ }
|
||||
EOF
|
||||
|
||||
echo "${hostname}" > ${work_dir}/etc/hostname
|
||||
echo "${hostname}" >${work_dir}/etc/hostname
|
||||
|
||||
cat << EOF > ${work_dir}/etc/hosts
|
||||
cat <<EOF >${work_dir}/etc/hosts
|
||||
127.0.0.1 ${hostname} localhost
|
||||
::1 localhost ip6-localhost ip6-loopback
|
||||
fe00::0 ip6-localnet
|
||||
@@ -176,7 +205,8 @@ ff02::2 ip6-allrouters
|
||||
EOF
|
||||
|
||||
mkdir -p ${work_dir}/etc/network/
|
||||
cat << EOF > ${work_dir}/etc/network/interfaces
|
||||
|
||||
cat <<EOF >${work_dir}/etc/network/interfaces
|
||||
auto lo
|
||||
iface lo inet loopback
|
||||
|
||||
@@ -191,7 +221,7 @@ iface usb0 inet static
|
||||
gateway 192.168.7.1
|
||||
EOF
|
||||
|
||||
cat << EOF > ${work_dir}/etc/resolv.conf
|
||||
cat <<EOF >${work_dir}/etc/resolv.conf
|
||||
nameserver 8.8.8.8
|
||||
EOF
|
||||
|
||||
@@ -202,11 +232,12 @@ export MALLOC_CHECK_=0 # workaround for LP: #520465
|
||||
|
||||
# Enable the use of http proxy in third-stage in case it is enabled.
|
||||
if [ -n "$proxy_url" ]; then
|
||||
echo "Acquire::http { Proxy \"$proxy_url\" };" > ${work_dir}/etc/apt/apt.conf.d/66proxy
|
||||
echo "Acquire::http { Proxy \"$proxy_url\" };" >${work_dir}/etc/apt/apt.conf.d/66proxy
|
||||
|
||||
fi
|
||||
|
||||
# Third stage
|
||||
cat << EOF > ${work_dir}/third-stage
|
||||
cat <<EOF >${work_dir}/third-stage
|
||||
#!/bin/bash -e
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
@@ -291,7 +322,7 @@ systemd-nspawn_exec /third-stage
|
||||
systemd-nspawn_exec dpkg-divert --remove --rename /usr/bin/dpkg
|
||||
|
||||
# Clean system
|
||||
systemd-nspawn_exec << 'EOF'
|
||||
systemd-nspawn_exec <<'EOF'
|
||||
rm -f /0
|
||||
rm -rf /bsp
|
||||
fc-cache -frs
|
||||
@@ -314,24 +345,26 @@ EOF
|
||||
if [ -n "$proxy_url" ]; then
|
||||
unset http_proxy
|
||||
rm -rf ${work_dir}/etc/apt/apt.conf.d/66proxy
|
||||
|
||||
fi
|
||||
|
||||
# Mirror & suite replacement
|
||||
if [[ ! -z "${4}" || ! -z "${5}" ]]; then
|
||||
mirror=${4}
|
||||
suite=${5}
|
||||
|
||||
fi
|
||||
|
||||
cat << EOF >> ${work_dir}/etc/udev/links.conf
|
||||
cat <<EOF >>${work_dir}/etc/udev/links.conf
|
||||
M ttyO0 c 5 1
|
||||
EOF
|
||||
|
||||
cat << EOF >> ${work_dir}/etc/securetty
|
||||
cat <<EOF >>${work_dir}/etc/securetty
|
||||
ttyO0
|
||||
EOF
|
||||
|
||||
# Define sources.list
|
||||
cat << EOF > ${work_dir}/etc/apt/sources.list
|
||||
cat <<EOF >${work_dir}/etc/apt/sources.list
|
||||
deb ${mirror} ${suite} ${components//,/ }
|
||||
#deb-src ${mirror} ${suite} ${components//,/ }
|
||||
EOF
|
||||
@@ -343,9 +376,9 @@ git clone --depth 1 https://gitlab.com/kalilinux/packages/gcc-arm-linux-gnueabih
|
||||
# Get, compile and install kernel
|
||||
git clone --depth 1 https://github.com/wawtechnologies/linux-kernel-3.14.51-catchwire-kalitap.git ${work_dir}/usr/src/kernel
|
||||
cd ${work_dir}/usr/src/kernel
|
||||
git rev-parse HEAD > ${work_dir}/usr/src/kernel-at-commit
|
||||
patch -p1 --no-backup-if-mismatch < ${repo_dir}/patches/kali-wifi-injection-3.14.patch
|
||||
patch -p1 --no-backup-if-mismatch < ${repo_dir}/patches/0001-wireless-carl9170-Enable-sniffer-mode-promisc-flag-t.patch
|
||||
git rev-parse HEAD >${work_dir}/usr/src/kernel-at-commit
|
||||
patch -p1 --no-backup-if-mismatch <${repo_dir}/patches/kali-wifi-injection-3.14.patch
|
||||
patch -p1 --no-backup-if-mismatch <${repo_dir}/patches/0001-wireless-carl9170-Enable-sniffer-mode-promisc-flag-t.patch
|
||||
touch .scmversion
|
||||
export ARCH=arm
|
||||
export CROSS_COMPILE="${basedir}"/gcc-arm-linux-gnueabihf-4.7/bin/arm-linux-gnueabihf-
|
||||
@@ -363,7 +396,7 @@ cd "${basedir}"
|
||||
# systemd doesn't seem to be generating the fstab properly for some people, so
|
||||
# let's create one. The rootfs partition is added below via UUID after the image
|
||||
# is created since we won't know the UUID until then.
|
||||
cat << EOF > ${work_dir}/etc/fstab
|
||||
cat <<EOF >${work_dir}/etc/fstab
|
||||
# <file system> <mount point> <type> <options> <dump> <pass>
|
||||
proc /proc proc defaults 0 0
|
||||
/dev/mmcblk0p1 /boot vfat defaults 0 2
|
||||
@@ -388,7 +421,7 @@ install -m755 udp0srv/udp0srv ${work_dir}/usr/sbin
|
||||
cd "${basedir}"
|
||||
|
||||
#u-boot kalitap specific overrides:
|
||||
cat << EOF > ${work_dir}/boot/uEnv.txt
|
||||
cat <<EOF >${work_dir}/boot/uEnv.txt
|
||||
optargs="consoleblank=0 mem=1G rootwait fixrtc net.ifnames=0 rootwait"
|
||||
kernel_file=zImage
|
||||
initrd_file=initrd.img
|
||||
@@ -422,8 +455,8 @@ cd "${basedir}"
|
||||
|
||||
# Calculate the space to create the image.
|
||||
root_size=$(du -s -B1 ${work_dir} --exclude=${work_dir}/boot | cut -f1)
|
||||
root_extra=$((${root_size}/1024/1000*5*1024/5))
|
||||
raw_size=$(($((${free_space}*1024))+${root_extra}+$((${bootsize}*1024))+4096))
|
||||
root_extra=$((${root_size} / 1024 / 1000 * 5 * 1024 / 5))
|
||||
raw_size=$(($((${free_space} * 1024)) + ${root_extra} + $((${bootsize} * 1024)) + 4096))
|
||||
|
||||
# Create the disk and partition it
|
||||
echo "Creating image file ${imagename}.img"
|
||||
@@ -434,8 +467,8 @@ parted -s -a minimal ${repo_dir}/${imagename}.img mkpart primary $fstype ${boots
|
||||
parted -s ${repo_dir}/${imagename}.img set 1 boot on
|
||||
|
||||
# Set the partition variables
|
||||
loopdevice=`losetup -f --show ${repo_dir}/${imagename}.img`
|
||||
device=`kpartx -va ${loopdevice} | sed 's/.*\(loop[0-9]\+\)p.*/\1/g' | head -1`
|
||||
loopdevice=$(losetup -f --show ${repo_dir}/${imagename}.img)
|
||||
device=$(kpartx -va ${loopdevice} | sed 's/.*\(loop[0-9]\+\)p.*/\1/g' | head -1)
|
||||
sleep 5
|
||||
device="/dev/mapper/${device}"
|
||||
bootp=${device}p1
|
||||
@@ -445,9 +478,12 @@ rootp=${device}p2
|
||||
mkfs.vfat -n BOOT -F 16 ${bootp}
|
||||
if [[ $fstype == ext4 ]]; then
|
||||
features="-O ^64bit,^metadata_csum"
|
||||
|
||||
elif [[ $fstype == ext3 ]]; then
|
||||
features="-O ^64bit"
|
||||
|
||||
fi
|
||||
|
||||
mkfs $features -t $fstype -L ROOTFS ${rootp}
|
||||
|
||||
# Create the dirs for the partitions and mount them
|
||||
@@ -457,13 +493,13 @@ mkdir -p "${basedir}"/root/boot
|
||||
mount ${bootp} "${basedir}"/root/boot
|
||||
|
||||
# We do this down here to get rid of the build system's resolv.conf after running through the build.
|
||||
cat << EOF > ${work_dir}/etc/resolv.conf
|
||||
cat <<EOF >${work_dir}/etc/resolv.conf
|
||||
nameserver 8.8.8.8
|
||||
EOF
|
||||
|
||||
# Create an fstab so that we don't mount / read-only.
|
||||
UUID=$(blkid -s UUID -o value ${rootp})
|
||||
echo "UUID=$UUID / $fstype errors=remount-ro 0 1" >> ${work_dir}/etc/fstab
|
||||
echo "UUID=$UUID / $fstype errors=remount-ro 0 1" >>${work_dir}/etc/fstab
|
||||
|
||||
echo "Rsyncing rootfs into image file"
|
||||
rsync -HPavz -q ${work_dir}/ ${basedir}/root/
|
||||
@@ -476,22 +512,31 @@ kpartx -dv ${loopdevice}
|
||||
losetup -d ${loopdevice}
|
||||
|
||||
# Limite use cpu function
|
||||
limit_cpu (){
|
||||
rand=$(tr -cd 'A-Za-z0-9' < /dev/urandom | head -c4 ; echo) # Randowm name group
|
||||
cgcreate -g cpu:/cpulimit-${rand} # Name of group cpulimit
|
||||
cgset -r cpu.shares=800 cpulimit-${rand} # Max 1024
|
||||
limit_cpu() {
|
||||
rand=$(
|
||||
tr -cd 'A-Za-z0-9' </dev/urandom | head -c4
|
||||
echo
|
||||
) # Randowm name group
|
||||
cgcreate -g cpu:/cpulimit-${rand} # Name of group cpulimit
|
||||
cgset -r cpu.shares=800 cpulimit-${rand} # Max 1024
|
||||
cgset -r cpu.cfs_quota_us=80000 cpulimit-${rand} # Max 100000
|
||||
|
||||
# Retry command
|
||||
local n=1; local max=5; local delay=2
|
||||
local n=1
|
||||
local max=5
|
||||
local delay=2
|
||||
|
||||
while true; do
|
||||
cgexec -g cpu:cpulimit-${rand} "$@" && break || {
|
||||
if [[ $n -lt $max ]]; then
|
||||
((n++))
|
||||
echo -e "\e[31m Command failed. Attempt $n/$max \033[0m"
|
||||
sleep $delay;
|
||||
sleep $delay
|
||||
|
||||
else
|
||||
echo "The command has failed after $n attempts."
|
||||
break
|
||||
|
||||
fi
|
||||
}
|
||||
done
|
||||
@@ -500,12 +545,15 @@ limit_cpu (){
|
||||
if [ $compress = xz ]; then
|
||||
if [ $(arch) == 'x86_64' ]; then
|
||||
echo "Compressing ${imagename}.img"
|
||||
[ $(nproc) \< 3 ] || cpu_cores=3 # cpu_cores = Number of cores to use
|
||||
[ $(nproc) \< 3 ] || cpu_cores=3 # cpu_cores = Number of cores to use
|
||||
limit_cpu pixz -p ${cpu_cores:-2} ${repo_dir}/${imagename}.img # -p Nº cpu cores use
|
||||
chmod 644 ${repo_dir}/${imagename}.img.xz
|
||||
|
||||
fi
|
||||
|
||||
else
|
||||
chmod 644 ${repo_dir}/${imagename}.img
|
||||
|
||||
fi
|
||||
|
||||
# Clean up all the temporary build stuff and remove the directories.
|
||||
|
||||
139
archived/luna.sh
139
archived/luna.sh
@@ -18,32 +18,47 @@ set -e
|
||||
if [ "$debug" = true ]; then
|
||||
exec > >(tee -a -i "${0%.*}.log") 2>&1
|
||||
set -x
|
||||
|
||||
fi
|
||||
|
||||
# Architecture
|
||||
architecture=${architecture:-"armhf"}
|
||||
|
||||
# Generate a random machine name to be used.
|
||||
machine=$(tr -cd 'A-Za-z0-9' < /dev/urandom | head -c16 ; echo)
|
||||
machine=$(
|
||||
tr -cd 'A-Za-z0-9' </dev/urandom | head -c16
|
||||
echo
|
||||
)
|
||||
|
||||
# Custom hostname variable
|
||||
hostname=${2:-kali}
|
||||
|
||||
# Custom image file name variable - MUST NOT include .img at the end.
|
||||
imagename=${3:-kali-linux-$1-luna}
|
||||
|
||||
# Suite to use, valid options are:
|
||||
# kali-rolling, kali-dev, kali-bleeding-edge, kali-dev-only, kali-experimental, kali-last-snapshot
|
||||
suite=${suite:-"kali-rolling"}
|
||||
|
||||
# Free space rootfs in MiB
|
||||
free_space="300"
|
||||
|
||||
# /boot partition in MiB
|
||||
bootsize="128"
|
||||
|
||||
# Select compression, xz or none
|
||||
compress="xz"
|
||||
|
||||
# Choose filesystem format to format ( ext3 or ext4 )
|
||||
fstype="ext3"
|
||||
|
||||
# If you have your own preferred mirrors, set them here.
|
||||
mirror=${mirror:-"http://http.kali.org/kali"}
|
||||
# Gitlab url Kali repository
|
||||
|
||||
# Gitlab URL Kali repository
|
||||
kaligit="https://gitlab.com/kalilinux"
|
||||
# Github raw url
|
||||
|
||||
# Github raw URL
|
||||
githubraw="https://raw.githubusercontent.com"
|
||||
|
||||
# Check EUID=0 you can run any binary as root.
|
||||
@@ -51,12 +66,14 @@ if [[ $EUID -ne 0 ]]; then
|
||||
echo "This script must be run as root or have super user permissions"
|
||||
echo "Use: sudo $0 ${1:-2.0} ${2:-kali}"
|
||||
exit 1
|
||||
|
||||
fi
|
||||
|
||||
# Pass version number
|
||||
if [[ $# -eq 0 ]] ; then
|
||||
if [[ $# -eq 0 ]]; then
|
||||
echo "Please pass version number, e.g. $0 2.0, and (if you want) a hostname, default is kali"
|
||||
exit 0
|
||||
|
||||
fi
|
||||
|
||||
# Check exist bsp directory.
|
||||
@@ -64,12 +81,15 @@ if [ ! -e "bsp" ]; then
|
||||
echo "Error: missing bsp directory structure"
|
||||
echo "Please clone the full repository ${kaligit}/build-scripts/kali-arm"
|
||||
exit 255
|
||||
|
||||
fi
|
||||
|
||||
# Current directory
|
||||
repo_dir="$(pwd)"
|
||||
|
||||
# Base directory
|
||||
basedir=${repo_dir}/luna-"$1"
|
||||
|
||||
# Working directory
|
||||
work_dir="${basedir}/kali-${architecture}"
|
||||
|
||||
@@ -77,12 +97,15 @@ work_dir="${basedir}/kali-${architecture}"
|
||||
if [ -e "${basedir}" ]; then
|
||||
echo "${basedir} directory exists, will not continue"
|
||||
exit 1
|
||||
|
||||
elif [[ ${repo_dir} =~ [[:space:]] ]]; then
|
||||
echo "The directory "\"${repo_dir}"\" contains whitespace. Not supported."
|
||||
exit 1
|
||||
|
||||
else
|
||||
echo "The basedir thinks it is: ${basedir}"
|
||||
mkdir -p ${basedir}
|
||||
|
||||
fi
|
||||
|
||||
components="main,contrib,non-free"
|
||||
@@ -100,48 +123,55 @@ packages="${arm} ${base} ${services}"
|
||||
# apt_cacher=off
|
||||
# By default the proxy settings are local, but you can define an external proxy.
|
||||
# proxy_url="http://external.intranet.local"
|
||||
apt_cacher=${apt_cacher:-"$(lsof -i :3142|cut -d ' ' -f3 | uniq | sed '/^\s*$/d')"}
|
||||
apt_cacher=${apt_cacher:-"$(lsof -i :3142 | cut -d ' ' -f3 | uniq | sed '/^\s*$/d')"}
|
||||
|
||||
if [ -n "$proxy_url" ]; then
|
||||
export http_proxy=$proxy_url
|
||||
elif [ "$apt_cacher" = "apt-cacher-ng" ] ; then
|
||||
|
||||
elif [ "$apt_cacher" = "apt-cacher-ng" ]; then
|
||||
if [ -z "$proxy_url" ]; then
|
||||
proxy_url=${proxy_url:-"http://127.0.0.1:3142/"}
|
||||
export http_proxy=$proxy_url
|
||||
|
||||
fi
|
||||
fi
|
||||
|
||||
# Detect architecture
|
||||
if [[ "${architecture}" == "arm64" ]]; then
|
||||
qemu_bin="/usr/bin/qemu-aarch64-static"
|
||||
lib_arch="aarch64-linux-gnu"
|
||||
qemu_bin="/usr/bin/qemu-aarch64-static"
|
||||
lib_arch="aarch64-linux-gnu"
|
||||
|
||||
elif [[ "${architecture}" == "armhf" ]]; then
|
||||
qemu_bin="/usr/bin/qemu-arm-static"
|
||||
lib_arch="arm-linux-gnueabihf"
|
||||
qemu_bin="/usr/bin/qemu-arm-static"
|
||||
lib_arch="arm-linux-gnueabihf"
|
||||
|
||||
elif [[ "${architecture}" == "armel" ]]; then
|
||||
qemu_bin="/usr/bin/qemu-arm-static"
|
||||
lib_arch="arm-linux-gnueabi"
|
||||
qemu_bin="/usr/bin/qemu-arm-static"
|
||||
lib_arch="arm-linux-gnueabi"
|
||||
|
||||
fi
|
||||
|
||||
# create the rootfs - not much to modify here, except maybe throw in some more packages if you want.
|
||||
# Create the rootfs - not much to modify here, except maybe throw in some more packages if you want.
|
||||
eatmydata debootstrap --foreign --keyring=/usr/share/keyrings/kali-archive-keyring.gpg --include=kali-archive-keyring,eatmydata \
|
||||
--components=${components} --arch ${architecture} ${suite} ${work_dir} http://http.kali.org/kali
|
||||
|
||||
# systemd-nspawn enviroment
|
||||
systemd-nspawn_exec(){
|
||||
systemd-nspawn_exec() {
|
||||
LANG=C systemd-nspawn -q --bind-ro ${qemu_bin} -M ${machine} -D ${work_dir} "$@"
|
||||
}
|
||||
|
||||
# We need to manually extract eatmydata to use it for the second stage.
|
||||
for archive in ${work_dir}/var/cache/apt/archives/*eatmydata*.deb; do
|
||||
dpkg-deb --fsys-tarfile "$archive" > ${work_dir}/eatmydata
|
||||
dpkg-deb --fsys-tarfile "$archive" >${work_dir}/eatmydata
|
||||
tar -xkf ${work_dir}/eatmydata -C ${work_dir}
|
||||
rm -f ${work_dir}/eatmydata
|
||||
|
||||
done
|
||||
|
||||
# Prepare dpkg to use eatmydata
|
||||
systemd-nspawn_exec dpkg-divert --divert /usr/bin/dpkg-eatmydata --rename --add /usr/bin/dpkg
|
||||
|
||||
cat > ${work_dir}/usr/bin/dpkg << EOF
|
||||
cat >${work_dir}/usr/bin/dpkg <<EOF
|
||||
#!/bin/sh
|
||||
if [ -e /usr/lib/${lib_arch}/libeatmydata.so ]; then
|
||||
[ -n "\${LD_PRELOAD}" ] && LD_PRELOAD="\$LD_PRELOAD:"
|
||||
@@ -154,21 +184,22 @@ done
|
||||
export LD_PRELOAD
|
||||
exec "\$0-eatmydata" --force-unsafe-io "\$@"
|
||||
EOF
|
||||
|
||||
chmod 755 ${work_dir}/usr/bin/dpkg
|
||||
|
||||
# debootstrap second stage
|
||||
systemd-nspawn_exec eatmydata /debootstrap/debootstrap --second-stage
|
||||
|
||||
cat << EOF > ${work_dir}/etc/apt/sources.list
|
||||
cat <<EOF >${work_dir}/etc/apt/sources.list
|
||||
deb ${mirror} ${suite} ${components//,/ }
|
||||
#deb-src ${mirror} ${suite} ${components//,/ }
|
||||
EOF
|
||||
|
||||
# Set hostname
|
||||
echo "${hostname}" > ${work_dir}/etc/hostname
|
||||
echo "${hostname}" >${work_dir}/etc/hostname
|
||||
|
||||
# So X doesn't complain, we add kali to hosts
|
||||
cat << EOF > ${work_dir}/etc/hosts
|
||||
cat <<EOF >${work_dir}/etc/hosts
|
||||
127.0.0.1 ${hostname} localhost
|
||||
::1 localhost ip6-localhost ip6-loopback
|
||||
fe00::0 ip6-localnet
|
||||
@@ -178,12 +209,12 @@ ff02::2 ip6-allrouters
|
||||
EOF
|
||||
|
||||
# Disable IPv6
|
||||
cat << EOF > ${work_dir}/etc/modprobe.d/ipv6.conf
|
||||
cat <<EOF >${work_dir}/etc/modprobe.d/ipv6.conf
|
||||
# Don't load ipv6 by default
|
||||
alias net-pf-10 off
|
||||
EOF
|
||||
|
||||
cat << EOF > ${work_dir}/etc/network/interfaces
|
||||
cat <<EOF >${work_dir}/etc/network/interfaces
|
||||
auto lo
|
||||
iface lo inet loopback
|
||||
|
||||
@@ -193,7 +224,7 @@ iface eth0 inet dhcp
|
||||
EOF
|
||||
|
||||
# DNS server
|
||||
echo "nameserver 8.8.8.8" > ${work_dir}/etc/resolv.conf
|
||||
echo "nameserver 8.8.8.8" >${work_dir}/etc/resolv.conf
|
||||
|
||||
# Copy directory bsp into build dir.
|
||||
cp -rp bsp ${work_dir}
|
||||
@@ -202,11 +233,12 @@ export MALLOC_CHECK_=0 # workaround for LP: #520465
|
||||
|
||||
# Enable the use of http proxy in third-stage in case it is enabled.
|
||||
if [ -n "$proxy_url" ]; then
|
||||
echo "Acquire::http { Proxy \"$proxy_url\" };" > ${work_dir}/etc/apt/apt.conf.d/66proxy
|
||||
echo "Acquire::http { Proxy \"$proxy_url\" };" >${work_dir}/etc/apt/apt.conf.d/66proxy
|
||||
|
||||
fi
|
||||
|
||||
# Third stage
|
||||
cat << EOF > ${work_dir}/third-stage
|
||||
cat <<EOF >${work_dir}/third-stage
|
||||
#!/bin/bash -e
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
@@ -290,7 +322,7 @@ systemd-nspawn_exec /third-stage
|
||||
systemd-nspawn_exec dpkg-divert --remove --rename /usr/bin/dpkg
|
||||
|
||||
# Clean system
|
||||
systemd-nspawn_exec << 'EOF'
|
||||
systemd-nspawn_exec <<'EOF'
|
||||
rm -f /0
|
||||
rm -rf /bsp
|
||||
fc-cache -frs
|
||||
@@ -313,24 +345,26 @@ EOF
|
||||
if [ -n "$proxy_url" ]; then
|
||||
unset http_proxy
|
||||
rm -rf ${work_dir}/etc/apt/apt.conf.d/66proxy
|
||||
|
||||
fi
|
||||
|
||||
# Mirror & suite replacement
|
||||
if [[ ! -z "${4}" || ! -z "${5}" ]]; then
|
||||
mirror=${4}
|
||||
suite=${5}
|
||||
|
||||
fi
|
||||
|
||||
cat << EOF >> ${work_dir}/etc/udev/links.conf
|
||||
cat <<EOF >>${work_dir}/etc/udev/links.conf
|
||||
M ttyO0 c 5 1
|
||||
EOF
|
||||
|
||||
cat << EOF >> ${work_dir}/etc/securetty
|
||||
cat <<EOF >>${work_dir}/etc/securetty
|
||||
ttyO0
|
||||
EOF
|
||||
|
||||
# Define sources.list
|
||||
cat << EOF > ${work_dir}/etc/apt/sources.list
|
||||
cat <<EOF >${work_dir}/etc/apt/sources.list
|
||||
deb ${mirror} ${suite} ${components//,/ }
|
||||
#deb-src ${mirror} ${suite} ${components//,/ }
|
||||
EOF
|
||||
@@ -338,7 +372,7 @@ EOF
|
||||
# Get, compile and install kernel
|
||||
git clone --depth 1 https://github.com/steev/luna-kernel ${work_dir}/usr/src/kernel
|
||||
cd ${work_dir}/usr/src/kernel
|
||||
patch -p1 --no-backup-if-mismatch < ${repo_dir}/patches/mac80211.patch
|
||||
patch -p1 --no-backup-if-mismatch <${repo_dir}/patches/mac80211.patch
|
||||
export ARCH=arm
|
||||
export CROSS_COMPILE=arm-linux-gnueabihf-
|
||||
cp ${repo_dir}/kernel-configs/luna.config .config
|
||||
@@ -350,7 +384,7 @@ cd "${basedir}"
|
||||
# systemd doesn't seem to be generating the fstab properly for some people, so
|
||||
# let's create one. We add the root partition below via UUID which we won't
|
||||
# know until after the image is created and partitioned.
|
||||
cat << EOF > ${work_dir}/etc/fstab
|
||||
cat <<EOF >${work_dir}/etc/fstab
|
||||
# <file system> <mount point> <type> <options> <dump> <pass>
|
||||
proc /proc proc defaults 0 0
|
||||
/dev/mmcblk0p1 /boot vfat defaults 0 2
|
||||
@@ -368,7 +402,7 @@ ln -s /usr/src/kernel source
|
||||
cd "${basedir}"
|
||||
|
||||
#u-boot LUNA specific overrides:
|
||||
cat << EOF > ${work_dir}/boot/uEnv.txt
|
||||
cat <<EOF >${work_dir}/boot/uEnv.txt
|
||||
fdtfile=am335x-luna.dtb
|
||||
kernel_file=zImage
|
||||
initrd_file=uInitrd
|
||||
@@ -388,8 +422,8 @@ EOF
|
||||
|
||||
# Calculate the space to create the image.
|
||||
root_size=$(du -s -B1 ${work_dir} --exclude=${work_dir}/boot | cut -f1)
|
||||
root_extra=$((${root_size}/1024/1000*5*1024/5))
|
||||
raw_size=$(($((${free_space}*1024))+${root_extra}+$((${bootsize}*1024))+4096))
|
||||
root_extra=$((${root_size} / 1024 / 1000 * 5 * 1024 / 5))
|
||||
raw_size=$(($((${free_space} * 1024)) + ${root_extra} + $((${bootsize} * 1024)) + 4096))
|
||||
|
||||
# Create the disk and partition it
|
||||
echo "Creating image file ${imagename}.img"
|
||||
@@ -399,8 +433,8 @@ parted -s ${repo_dir}/${imagename}.img mkpart primary fat32 1MiB ${bootsize}MiB
|
||||
parted -s -a minimal ${repo_dir}/${imagename}.img mkpart primary $fstype ${bootsize}MiB 100%
|
||||
|
||||
# Set the partition variables
|
||||
loopdevice=`losetup -f --show ${repo_dir}/${imagename}.img`
|
||||
device=`kpartx -va ${loopdevice} | sed 's/.*\(loop[0-9]\+\)p.*/\1/g' | head -1`
|
||||
loopdevice=$(losetup -f --show ${repo_dir}/${imagename}.img)
|
||||
device=$(kpartx -va ${loopdevice} | sed 's/.*\(loop[0-9]\+\)p.*/\1/g' | head -1)
|
||||
sleep 5
|
||||
device="/dev/mapper/${device}"
|
||||
bootp=${device}p1
|
||||
@@ -408,27 +442,32 @@ rootp=${device}p2
|
||||
|
||||
# Create file systems
|
||||
mkfs.vfat -n BOOT -F 16 ${bootp}
|
||||
|
||||
if [[ $fstype == ext4 ]]; then
|
||||
features="-O ^64bit,^metadata_csum"
|
||||
|
||||
elif [[ $fstype == ext3 ]]; then
|
||||
features="-O ^64bit"
|
||||
|
||||
fi
|
||||
|
||||
mkfs $features -t $fstype -L ROOTFS ${rootp}
|
||||
|
||||
# Create the dirs for the partitions and mount them
|
||||
mkdir -p "${basedir}"/root
|
||||
mount ${rootp} "${basedir}"/root
|
||||
|
||||
mkdir -p $"${basedir}"/root/boot
|
||||
mount ${bootp} "${basedir}"/root/boot
|
||||
|
||||
# We do this down here to get rid of the build system's resolv.conf after running through the build.
|
||||
cat << EOF > ${work_dir}/etc/resolv.conf
|
||||
cat <<EOF >${work_dir}/etc/resolv.conf
|
||||
nameserver 8.8.8.8
|
||||
EOF
|
||||
|
||||
# Create an fstab so that we don't mount / read-only.
|
||||
UUID=$(blkid -s UUID -o value ${rootp})
|
||||
echo "UUID=$UUID / $fstype errors=remount-ro 0 1" >> ${work_dir}/etc/fstab
|
||||
echo "UUID=$UUID / $fstype errors=remount-ro 0 1" >>${work_dir}/etc/fstab
|
||||
|
||||
echo "Rsyncing rootfs into image file"
|
||||
rsync -HPavz -q ${work_dir}/ ${basedir}/root/
|
||||
@@ -441,22 +480,31 @@ kpartx -dv ${loopdevice}
|
||||
losetup -d ${loopdevice}
|
||||
|
||||
# Limite use cpu function
|
||||
limit_cpu (){
|
||||
rand=$(tr -cd 'A-Za-z0-9' < /dev/urandom | head -c4 ; echo) # Randowm name group
|
||||
cgcreate -g cpu:/cpulimit-${rand} # Name of group cpulimit
|
||||
cgset -r cpu.shares=800 cpulimit-${rand} # Max 1024
|
||||
limit_cpu() {
|
||||
rand=$(
|
||||
tr -cd 'A-Za-z0-9' </dev/urandom | head -c4
|
||||
echo
|
||||
) # Randowm name group
|
||||
cgcreate -g cpu:/cpulimit-${rand} # Name of group cpulimit
|
||||
cgset -r cpu.shares=800 cpulimit-${rand} # Max 1024
|
||||
cgset -r cpu.cfs_quota_us=80000 cpulimit-${rand} # Max 100000
|
||||
|
||||
# Retry command
|
||||
local n=1; local max=5; local delay=2
|
||||
local n=1
|
||||
local max=5
|
||||
local delay=2
|
||||
|
||||
while true; do
|
||||
cgexec -g cpu:cpulimit-${rand} "$@" && break || {
|
||||
if [[ $n -lt $max ]]; then
|
||||
((n++))
|
||||
echo -e "\e[31m Command failed. Attempt $n/$max \033[0m"
|
||||
sleep $delay;
|
||||
sleep $delay
|
||||
|
||||
else
|
||||
echo "The command has failed after $n attempts."
|
||||
break
|
||||
|
||||
fi
|
||||
}
|
||||
done
|
||||
@@ -465,12 +513,15 @@ limit_cpu (){
|
||||
if [ $compress = xz ]; then
|
||||
if [ $(arch) == 'x86_64' ]; then
|
||||
echo "Compressing ${imagename}.img"
|
||||
[ $(nproc) \< 3 ] || cpu_cores=3 # cpu_cores = Number of cores to use
|
||||
[ $(nproc) \< 3 ] || cpu_cores=3 # cpu_cores = Number of cores to use
|
||||
limit_cpu pixz -p ${cpu_cores:-2} ${repo_dir}/${imagename}.img # -p Nº cpu cores use
|
||||
chmod 644 ${repo_dir}/${imagename}.img.xz
|
||||
|
||||
fi
|
||||
|
||||
else
|
||||
chmod 644 ${repo_dir}/${imagename}.img
|
||||
|
||||
fi
|
||||
|
||||
# Clean up all the temporary build stuff and remove the directories.
|
||||
|
||||
@@ -18,32 +18,47 @@ set -e
|
||||
if [ "$debug" = true ]; then
|
||||
exec > >(tee -a -i "${0%.*}.log") 2>&1
|
||||
set -x
|
||||
|
||||
fi
|
||||
|
||||
# Architecture
|
||||
architecture=${architecture:-"armel"}
|
||||
|
||||
# Generate a random machine name to be used.
|
||||
machine=$(tr -cd 'A-Za-z0-9' < /dev/urandom | head -c16 ; echo)
|
||||
machine=$(
|
||||
tr -cd 'A-Za-z0-9' </dev/urandom | head -c16
|
||||
echo
|
||||
)
|
||||
|
||||
# Custom hostname variable
|
||||
hostname=${2:-kali}
|
||||
|
||||
# Custom image file name variable - MUST NOT include .img at the end.
|
||||
imagename=${3:-kali-linux-$1-owdk}
|
||||
|
||||
# Suite to use, valid options are:
|
||||
# kali-rolling, kali-dev, kali-bleeding-edge, kali-dev-only, kali-experimental, kali-last-snapshot
|
||||
suite=${suite:-"kali-rolling"}
|
||||
|
||||
# Free space rootfs in MiB
|
||||
free_space="300"
|
||||
|
||||
# /boot partition in MiB
|
||||
bootsize="128"
|
||||
|
||||
# Select compression, xz or none
|
||||
compress="xz"
|
||||
|
||||
# Choose filesystem format to format ( ext3 or ext4 )
|
||||
fstype="ext3"
|
||||
|
||||
# If you have your own preferred mirrors, set them here.
|
||||
mirror=${mirror:-"http://http.kali.org/kali"}
|
||||
# Gitlab url Kali repository
|
||||
|
||||
# Gitlab URL Kali repository
|
||||
kaligit="https://gitlab.com/kalilinux"
|
||||
# Github raw url
|
||||
|
||||
# Github raw URL
|
||||
githubraw="https://raw.githubusercontent.com"
|
||||
|
||||
# Check EUID=0 you can run any binary as root.
|
||||
@@ -51,12 +66,14 @@ if [[ $EUID -ne 0 ]]; then
|
||||
echo "This script must be run as root or have super user permissions"
|
||||
echo "Use: sudo $0 ${1:-2.0} ${2:-kali}"
|
||||
exit 1
|
||||
|
||||
fi
|
||||
|
||||
# Pass version number
|
||||
if [[ $# -eq 0 ]] ; then
|
||||
if [[ $# -eq 0 ]]; then
|
||||
echo "Please pass version number, e.g. $0 2.0, and (if you want) a hostname, default is kali"
|
||||
exit 0
|
||||
|
||||
fi
|
||||
|
||||
# Check exist bsp directory.
|
||||
@@ -64,12 +81,15 @@ if [ ! -e "bsp" ]; then
|
||||
echo "Error: missing bsp directory structure"
|
||||
echo "Please clone the full repository ${kaligit}/build-scripts/kali-arm"
|
||||
exit 255
|
||||
|
||||
fi
|
||||
|
||||
# Current directory
|
||||
repo_dir="$(pwd)"
|
||||
|
||||
# Base directory
|
||||
basedir=${repo_dir}/owdk-"$1"
|
||||
|
||||
# Working directory
|
||||
work_dir="${basedir}/kali-${architecture}"
|
||||
|
||||
@@ -77,12 +97,15 @@ work_dir="${basedir}/kali-${architecture}"
|
||||
if [ -e "${basedir}" ]; then
|
||||
echo "${basedir} directory exists, will not continue"
|
||||
exit 1
|
||||
|
||||
elif [[ ${repo_dir} =~ [[:space:]] ]]; then
|
||||
echo "The directory "\"${repo_dir}"\" contains whitespace. Not supported."
|
||||
exit 1
|
||||
|
||||
else
|
||||
echo "The basedir thinks it is: ${basedir}"
|
||||
mkdir -p ${basedir}
|
||||
|
||||
fi
|
||||
|
||||
components="main,contrib,non-free"
|
||||
@@ -98,9 +121,10 @@ packages="${arm} ${base} ${services}"
|
||||
|
||||
# Check to ensure that the architecture is set to ARMEL since the ODWK is the
|
||||
# only board that is armel.
|
||||
if [[ ${architecture} != "armel" ]] ; then
|
||||
echo "The ODROID-W cannot run the Debian armhf binaries"
|
||||
exit 0
|
||||
if [[ ${architecture} != "armel" ]]; then
|
||||
echo "The ODROID-W cannot run the Debian armhf binaries"
|
||||
exit 0
|
||||
|
||||
fi
|
||||
|
||||
# Automatic configuration to use an http proxy, such as apt-cacher-ng.
|
||||
@@ -108,48 +132,55 @@ fi
|
||||
# apt_cacher=off
|
||||
# By default the proxy settings are local, but you can define an external proxy.
|
||||
# proxy_url="http://external.intranet.local"
|
||||
apt_cacher=${apt_cacher:-"$(lsof -i :3142|cut -d ' ' -f3 | uniq | sed '/^\s*$/d')"}
|
||||
apt_cacher=${apt_cacher:-"$(lsof -i :3142 | cut -d ' ' -f3 | uniq | sed '/^\s*$/d')"}
|
||||
|
||||
if [ -n "$proxy_url" ]; then
|
||||
export http_proxy=$proxy_url
|
||||
elif [ "$apt_cacher" = "apt-cacher-ng" ] ; then
|
||||
|
||||
elif [ "$apt_cacher" = "apt-cacher-ng" ]; then
|
||||
if [ -z "$proxy_url" ]; then
|
||||
proxy_url=${proxy_url:-"http://127.0.0.1:3142/"}
|
||||
export http_proxy=$proxy_url
|
||||
|
||||
fi
|
||||
fi
|
||||
|
||||
# Detect architecture
|
||||
if [[ "${architecture}" == "arm64" ]]; then
|
||||
qemu_bin="/usr/bin/qemu-aarch64-static"
|
||||
lib_arch="aarch64-linux-gnu"
|
||||
qemu_bin="/usr/bin/qemu-aarch64-static"
|
||||
lib_arch="aarch64-linux-gnu"
|
||||
|
||||
elif [[ "${architecture}" == "armhf" ]]; then
|
||||
qemu_bin="/usr/bin/qemu-arm-static"
|
||||
lib_arch="arm-linux-gnueabihf"
|
||||
qemu_bin="/usr/bin/qemu-arm-static"
|
||||
lib_arch="arm-linux-gnueabihf"
|
||||
|
||||
elif [[ "${architecture}" == "armel" ]]; then
|
||||
qemu_bin="/usr/bin/qemu-arm-static"
|
||||
lib_arch="arm-linux-gnueabi"
|
||||
qemu_bin="/usr/bin/qemu-arm-static"
|
||||
lib_arch="arm-linux-gnueabi"
|
||||
|
||||
fi
|
||||
|
||||
# create the rootfs - not much to modify here, except maybe throw in some more packages if you want.
|
||||
eatmydata debootstrap --foreign --keyring=/usr/share/keyrings/kali-archive-keyring.gpg --include=kali-archive-keyring,eatmydata \
|
||||
--components=${components} --arch ${architecture} ${suite} ${work_dir} http://http.kali.org/kali
|
||||
eatmydata debootstrap --foreign --keyring=/usr/share/keyrings/kali-archive-keyring.gpg \
|
||||
--include=kali-archive-keyring,eatmydata --components=${components} \--arch ${architecture} ${suite} ${work_dir} http://http.kali.org/kali
|
||||
|
||||
# systemd-nspawn enviroment
|
||||
systemd-nspawn_exec(){
|
||||
systemd-nspawn_exec() {
|
||||
LANG=C systemd-nspawn -q --bind-ro ${qemu_bin} -M ${machine} -D ${work_dir} "$@"
|
||||
}
|
||||
|
||||
# We need to manually extract eatmydata to use it for the second stage.
|
||||
for archive in ${work_dir}/var/cache/apt/archives/*eatmydata*.deb; do
|
||||
dpkg-deb --fsys-tarfile "$archive" > ${work_dir}/eatmydata
|
||||
dpkg-deb --fsys-tarfile "$archive" >${work_dir}/eatmydata
|
||||
tar -xkf ${work_dir}/eatmydata -C ${work_dir}
|
||||
rm -f ${work_dir}/eatmydata
|
||||
|
||||
done
|
||||
|
||||
# Prepare dpkg to use eatmydata
|
||||
systemd-nspawn_exec dpkg-divert --divert /usr/bin/dpkg-eatmydata --rename --add /usr/bin/dpkg
|
||||
|
||||
cat > ${work_dir}/usr/bin/dpkg << EOF
|
||||
cat >${work_dir}/usr/bin/dpkg <<EOF
|
||||
#!/bin/sh
|
||||
if [ -e /usr/lib/${lib_arch}/libeatmydata.so ]; then
|
||||
[ -n "\${LD_PRELOAD}" ] && LD_PRELOAD="\$LD_PRELOAD:"
|
||||
@@ -167,16 +198,16 @@ chmod 755 ${work_dir}/usr/bin/dpkg
|
||||
# debootstrap second stage
|
||||
systemd-nspawn_exec eatmydata /debootstrap/debootstrap --second-stage
|
||||
|
||||
cat << EOF > ${work_dir}/etc/apt/sources.list
|
||||
cat <<EOF >${work_dir}/etc/apt/sources.list
|
||||
deb ${mirror} ${suite} ${components//,/ }
|
||||
#deb-src ${mirror} ${suite} ${components//,/ }
|
||||
EOF
|
||||
|
||||
# Set hostname
|
||||
echo "${hostname}" > ${work_dir}/etc/hostname
|
||||
echo "${hostname}" >${work_dir}/etc/hostname
|
||||
|
||||
# So X doesn't complain, we add kali to hosts
|
||||
cat << EOF > ${work_dir}/etc/hosts
|
||||
cat <<EOF >${work_dir}/etc/hosts
|
||||
127.0.0.1 ${hostname} localhost
|
||||
::1 localhost ip6-localhost ip6-loopback
|
||||
fe00::0 ip6-localnet
|
||||
@@ -186,12 +217,12 @@ ff02::2 ip6-allrouters
|
||||
EOF
|
||||
|
||||
# Disable IPv6
|
||||
cat << EOF > ${work_dir}/etc/modprobe.d/ipv6.conf
|
||||
cat <<EOF >${work_dir}/etc/modprobe.d/ipv6.conf
|
||||
# Don't load ipv6 by default
|
||||
alias net-pf-10 off
|
||||
EOF
|
||||
|
||||
cat << EOF > ${work_dir}/etc/network/interfaces
|
||||
cat <<EOF >${work_dir}/etc/network/interfaces
|
||||
auto lo
|
||||
iface lo inet loopback
|
||||
|
||||
@@ -201,7 +232,7 @@ iface eth0 inet dhcp
|
||||
EOF
|
||||
|
||||
# DNS server
|
||||
echo "nameserver 8.8.8.8" > ${work_dir}/etc/resolv.conf
|
||||
echo "nameserver 8.8.8.8" >${work_dir}/etc/resolv.conf
|
||||
|
||||
# Copy directory bsp into build dir.
|
||||
cp -rp bsp ${work_dir}
|
||||
@@ -210,11 +241,12 @@ export MALLOC_CHECK_=0 # workaround for LP: #520465
|
||||
|
||||
# Enable the use of http proxy in third-stage in case it is enabled.
|
||||
if [ -n "$proxy_url" ]; then
|
||||
echo "Acquire::http { Proxy \"$proxy_url\" };" > ${work_dir}/etc/apt/apt.conf.d/66proxy
|
||||
echo "Acquire::http { Proxy \"$proxy_url\" };" >${work_dir}/etc/apt/apt.conf.d/66proxy
|
||||
|
||||
fi
|
||||
|
||||
# Third stage
|
||||
cat << EOF > ${work_dir}/third-stage
|
||||
cat <<EOF >${work_dir}/third-stage
|
||||
#!/bin/bash -e
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
@@ -333,7 +365,7 @@ systemd-nspawn_exec /third-stage
|
||||
systemd-nspawn_exec dpkg-divert --remove --rename /usr/bin/dpkg
|
||||
|
||||
# Clean system
|
||||
systemd-nspawn_exec << 'EOF'
|
||||
systemd-nspawn_exec <<'EOF'
|
||||
rm -f /0
|
||||
rm -rf /bsp
|
||||
fc-cache -frs
|
||||
@@ -356,16 +388,18 @@ EOF
|
||||
if [ -n "$proxy_url" ]; then
|
||||
unset http_proxy
|
||||
rm -rf ${work_dir}/etc/apt/apt.conf.d/66proxy
|
||||
|
||||
fi
|
||||
|
||||
# Mirror & suite replacement
|
||||
if [[ ! -z "${4}" || ! -z "${5}" ]]; then
|
||||
mirror=${4}
|
||||
suite=${5}
|
||||
|
||||
fi
|
||||
|
||||
# Define sources.list
|
||||
cat << EOF > ${work_dir}/etc/apt/sources.list
|
||||
cat <<EOF >${work_dir}/etc/apt/sources.list
|
||||
deb ${mirror} ${suite} ${components//,/ }
|
||||
#deb-src ${mirror} ${suite} ${components//,/ }
|
||||
EOF
|
||||
@@ -373,32 +407,33 @@ EOF
|
||||
# systemd doesn't seem to be generating the fstab properly for some people, so
|
||||
# let's create one. Root partition is added below after the image file is created
|
||||
# because we add it via UUID.
|
||||
cat << EOF > ${work_dir}/etc/fstab
|
||||
cat <<EOF >${work_dir}/etc/fstab
|
||||
# <file system> <mount point> <type> <options> <dump> <pass>
|
||||
proc /proc proc defaults 0 0
|
||||
/dev/mmcblk0p1 /boot vfat defaults 0 2
|
||||
EOF
|
||||
|
||||
# Create cmdline.txt file
|
||||
cat << EOF > ${work_dir}/boot/cmdline.txt
|
||||
cat <<EOF >${work_dir}/boot/cmdline.txt
|
||||
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 elevator=deadline root=/dev/mmcblk0p2 rootfstype=$fstype rootwait fbcon=map:10 net.ifnames=0 rw
|
||||
EOF
|
||||
|
||||
# Copy a default config, with everything commented out so people find it when
|
||||
# they go to add something when they are following instructions on a website.
|
||||
cp ./bsp/firmware/rpi/config.txt ${work_dir}/boot/config.txt
|
||||
|
||||
# Remove repeat conditional filters [all] in config.txt
|
||||
sed -i "59,66d" ${work_dir}/boot/config.txt
|
||||
|
||||
# Add needed bit for the lcd of the devkit.
|
||||
cat << EOF >> ${work_dir}/boot/config.txt
|
||||
cat <<EOF >>${work_dir}/boot/config.txt
|
||||
|
||||
# Use fbtft_device instead of a DT overlay
|
||||
dtparam=spi=on
|
||||
EOF
|
||||
|
||||
# Create /etc/modules based on ODROID-W
|
||||
cat << EOF > ${work_dir}/etc/modules
|
||||
cat <<EOF >${work_dir}/etc/modules
|
||||
# /etc/modules: kernel modules to load at boot time.
|
||||
#
|
||||
# This file contains the names of kernel modules that should be loaded
|
||||
@@ -411,18 +446,19 @@ fbtft_device name=adafruit22a rotate=90
|
||||
EOF
|
||||
|
||||
mkdir -p ${work_dir}/etc/modprobe.d/
|
||||
cat << EOF > ${work_dir}/etc/modprobe.d/fbtft_device.conf
|
||||
cat <<EOF >${work_dir}/etc/modprobe.d/fbtft_device.conf
|
||||
options fbtft_device name=adafruit22a rotate=90
|
||||
EOF
|
||||
|
||||
# Calculate the space to create the image.
|
||||
root_size=$(du -s -B1 ${work_dir} --exclude=${work_dir}/boot | cut -f1)
|
||||
root_extra=$((${root_size}/1024/1000*5*1024/5))
|
||||
raw_size=$(($((${free_space}*1024))+${root_extra}+$((${bootsize}*1024))+4096))
|
||||
root_extra=$((${root_size} / 1024 / 1000 * 5 * 1024 / 5))
|
||||
raw_size=$(($((${free_space} * 1024)) + ${root_extra} + $((${bootsize} * 1024)) + 4096))
|
||||
|
||||
# Create the disk and partition it
|
||||
echo "Creating image file ${imagename}.img"
|
||||
fallocate -l $(echo ${raw_size}Ki | numfmt --from=iec-i --to=si) ${repo_dir}/${imagename}.img
|
||||
|
||||
parted -s ${repo_dir}/${imagename}.img mklabel msdos
|
||||
parted -s ${repo_dir}/${imagename}.img mkpart primary fat32 1MiB ${bootsize}MiB
|
||||
parted -s -a minimal ${repo_dir}/${imagename}.img mkpart primary $fstype ${bootsize}MiB 100%
|
||||
@@ -436,25 +472,29 @@ rootp="${loopdevice}p2"
|
||||
mkfs.vfat -n BOOT -F 32 -v ${bootp}
|
||||
if [[ $fstype == ext4 ]]; then
|
||||
features="-O ^64bit,^metadata_csum"
|
||||
|
||||
elif [[ $fstype == ext3 ]]; then
|
||||
features="-O ^64bit"
|
||||
|
||||
fi
|
||||
|
||||
mkfs $features -t $fstype -L ROOTFS ${rootp}
|
||||
|
||||
# Create the dirs for the partitions and mount them
|
||||
mkdir -p ${basedir}/root/
|
||||
mount ${rootp} ${basedir}/root
|
||||
|
||||
mkdir -p ${basedir}/root/boot
|
||||
mount ${bootp} ${basedir}/root/boot
|
||||
|
||||
# We do this down here to get rid of the build system's resolv.conf after running through the build.
|
||||
cat << EOF > ${work_dir}/etc/resolv.conf
|
||||
cat <<EOF >${work_dir}/etc/resolv.conf
|
||||
nameserver 8.8.8.8
|
||||
EOF
|
||||
|
||||
# Create an fstab so that we don't mount / read-only.
|
||||
UUID=$(blkid -s UUID -o value ${rootp})
|
||||
echo "UUID=$UUID / $fstype errors=remount-ro 0 1" >> ${work_dir}/etc/fstab
|
||||
echo "UUID=$UUID / $fstype errors=remount-ro 0 1" >>${work_dir}/etc/fstab
|
||||
|
||||
echo "Rsyncing rootfs into image file"
|
||||
rsync -HPavz -q ${work_dir}/ ${basedir}/root/
|
||||
@@ -467,22 +507,31 @@ kpartx -dv ${loopdevice}
|
||||
losetup -d ${loopdevice}
|
||||
|
||||
# Limite use cpu function
|
||||
limit_cpu (){
|
||||
rand=$(tr -cd 'A-Za-z0-9' < /dev/urandom | head -c4 ; echo) # Randowm name group
|
||||
cgcreate -g cpu:/cpulimit-${rand} # Name of group cpulimit
|
||||
cgset -r cpu.shares=800 cpulimit-${rand} # Max 1024
|
||||
limit_cpu() {
|
||||
rand=$(
|
||||
tr -cd 'A-Za-z0-9' </dev/urandom | head -c4
|
||||
echo
|
||||
) # Randowm name group
|
||||
cgcreate -g cpu:/cpulimit-${rand} # Name of group cpulimit
|
||||
cgset -r cpu.shares=800 cpulimit-${rand} # Max 1024
|
||||
cgset -r cpu.cfs_quota_us=80000 cpulimit-${rand} # Max 100000
|
||||
|
||||
# Retry command
|
||||
local n=1; local max=5; local delay=2
|
||||
local n=1
|
||||
local max=5
|
||||
local delay=2
|
||||
|
||||
while true; do
|
||||
cgexec -g cpu:cpulimit-${rand} "$@" && break || {
|
||||
if [[ $n -lt $max ]]; then
|
||||
((n++))
|
||||
echo -e "\e[31m Command failed. Attempt $n/$max \033[0m"
|
||||
sleep $delay;
|
||||
sleep $delay
|
||||
|
||||
else
|
||||
echo "The command has failed after $n attempts."
|
||||
break
|
||||
|
||||
fi
|
||||
}
|
||||
done
|
||||
@@ -491,12 +540,15 @@ limit_cpu (){
|
||||
if [ $compress = xz ]; then
|
||||
if [ $(arch) == 'x86_64' ]; then
|
||||
echo "Compressing ${imagename}.img"
|
||||
[ $(nproc) \< 3 ] || cpu_cores=3 # cpu_cores = Number of cores to use
|
||||
[ $(nproc) \< 3 ] || cpu_cores=3 # cpu_cores = Number of cores to use
|
||||
limit_cpu pixz -p ${cpu_cores:-2} ${repo_dir}/${imagename}.img # -p Nº cpu cores use
|
||||
chmod 644 ${repo_dir}/${imagename}.img.xz
|
||||
|
||||
fi
|
||||
|
||||
else
|
||||
chmod 644 ${repo_dir}/${imagename}.img
|
||||
|
||||
fi
|
||||
|
||||
# Clean up all the temporary build stuff and remove the directories.
|
||||
|
||||
@@ -18,32 +18,47 @@ set -e
|
||||
if [ "$debug" = true ]; then
|
||||
exec > >(tee -a -i "${0%.*}.log") 2>&1
|
||||
set -x
|
||||
|
||||
fi
|
||||
|
||||
# Architecture
|
||||
architecture=${architecture:-"armel"}
|
||||
|
||||
# Generate a random machine name to be used.
|
||||
machine=$(tr -cd 'A-Za-z0-9' < /dev/urandom | head -c16 ; echo)
|
||||
machine=$(
|
||||
tr -cd 'A-Za-z0-9' </dev/urandom | head -c16
|
||||
echo
|
||||
)
|
||||
|
||||
# Custom hostname variable
|
||||
hostname=${2:-kali}
|
||||
|
||||
# Custom image file name variable - MUST NOT include .img at the end.
|
||||
imagename=${3:-kali-linux-$1-odroidw}
|
||||
|
||||
# Suite to use, valid options are:
|
||||
# kali-rolling, kali-dev, kali-bleeding-edge, kali-dev-only, kali-experimental, kali-last-snapshot
|
||||
suite=${suite:-"kali-rolling"}
|
||||
|
||||
# Free space rootfs in MiB
|
||||
free_space="300"
|
||||
|
||||
# /boot partition in MiB
|
||||
bootsize="128"
|
||||
|
||||
# Select compression, xz or none
|
||||
compress="xz"
|
||||
|
||||
# Choose filesystem format to format ( ext3 or ext4 )
|
||||
fstype="ext3"
|
||||
|
||||
# If you have your own preferred mirrors, set them here.
|
||||
mirror=${mirror:-"http://http.kali.org/kali"}
|
||||
# Gitlab url Kali repository
|
||||
|
||||
# Gitlab URL Kali repository
|
||||
kaligit="https://gitlab.com/kalilinux"
|
||||
# Github raw url
|
||||
|
||||
# Github raw URL
|
||||
githubraw="https://raw.githubusercontent.com"
|
||||
|
||||
# Check EUID=0 you can run any binary as root.
|
||||
@@ -51,12 +66,14 @@ if [[ $EUID -ne 0 ]]; then
|
||||
echo "This script must be run as root or have super user permissions"
|
||||
echo "Use: sudo $0 ${1:-2.0} ${2:-kali}"
|
||||
exit 1
|
||||
|
||||
fi
|
||||
|
||||
# Pass version number
|
||||
if [[ $# -eq 0 ]] ; then
|
||||
if [[ $# -eq 0 ]]; then
|
||||
echo "Please pass version number, e.g. $0 2.0, and (if you want) a hostname, default is kali"
|
||||
exit 0
|
||||
|
||||
fi
|
||||
|
||||
# Check exist bsp directory.
|
||||
@@ -64,12 +81,15 @@ if [ ! -e "bsp" ]; then
|
||||
echo "Error: missing bsp directory structure"
|
||||
echo "Please clone the full repository ${kaligit}/build-scripts/kali-arm"
|
||||
exit 255
|
||||
|
||||
fi
|
||||
|
||||
# Current directory
|
||||
repo_dir="$(pwd)"
|
||||
|
||||
# Base directory
|
||||
basedir=${repo_dir}/odroidw-"$1"
|
||||
|
||||
# Working directory
|
||||
work_dir="${basedir}/kali-${architecture}"
|
||||
|
||||
@@ -77,12 +97,15 @@ work_dir="${basedir}/kali-${architecture}"
|
||||
if [ -e "${basedir}" ]; then
|
||||
echo "${basedir} directory exists, will not continue"
|
||||
exit 1
|
||||
|
||||
elif [[ ${repo_dir} =~ [[:space:]] ]]; then
|
||||
echo "The directory "\"${repo_dir}"\" contains whitespace. Not supported."
|
||||
exit 1
|
||||
|
||||
else
|
||||
echo "The basedir thinks it is: ${basedir}"
|
||||
mkdir -p ${basedir}
|
||||
|
||||
fi
|
||||
|
||||
components="main,contrib,non-free"
|
||||
@@ -97,9 +120,10 @@ packages="${arm} ${base} ${services}"
|
||||
|
||||
# Check to ensure that the architecture is set to ARMEL since the ODROID-W is the
|
||||
# only board that is armel.
|
||||
if [[ ${architecture} != "armel" ]] ; then
|
||||
echo "The ODROID-W cannot run Debian armhf binaries"
|
||||
exit 0
|
||||
if [[ ${architecture} != "armel" ]]; then
|
||||
echo "The ODROID-W cannot run Debian armhf binaries"
|
||||
exit 0
|
||||
|
||||
fi
|
||||
|
||||
# Automatic configuration to use an http proxy, such as apt-cacher-ng.
|
||||
@@ -107,48 +131,55 @@ fi
|
||||
# apt_cacher=off
|
||||
# By default the proxy settings are local, but you can define an external proxy.
|
||||
# proxy_url="http://external.intranet.local"
|
||||
apt_cacher=${apt_cacher:-"$(lsof -i :3142|cut -d ' ' -f3 | uniq | sed '/^\s*$/d')"}
|
||||
apt_cacher=${apt_cacher:-"$(lsof -i :3142 | cut -d ' ' -f3 | uniq | sed '/^\s*$/d')"}
|
||||
|
||||
if [ -n "$proxy_url" ]; then
|
||||
export http_proxy=$proxy_url
|
||||
elif [ "$apt_cacher" = "apt-cacher-ng" ] ; then
|
||||
|
||||
elif [ "$apt_cacher" = "apt-cacher-ng" ]; then
|
||||
if [ -z "$proxy_url" ]; then
|
||||
proxy_url=${proxy_url:-"http://127.0.0.1:3142/"}
|
||||
export http_proxy=$proxy_url
|
||||
|
||||
fi
|
||||
fi
|
||||
|
||||
# Detect architecture
|
||||
if [[ "${architecture}" == "arm64" ]]; then
|
||||
qemu_bin="/usr/bin/qemu-aarch64-static"
|
||||
lib_arch="aarch64-linux-gnu"
|
||||
qemu_bin="/usr/bin/qemu-aarch64-static"
|
||||
lib_arch="aarch64-linux-gnu"
|
||||
|
||||
elif [[ "${architecture}" == "armhf" ]]; then
|
||||
qemu_bin="/usr/bin/qemu-arm-static"
|
||||
lib_arch="arm-linux-gnueabihf"
|
||||
qemu_bin="/usr/bin/qemu-arm-static"
|
||||
lib_arch="arm-linux-gnueabihf"
|
||||
|
||||
elif [[ "${architecture}" == "armel" ]]; then
|
||||
qemu_bin="/usr/bin/qemu-arm-static"
|
||||
lib_arch="arm-linux-gnueabi"
|
||||
qemu_bin="/usr/bin/qemu-arm-static"
|
||||
lib_arch="arm-linux-gnueabi"
|
||||
|
||||
fi
|
||||
|
||||
# create the rootfs - not much to modify here, except maybe throw in some more packages if you want.
|
||||
# Create the rootfs - not much to modify here, except maybe throw in some more packages if you want.
|
||||
eatmydata debootstrap --foreign --keyring=/usr/share/keyrings/kali-archive-keyring.gpg --include=kali-archive-keyring,eatmydata \
|
||||
--components=${components} --arch ${architecture} ${suite} ${work_dir} http://http.kali.org/kali
|
||||
|
||||
# systemd-nspawn enviroment
|
||||
systemd-nspawn_exec(){
|
||||
systemd-nspawn_exec() {
|
||||
LANG=C systemd-nspawn -q --bind-ro ${qemu_bin} -M ${machine} -D ${work_dir} "$@"
|
||||
}
|
||||
|
||||
# We need to manually extract eatmydata to use it for the second stage.
|
||||
for archive in ${work_dir}/var/cache/apt/archives/*eatmydata*.deb; do
|
||||
dpkg-deb --fsys-tarfile "$archive" > ${work_dir}/eatmydata
|
||||
dpkg-deb --fsys-tarfile "$archive" >${work_dir}/eatmydata
|
||||
tar -xkf ${work_dir}/eatmydata -C ${work_dir}
|
||||
rm -f ${work_dir}/eatmydata
|
||||
|
||||
done
|
||||
|
||||
# Prepare dpkg to use eatmydata
|
||||
systemd-nspawn_exec dpkg-divert --divert /usr/bin/dpkg-eatmydata --rename --add /usr/bin/dpkg
|
||||
|
||||
cat > ${work_dir}/usr/bin/dpkg << EOF
|
||||
cat >${work_dir}/usr/bin/dpkg <<EOF
|
||||
#!/bin/sh
|
||||
if [ -e /usr/lib/${lib_arch}/libeatmydata.so ]; then
|
||||
[ -n "\${LD_PRELOAD}" ] && LD_PRELOAD="\$LD_PRELOAD:"
|
||||
@@ -161,21 +192,22 @@ done
|
||||
export LD_PRELOAD
|
||||
exec "\$0-eatmydata" --force-unsafe-io "\$@"
|
||||
EOF
|
||||
|
||||
chmod 755 ${work_dir}/usr/bin/dpkg
|
||||
|
||||
# debootstrap second stage
|
||||
systemd-nspawn_exec eatmydata /debootstrap/debootstrap --second-stage
|
||||
|
||||
cat << EOF > ${work_dir}/etc/apt/sources.list
|
||||
cat <<EOF >${work_dir}/etc/apt/sources.list
|
||||
deb ${mirror} ${suite} ${components//,/ }
|
||||
#deb-src ${mirror} ${suite} ${components//,/ }
|
||||
EOF
|
||||
|
||||
# Set hostname
|
||||
echo "${hostname}" > ${work_dir}/etc/hostname
|
||||
echo "${hostname}" >${work_dir}/etc/hostname
|
||||
|
||||
# So X doesn't complain, we add kali to hosts
|
||||
cat << EOF > ${work_dir}/etc/hosts
|
||||
cat <<EOF >${work_dir}/etc/hosts
|
||||
127.0.0.1 ${hostname} localhost
|
||||
::1 localhost ip6-localhost ip6-loopback
|
||||
fe00::0 ip6-localnet
|
||||
@@ -185,12 +217,12 @@ ff02::2 ip6-allrouters
|
||||
EOF
|
||||
|
||||
# Disable IPv6
|
||||
cat << EOF > ${work_dir}/etc/modprobe.d/ipv6.conf
|
||||
cat <<EOF >${work_dir}/etc/modprobe.d/ipv6.conf
|
||||
# Don't load ipv6 by default
|
||||
alias net-pf-10 off
|
||||
EOF
|
||||
|
||||
cat << EOF > ${work_dir}/etc/network/interfaces
|
||||
cat <<EOF >${work_dir}/etc/network/interfaces
|
||||
auto lo
|
||||
iface lo inet loopback
|
||||
|
||||
@@ -200,7 +232,7 @@ iface eth0 inet dhcp
|
||||
EOF
|
||||
|
||||
# DNS server
|
||||
echo "nameserver 8.8.8.8" > ${work_dir}/etc/resolv.conf
|
||||
echo "nameserver 8.8.8.8" >${work_dir}/etc/resolv.conf
|
||||
|
||||
# Copy directory bsp into build dir.
|
||||
cp -rp bsp ${work_dir}
|
||||
@@ -209,11 +241,12 @@ export MALLOC_CHECK_=0 # workaround for LP: #520465
|
||||
|
||||
# Enable the use of http proxy in third-stage in case it is enabled.
|
||||
if [ -n "$proxy_url" ]; then
|
||||
echo "Acquire::http { Proxy \"$proxy_url\" };" > ${work_dir}/etc/apt/apt.conf.d/66proxy
|
||||
echo "Acquire::http { Proxy \"$proxy_url\" };" >${work_dir}/etc/apt/apt.conf.d/66proxy
|
||||
|
||||
fi
|
||||
|
||||
# Third stage
|
||||
cat << EOF > ${work_dir}/third-stage
|
||||
cat <<EOF >${work_dir}/third-stage
|
||||
#!/bin/bash -e
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
@@ -333,7 +366,7 @@ systemd-nspawn_exec /third-stage
|
||||
systemd-nspawn_exec dpkg-divert --remove --rename /usr/bin/dpkg
|
||||
|
||||
# Clean system
|
||||
systemd-nspawn_exec << 'EOF'
|
||||
systemd-nspawn_exec <<'EOF'
|
||||
rm -f /0
|
||||
rm -rf /bsp
|
||||
fc-cache -frs
|
||||
@@ -356,29 +389,31 @@ EOF
|
||||
if [ -n "$proxy_url" ]; then
|
||||
unset http_proxy
|
||||
rm -rf ${work_dir}/etc/apt/apt.conf.d/66proxy
|
||||
|
||||
fi
|
||||
|
||||
# Mirror & suite replacement
|
||||
if [[ ! -z "${4}" || ! -z "${5}" ]]; then
|
||||
mirror=${4}
|
||||
suite=${5}
|
||||
|
||||
fi
|
||||
|
||||
# Create cmdline.txt file
|
||||
cat << EOF > ${work_dir}/boot/cmdline.txt
|
||||
cat <<EOF >${work_dir}/boot/cmdline.txt
|
||||
dwc_otg.fiq_fix_enable=2 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=$fstype rootwait rootflags=noload net.ifnames=0
|
||||
EOF
|
||||
|
||||
# systemd doesn't seem to be generating the fstab properly for some people, so
|
||||
# let's create one.
|
||||
cat << EOF > ${work_dir}/etc/fstab
|
||||
cat <<EOF >${work_dir}/etc/fstab
|
||||
# <file system> <mount point> <type> <options> <dump> <pass>
|
||||
proc /proc proc defaults 0 0
|
||||
/dev/mmcblk0p1 /boot vfat defaults 0 2
|
||||
EOF
|
||||
|
||||
# Define sources.list
|
||||
cat << EOF > ${work_dir}/etc/apt/sources.list
|
||||
cat <<EOF >${work_dir}/etc/apt/sources.list
|
||||
deb ${mirror} ${suite} ${components//,/ }
|
||||
#deb-src ${mirror} ${suite} ${components//,/ }
|
||||
EOF
|
||||
@@ -386,20 +421,21 @@ EOF
|
||||
# Copy a default config, with everything commented out so people find it when
|
||||
# they go to add something when they are following instructions on a website.
|
||||
cp ./bsp/firmware/rpi/config.txt ${work_dir}/boot/config.txt
|
||||
|
||||
# Remove repeat conditional filters [all] in config.txt
|
||||
sed -i "59,66d" ${work_dir}/boot/config.txt
|
||||
|
||||
|
||||
cd "${basedir}"
|
||||
|
||||
# Calculate the space to create the image.
|
||||
root_size=$(du -s -B1 ${work_dir} --exclude=${work_dir}/boot | cut -f1)
|
||||
root_extra=$((${root_size}/1024/1000*5*1024/5))
|
||||
raw_size=$(($((${free_space}*1024))+${root_extra}+$((${bootsize}*1024))+4096))
|
||||
root_extra=$((${root_size} / 1024 / 1000 * 5 * 1024 / 5))
|
||||
raw_size=$(($((${free_space} * 1024)) + ${root_extra} + $((${bootsize} * 1024)) + 4096))
|
||||
|
||||
# Create the disk and partition it
|
||||
echo "Creating image file ${imagename}.img"
|
||||
fallocate -l $(echo ${raw_size}Ki | numfmt --from=iec-i --to=si) ${repo_dir}/${imagename}.img
|
||||
|
||||
parted -s ${repo_dir}/${imagename}.img mklabel msdos
|
||||
parted -s ${repo_dir}/${imagename}.img mkpart primary fat32 1MiB ${bootsize}MiB
|
||||
parted -s -a minimal ${repo_dir}/${imagename}.img mkpart primary $fstype ${bootsize}MiB 100%
|
||||
@@ -413,25 +449,29 @@ rootp="${loopdevice}p2"
|
||||
mkfs.vfat -n BOOT -F 32 -v ${bootp}
|
||||
if [[ $fstype == ext4 ]]; then
|
||||
features="-O ^64bit,^metadata_csum"
|
||||
|
||||
elif [[ $fstype == ext3 ]]; then
|
||||
features="-O ^64bit"
|
||||
|
||||
fi
|
||||
|
||||
mkfs $features -t $fstype -L ROOTFS ${rootp}
|
||||
|
||||
# Create the dirs for the partitions and mount them
|
||||
mkdir -p ${basedir}/root/
|
||||
mount ${rootp} ${basedir}/root
|
||||
|
||||
mkdir -p ${basedir}/root/boot
|
||||
mount ${bootp} ${basedir}/root/boot
|
||||
|
||||
# We do this down here to get rid of the build system's resolv.conf after running through the build.
|
||||
cat << EOF > ${work_dir}/etc/resolv.conf
|
||||
cat <<EOF >${work_dir}/etc/resolv.conf
|
||||
nameserver 8.8.8.8
|
||||
EOF
|
||||
|
||||
# Create an fstab so that we don't mount / read-only.
|
||||
UUID=$(blkid -s UUID -o value ${rootp})
|
||||
echo "UUID=$UUID / $fstype errors=remount-ro 0 1" >> ${work_dir}/etc/fstab
|
||||
echo "UUID=$UUID / $fstype errors=remount-ro 0 1" >>${work_dir}/etc/fstab
|
||||
|
||||
echo "Rsyncing rootfs into image file"
|
||||
rsync -HPavz -q ${work_dir}/ ${basedir}/root/
|
||||
@@ -444,22 +484,31 @@ kpartx -dv ${loopdevice}
|
||||
losetup -d ${loopdevice}
|
||||
|
||||
# Limite use cpu function
|
||||
limit_cpu (){
|
||||
rand=$(tr -cd 'A-Za-z0-9' < /dev/urandom | head -c4 ; echo) # Randowm name group
|
||||
cgcreate -g cpu:/cpulimit-${rand} # Name of group cpulimit
|
||||
cgset -r cpu.shares=800 cpulimit-${rand} # Max 1024
|
||||
limit_cpu() {
|
||||
rand=$(
|
||||
tr -cd 'A-Za-z0-9' </dev/urandom | head -c4
|
||||
echo
|
||||
) # Randowm name group
|
||||
cgcreate -g cpu:/cpulimit-${rand} # Name of group cpulimit
|
||||
cgset -r cpu.shares=800 cpulimit-${rand} # Max 1024
|
||||
cgset -r cpu.cfs_quota_us=80000 cpulimit-${rand} # Max 100000
|
||||
|
||||
# Retry command
|
||||
local n=1; local max=5; local delay=2
|
||||
local n=1
|
||||
local max=5
|
||||
local delay=2
|
||||
|
||||
while true; do
|
||||
cgexec -g cpu:cpulimit-${rand} "$@" && break || {
|
||||
if [[ $n -lt $max ]]; then
|
||||
((n++))
|
||||
echo -e "\e[31m Command failed. Attempt $n/$max \033[0m"
|
||||
sleep $delay;
|
||||
sleep $delay
|
||||
|
||||
else
|
||||
echo "The command has failed after $n attempts."
|
||||
break
|
||||
|
||||
fi
|
||||
}
|
||||
done
|
||||
@@ -468,12 +517,15 @@ limit_cpu (){
|
||||
if [ $compress = xz ]; then
|
||||
if [ $(arch) == 'x86_64' ]; then
|
||||
echo "Compressing ${imagename}.img"
|
||||
[ $(nproc) \< 3 ] || cpu_cores=3 # cpu_cores = Number of cores to use
|
||||
[ $(nproc) \< 3 ] || cpu_cores=3 # cpu_cores = Number of cores to use
|
||||
limit_cpu pixz -p ${cpu_cores:-2} ${repo_dir}/${imagename}.img # -p Nº cpu cores use
|
||||
chmod 644 ${repo_dir}/${imagename}.img.xz
|
||||
|
||||
fi
|
||||
|
||||
else
|
||||
chmod 644 ${repo_dir}/${imagename}.img
|
||||
|
||||
fi
|
||||
|
||||
# Clean up all the temporary build stuff and remove the directories.
|
||||
|
||||
Reference in New Issue
Block a user