Update and fix bash syntax of archived scripts
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
|
||||
echo "This script is now deprecated" >&2
|
||||
echo "The kernel is too old to run systemd" >&2
|
||||
|
||||
sleep 5s
|
||||
|
||||
set -e
|
||||
@@ -16,19 +17,23 @@ set -e
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
echo "This script must be run as root"
|
||||
exit 1
|
||||
|
||||
fi
|
||||
|
||||
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
|
||||
|
||||
@@ -41,7 +46,9 @@ export CROSS_COMPILE=arm-linux-gnueabihf-
|
||||
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,11 +94,11 @@ 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
|
||||
deb http://${mirror}/kali moto main contrib non-free
|
||||
EOF
|
||||
|
||||
|
||||
echo "${hostname}" >kali-${architecture}/etc/hostname
|
||||
|
||||
# So X doesn't complain, we add kali to hosts
|
||||
@@ -104,6 +112,7 @@ ff02::2 ip6-allrouters
|
||||
EOF
|
||||
|
||||
mkdir -p kali-${architecture}/etc/network/
|
||||
|
||||
cat <<EOF >kali-${architecture}/etc/network/interfaces
|
||||
auto lo
|
||||
iface lo inet loopback
|
||||
@@ -167,6 +176,7 @@ 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
|
||||
@@ -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
|
||||
@@ -222,15 +233,22 @@ 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
|
||||
|
||||
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
|
||||
@@ -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,10 +297,12 @@ 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
|
||||
|
||||
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
|
||||
@@ -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
|
||||
|
||||
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
|
||||
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"
|
||||
@@ -101,12 +124,15 @@ packages="${arm} ${base} ${services}"
|
||||
# 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')"}
|
||||
|
||||
if [ -n "$proxy_url" ]; then
|
||||
export http_proxy=$proxy_url
|
||||
|
||||
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
|
||||
|
||||
@@ -114,15 +140,17 @@ fi
|
||||
if [[ "${architecture}" == "arm64" ]]; then
|
||||
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"
|
||||
|
||||
elif [[ "${architecture}" == "armel" ]]; then
|
||||
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
|
||||
|
||||
@@ -136,6 +164,7 @@ for archive in ${work_dir}/var/cache/apt/archives/*eatmydata*.deb; do
|
||||
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
|
||||
@@ -176,6 +205,7 @@ ff02::2 ip6-allrouters
|
||||
EOF
|
||||
|
||||
mkdir -p ${work_dir}/etc/network/
|
||||
|
||||
cat <<EOF >${work_dir}/etc/network/interfaces
|
||||
auto lo
|
||||
iface lo inet loopback
|
||||
@@ -203,6 +233,7 @@ 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
|
||||
|
||||
fi
|
||||
|
||||
# Third stage
|
||||
@@ -314,12 +345,14 @@ 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
|
||||
@@ -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
|
||||
@@ -477,21 +513,30 @@ losetup -d ${loopdevice}
|
||||
|
||||
# Limite use cpu function
|
||||
limit_cpu() {
|
||||
rand=$(tr -cd 'A-Za-z0-9' < /dev/urandom | head -c4 ; echo) # Randowm name group
|
||||
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
|
||||
@@ -503,9 +548,12 @@ if [ $compress = xz ]; then
|
||||
[ $(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:-"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
|
||||
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"
|
||||
@@ -101,12 +124,15 @@ packages="${arm} ${base} ${services}"
|
||||
# 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')"}
|
||||
|
||||
if [ -n "$proxy_url" ]; then
|
||||
export http_proxy=$proxy_url
|
||||
|
||||
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
|
||||
|
||||
@@ -114,15 +140,18 @@ fi
|
||||
if [[ "${architecture}" == "arm64" ]]; then
|
||||
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"
|
||||
|
||||
elif [[ "${architecture}" == "armel" ]]; then
|
||||
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
|
||||
|
||||
@@ -136,6 +165,7 @@ for archive in ${work_dir}/var/cache/apt/archives/*eatmydata*.deb; do
|
||||
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
|
||||
@@ -154,6 +184,7 @@ done
|
||||
export LD_PRELOAD
|
||||
exec "\$0-eatmydata" --force-unsafe-io "\$@"
|
||||
EOF
|
||||
|
||||
chmod 755 ${work_dir}/usr/bin/dpkg
|
||||
|
||||
# debootstrap second stage
|
||||
@@ -203,6 +234,7 @@ 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
|
||||
|
||||
fi
|
||||
|
||||
# Third stage
|
||||
@@ -313,12 +345,14 @@ 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
|
||||
@@ -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,16 +442,21 @@ 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
|
||||
|
||||
@@ -442,21 +481,30 @@ losetup -d ${loopdevice}
|
||||
|
||||
# Limite use cpu function
|
||||
limit_cpu() {
|
||||
rand=$(tr -cd 'A-Za-z0-9' < /dev/urandom | head -c4 ; echo) # Randowm name group
|
||||
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,9 +516,12 @@ if [ $compress = xz ]; then
|
||||
[ $(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
|
||||
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"
|
||||
@@ -101,6 +124,7 @@ packages="${arm} ${base} ${services}"
|
||||
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.
|
||||
@@ -109,12 +133,15 @@ fi
|
||||
# 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')"}
|
||||
|
||||
if [ -n "$proxy_url" ]; then
|
||||
export http_proxy=$proxy_url
|
||||
|
||||
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
|
||||
|
||||
@@ -122,17 +149,20 @@ fi
|
||||
if [[ "${architecture}" == "arm64" ]]; then
|
||||
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"
|
||||
|
||||
elif [[ "${architecture}" == "armel" ]]; then
|
||||
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() {
|
||||
@@ -144,6 +174,7 @@ for archive in ${work_dir}/var/cache/apt/archives/*eatmydata*.deb; do
|
||||
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
|
||||
@@ -211,6 +242,7 @@ 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
|
||||
|
||||
fi
|
||||
|
||||
# Third stage
|
||||
@@ -356,12 +388,14 @@ 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
|
||||
@@ -387,6 +421,7 @@ 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
|
||||
|
||||
@@ -423,6 +458,7 @@ 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,14 +472,18 @@ 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
|
||||
|
||||
@@ -468,21 +508,30 @@ losetup -d ${loopdevice}
|
||||
|
||||
# Limite use cpu function
|
||||
limit_cpu() {
|
||||
rand=$(tr -cd 'A-Za-z0-9' < /dev/urandom | head -c4 ; echo) # Randowm name group
|
||||
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
|
||||
@@ -494,9 +543,12 @@ if [ $compress = xz ]; then
|
||||
[ $(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
|
||||
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"
|
||||
@@ -100,6 +123,7 @@ packages="${arm} ${base} ${services}"
|
||||
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.
|
||||
@@ -108,12 +132,15 @@ fi
|
||||
# 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')"}
|
||||
|
||||
if [ -n "$proxy_url" ]; then
|
||||
export http_proxy=$proxy_url
|
||||
|
||||
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
|
||||
|
||||
@@ -121,15 +148,18 @@ fi
|
||||
if [[ "${architecture}" == "arm64" ]]; then
|
||||
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"
|
||||
|
||||
elif [[ "${architecture}" == "armel" ]]; then
|
||||
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
|
||||
|
||||
@@ -143,6 +173,7 @@ for archive in ${work_dir}/var/cache/apt/archives/*eatmydata*.deb; do
|
||||
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
|
||||
@@ -161,6 +192,7 @@ done
|
||||
export LD_PRELOAD
|
||||
exec "\$0-eatmydata" --force-unsafe-io "\$@"
|
||||
EOF
|
||||
|
||||
chmod 755 ${work_dir}/usr/bin/dpkg
|
||||
|
||||
# debootstrap second stage
|
||||
@@ -210,6 +242,7 @@ 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
|
||||
|
||||
fi
|
||||
|
||||
# Third stage
|
||||
@@ -356,12 +389,14 @@ 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
|
||||
@@ -386,10 +421,10 @@ 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.
|
||||
@@ -400,6 +435,7 @@ 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,14 +449,18 @@ 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
|
||||
|
||||
@@ -445,21 +485,30 @@ losetup -d ${loopdevice}
|
||||
|
||||
# Limite use cpu function
|
||||
limit_cpu() {
|
||||
rand=$(tr -cd 'A-Za-z0-9' < /dev/urandom | head -c4 ; echo) # Randowm name group
|
||||
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
|
||||
@@ -471,9 +520,12 @@ if [ $compress = xz ]; then
|
||||
[ $(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