nyan: New script
This commit is contained in:
@@ -1,54 +1,75 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
echo "This script must be run as root"
|
||||
exit 1
|
||||
# Uncomment to activate debug
|
||||
# debug=true
|
||||
|
||||
if [ "$debug" = true ]; then
|
||||
exec > >(tee -a -i "${0%.*}.log") 2>&1
|
||||
set -x
|
||||
fi
|
||||
|
||||
if [[ $# -eq 0 ]] ; then
|
||||
echo "Please pass version number, e.g. $0 2.0"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
basedir=`pwd`/nyan-$1
|
||||
|
||||
# Architecture
|
||||
architecture=${architecture:-"armhf"}
|
||||
# Generate a random machine name to be used.
|
||||
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-nyan}
|
||||
# Size of image in megabytes (Default is 14000=14GB)
|
||||
size=14000
|
||||
# Suite to use.
|
||||
# Valid options are:
|
||||
# Suite to use, valid options are:
|
||||
# kali-rolling, kali-dev, kali-bleeding-edge, kali-dev-only, kali-experimental, kali-last-snapshot
|
||||
# A release is done against kali-last-snapshot, but if you're building your own, you'll probably want to build
|
||||
# kali-rolling.
|
||||
suite=kali-rolling
|
||||
suite=${suite:-"kali-rolling"}
|
||||
# Free space rootfs in MiB
|
||||
free_space="300"
|
||||
# /boot partition in MiB
|
||||
bootsize="128"
|
||||
# If you have your own preferred mirrors, set them here.
|
||||
mirror="http://http.kali.org/kali"
|
||||
# Gitlab url Kali repository
|
||||
kaligit="https://gitlab.com/kalilinux"
|
||||
# Github raw url
|
||||
githubraw="https://raw.githubusercontent.com"
|
||||
|
||||
# Generate a random machine name to be used.
|
||||
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
|
||||
echo "Missing cross compiler. Set up PATH according to the README"
|
||||
exit 1
|
||||
# Check EUID=0 you can run any binary as root.
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
echo "This script must be run as root"
|
||||
exit 1
|
||||
fi
|
||||
# Unset CROSS_COMPILE so that if there is any native compiling needed it doesn't
|
||||
# get cross compiled.
|
||||
unset CROSS_COMPILE
|
||||
|
||||
# Package installations for various sections.
|
||||
# This will build a minimal Gnome Kali system with the top 10 tools.
|
||||
# This is the section to edit if you would like to add more packages.
|
||||
# See http://www.kali.org/new/kali-linux-metapackages/ for meta packages you can
|
||||
# use. You can also install packages, using just the package name, but keep in
|
||||
# mind that not all packages work on ARM! If you specify one of those, the
|
||||
# script will throw an error, but will still continue on, and create an unusable
|
||||
# image, keep that in mind.
|
||||
# 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.
|
||||
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
|
||||
current_dir="$(pwd)"
|
||||
# Base directory
|
||||
basedir=${current_dir}/nyan-"$1"
|
||||
# Working directory
|
||||
work_dir="${basedir}/kali-${architecture}"
|
||||
|
||||
# Check directory build
|
||||
if [ -e "${basedir}" ]; then
|
||||
echo "${basedir} directory exists, will not continue"
|
||||
exit 1
|
||||
elif [[ ${current_dir} =~ [[:space:]] ]]; then
|
||||
echo "The directory "\"${current_dir}"\" contains whitespace. Not supported."
|
||||
exit 1
|
||||
else
|
||||
echo "The basedir thinks it is: ${basedir}"
|
||||
mkdir -p ${basedir}
|
||||
fi
|
||||
|
||||
components="main,contrib,non-free"
|
||||
arm="kali-linux-arm ntpdate"
|
||||
base="apt-transport-https apt-utils bash-completion console-setup dialog e2fsprogs ifupdown initramfs-tools inxi iw man-db mlocate netcat-traditional net-tools parted pciutils psmisc rfkill screen tmux unrar usbutils vim wget whiptail zerofree"
|
||||
desktop="kali-desktop-xfce kali-root-login xserver-xorg-video-fbdev xserver-xorg-input-libinput xserver-xorg-input-synaptics xfonts-terminus xinput"
|
||||
@@ -57,37 +78,47 @@ services="apache2 atftpd"
|
||||
extras="alsa-utils bc bison bluez bluez-firmware kali-linux-core libnss-systemd libssl-dev triggerhappy"
|
||||
|
||||
packages="${arm} ${base} ${services}"
|
||||
architecture="armhf"
|
||||
# If you have your own preferred mirrors, set them here.
|
||||
# After generating the rootfs, we set the sources.list to the default settings.
|
||||
mirror=http.kali.org
|
||||
|
||||
kernel_release="R71-11151.B-chromeos-3.10"
|
||||
|
||||
# Set this to use an http proxy, like apt-cacher-ng, and uncomment further down
|
||||
# to unset it.
|
||||
#export http_proxy="http://localhost:3142/"
|
||||
|
||||
mkdir -p "${basedir}"
|
||||
cd "${basedir}"
|
||||
# Automatic configuration to use an http proxy, such as apt-cacher-ng.
|
||||
# You can turn off automatic settings by uncommenting apt_cacher=off.
|
||||
# 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')"}
|
||||
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
|
||||
|
||||
# create the rootfs - not much to modify here, except maybe throw in some more packages if you want.
|
||||
debootstrap --foreign --keyring=/usr/share/keyrings/kali-archive-keyring.gpg --include=kali-archive-keyring --arch ${architecture} ${suite} kali-${architecture} http://${mirror}/kali
|
||||
debootstrap --foreign --keyring=/usr/share/keyrings/kali-archive-keyring.gpg --include=kali-archive-keyring \
|
||||
--components=${components} --arch ${architecture} ${suite} ${work_dir} http://http.kali.org/kali
|
||||
|
||||
cp /usr/bin/qemu-arm-static kali-${architecture}/usr/bin/
|
||||
# systemd-nspawn enviroment
|
||||
systemd-nspawn_exec(){
|
||||
qemu_bin=/usr/bin/qemu-arm-static
|
||||
LANG=C systemd-nspawn -q --bind-ro ${qemu_bin} -M ${machine} -D ${work_dir} "$@"
|
||||
}
|
||||
|
||||
LANG=C systemd-nspawn -M ${machine} -D kali-${architecture} /debootstrap/debootstrap --second-stage
|
||||
# debootstrap second stage
|
||||
systemd-nspawn_exec /debootstrap/debootstrap --second-stage
|
||||
|
||||
mkdir -p kali-${architecture}/etc/apt/
|
||||
cat << EOF > kali-${architecture}/etc/apt/sources.list
|
||||
deb http://${mirror}/kali ${suite} main contrib non-free
|
||||
cat << EOF > ${work_dir}/etc/apt/sources.list
|
||||
deb ${mirror} ${suite} ${components//,/ }
|
||||
#deb-src ${mirror} ${suite} ${components//,/ }
|
||||
EOF
|
||||
|
||||
# Set hostname
|
||||
echo "${hostname}" > kali-${architecture}/etc/hostname
|
||||
echo "${hostname}" > ${work_dir}/etc/hostname
|
||||
|
||||
# So X doesn't complain, we add kali to hosts
|
||||
cat << EOF > kali-${architecture}/etc/hosts
|
||||
cat << EOF > ${work_dir}/etc/hosts
|
||||
127.0.0.1 ${hostname} localhost
|
||||
::1 localhost ip6-localhost ip6-loopback
|
||||
fe00::0 ip6-localnet
|
||||
@@ -96,47 +127,42 @@ ff02::1 ip6-allnodes
|
||||
ff02::2 ip6-allrouters
|
||||
EOF
|
||||
|
||||
mkdir -p kali-${architecture}/etc/network/
|
||||
cat << EOF > kali-${architecture}/etc/network/interfaces
|
||||
# Disable IPv6
|
||||
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
|
||||
auto lo
|
||||
iface lo inet loopback
|
||||
EOF
|
||||
|
||||
cat << EOF > kali-${architecture}/etc/resolv.conf
|
||||
nameserver 8.8.8.8
|
||||
EOF
|
||||
# DNS server
|
||||
echo "nameserver 8.8.8.8" > ${work_dir}/etc/resolv.conf
|
||||
|
||||
# Copy directory bsp into build dir.
|
||||
cp -rp bsp ${work_dir}
|
||||
|
||||
export MALLOC_CHECK_=0 # workaround for LP: #520465
|
||||
export LC_ALL=C
|
||||
|
||||
# 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
|
||||
cat << EOF > ${work_dir}/third-stage
|
||||
#!/bin/bash -e
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
#mount -t proc proc kali-$architecture/proc
|
||||
#mount -o bind /dev/ kali-$architecture/dev/
|
||||
#mount -o bind /dev/pts kali-$architecture/dev/pts
|
||||
|
||||
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
|
||||
|
||||
mkdir -p kali-${architecture}/usr/lib/systemd/system/
|
||||
cp "${basedir}"/../bsp/services/all/*.service kali-${architecture}/usr/lib/systemd/system/
|
||||
|
||||
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
|
||||
cp /bin/true /usr/sbin/invoke-rc.d
|
||||
export RUNLEVEL=1
|
||||
ln -sf /bin/true /usr/sbin/invoke-rc.d
|
||||
echo -e "#!/bin/sh\nexit 101" > /usr/sbin/policy-rc.d
|
||||
chmod 755 /usr/sbin/policy-rc.d
|
||||
|
||||
apt-get update
|
||||
|
||||
debconf-set-selections /debconf.set
|
||||
rm -f /debconf.set
|
||||
apt-get update
|
||||
apt-get -y install git-core binutils ca-certificates cryptsetup-bin initramfs-tools u-boot-tools
|
||||
apt-get -y install locales console-common less nano git
|
||||
apt-get -y install binutils ca-certificates console-common cryptsetup-bin git initramfs-tools less locales nano u-boot-tools
|
||||
|
||||
# Create kali user with kali password... but first, we need to manually make some groups because they don't yet exist...
|
||||
# This mirrors what we have on a pre-installed VM, until the script works properly to allow end users to set up their own... user.
|
||||
@@ -152,16 +178,25 @@ groupadd -g 1000 kali
|
||||
useradd -m -u 1000 -g 1000 -G sudo,audio,bluetooth,cdrom,dialout,dip,lpadmin,netdev,plugdev,scanner,video,kali -s /bin/bash kali
|
||||
echo "kali:kali" | chpasswd
|
||||
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
aptops="--allow-change-held-packages -o dpkg::options::=--force-confnew"
|
||||
|
||||
# This looks weird, but we do it twice because every so often, there's a failure to download from the mirror
|
||||
# So to workaround it, we attempt to install them twice.
|
||||
apt-get --yes --allow-change-held-packages -o dpkg::options::=--force-confnew install ${packages} || apt-get --yes --fix-broken install
|
||||
apt-get --yes --allow-change-held-packages -o dpkg::options::=--force-confnew install ${packages} || apt-get --yes --fix-broken install
|
||||
apt-get --yes --allow-change-held-packages -o dpkg::options::=--force-confnew install ${desktop} ${extras} ${tools} || apt-get --yes --fix-broken install
|
||||
apt-get --yes --allow-change-held-packages -o dpkg::options::=--force-confnew install ${desktop} ${extras} ${tools} || apt-get --yes --fix-broken install
|
||||
apt-get --yes --allow-change-held-packages --autoremove install systemd-timesyncd || apt-get --yes --fix-broken install
|
||||
apt-get --yes --allow-change-held-packages -o dpkg::options::=--force-confnew dist-upgrade
|
||||
apt-get --yes --allow-change-held-packages -o dpkg::options::=--force-confnew autoremove
|
||||
apt-get install -y \$aptops ${packages} || apt-get --yes --fix-broken install
|
||||
apt-get install -y \$aptops ${packages} || apt-get --yes --fix-broken install
|
||||
apt-get install -y \$aptops ${desktop} ${extras} ${tools} || apt-get --yes --fix-broken install
|
||||
apt-get install -y \$aptops ${desktop} ${extras} ${tools} || apt-get --yes --fix-broken install
|
||||
apt-get install -y \$aptops --autoremove systemd-timesyncd || apt-get --yes --fix-broken install
|
||||
apt-get dist-upgrade -y \$aptops
|
||||
|
||||
apt-get -y --allow-change-held-packages --purge autoremove
|
||||
|
||||
# Linux console/Keyboard configuration
|
||||
echo 'console-common console-data/keymap/policy select Select keymap from full list' | debconf-set-selections
|
||||
echo 'console-common console-data/keymap/full select en-latin1-nodeadkeys' | debconf-set-selections
|
||||
|
||||
# Copy all services
|
||||
cp -p /bsp/services/all/*.service /etc/systemd/system/
|
||||
|
||||
# Regenerated the shared-mime-info database on the first boot
|
||||
# since it fails to do so properly in a chroot.
|
||||
@@ -169,59 +204,71 @@ systemctl enable smi-hack
|
||||
|
||||
# Generate SSH host keys on first run
|
||||
systemctl enable regenerate_ssh_host_keys
|
||||
# Enable sshd
|
||||
systemctl enable ssh
|
||||
|
||||
# Copy over the default bashrc
|
||||
cp /etc/skel/.bashrc /root/.bashrc
|
||||
|
||||
cd /root
|
||||
apt download ca-certificates
|
||||
apt download libgdk-pixbuf2.0-0
|
||||
apt download fontconfig
|
||||
apt download -o APT::Sandbox::User=root ca-certificates 2>/dev/null
|
||||
|
||||
# Copy over the default bashrc
|
||||
cp /etc/skel/.bashrc /root/.bashrc
|
||||
|
||||
# Set a REGDOMAIN. This needs to be done or wireless doesn't work correctly on the RPi 3B+
|
||||
sed -i -e 's/REGDOM.*/REGDOMAIN=00/g' /etc/default/crda
|
||||
|
||||
# Enable login over serial
|
||||
echo "T0:23:respawn:/sbin/agetty -L ttyAMA0 115200 vt100" >> /etc/inittab
|
||||
|
||||
# Try and make the console a bit nicer
|
||||
# Set the terminus font for a bit nicer display.
|
||||
sed -i -e 's/FONTFACE=.*/FONTFACE="Terminus"/' /etc/default/console-setup
|
||||
sed -i -e 's/FONTSIZE=.*/FONTSIZE="6x12"/' /etc/default/console-setup
|
||||
|
||||
# Fix startup time from 5 minutes to 15 secs on raise interface wlan0
|
||||
sed -i 's/^TimeoutStartSec=5min/TimeoutStartSec=15/g' "/usr/lib/systemd/system/networking.service"
|
||||
|
||||
rm -f /usr/sbin/policy-rc.d
|
||||
rm -f /usr/sbin/invoke-rc.d
|
||||
dpkg-divert --remove --rename /usr/sbin/invoke-rc.d
|
||||
|
||||
rm -f /third-stage
|
||||
unlink /usr/sbin/invoke-rc.d
|
||||
EOF
|
||||
|
||||
chmod 755 kali-${architecture}/third-stage
|
||||
LANG=C systemd-nspawn -M ${machine} -D kali-${architecture} /third-stage
|
||||
# Run third stage
|
||||
chmod 755 ${work_dir}/third-stage
|
||||
systemd-nspawn_exec /third-stage
|
||||
|
||||
cat << EOF > kali-${architecture}/cleanup
|
||||
#!/bin/bash
|
||||
rm -rf /root/.bash_history
|
||||
apt-get update
|
||||
# Clean system
|
||||
systemd-nspawn_exec << EOF
|
||||
rm -f /0
|
||||
rm -f /hs_err*
|
||||
rm -f cleanup
|
||||
rm -f /usr/bin/qemu*
|
||||
rm -rf /bsp
|
||||
fc-cache -frs
|
||||
rm -rf /tmp/*
|
||||
rm -rf /etc/*-
|
||||
rm -rf /hs_err*
|
||||
rm -rf /userland
|
||||
rm -rf /opt/vc/src
|
||||
rm -f /etc/ssh/ssh_host_*
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
rm -rf /var/cache/apt/*.bin
|
||||
rm -rf /var/cache/apt/archives/*
|
||||
rm -rf /var/cache/debconf/*.data-old
|
||||
history -c
|
||||
EOF
|
||||
#Clear all logs
|
||||
for logs in `find $work_dir/var/log -type f`; do > $logs; done
|
||||
|
||||
chmod 755 kali-${architecture}/cleanup
|
||||
LANG=C systemd-nspawn -M ${machine} -D kali-${architecture} /cleanup
|
||||
# Disable the use of http proxy in case it is enabled.
|
||||
if [ -n "$proxy_url" ]; then
|
||||
unset http_proxy
|
||||
rm -rf ${work_dir}/etc/apt/apt.conf.d/66proxy
|
||||
fi
|
||||
|
||||
#umount kali-${architecture}/proc/sys/fs/binfmt_misc
|
||||
#umount kali-${architecture}/dev/pts
|
||||
#umount kali-${architecture}/dev/
|
||||
#umount kali-${architecture}/proc
|
||||
|
||||
cat << EOF > "${basedir}"/kali-${architecture}/etc/apt/sources.list
|
||||
cat << EOF > ${work_dir}/etc/apt/sources.list
|
||||
deb http://http.kali.org/kali kali-rolling main contrib non-free
|
||||
deb-src http://http.kali.org/kali kali-rolling main contrib non-free
|
||||
EOF
|
||||
|
||||
# Uncomment this if you use apt-cacher-ng otherwise git clones will fail.
|
||||
#unset http_proxy
|
||||
|
||||
# Pull in the gcc 5.3 cross compiler to build the kernel.
|
||||
# Debian uses a 7.3 based kernel, and the chromebook kernel doesn't support
|
||||
# Debian uses a newer compiler and the chromebook kernel doesn't support
|
||||
# that.
|
||||
cd "${basedir}"
|
||||
git clone --depth 1 https://gitlab.com/kalilinux/packages/gcc-arm-linux-gnueabihf-4-7.git gcc-arm-linux-gnueabihf-4.7
|
||||
@@ -229,24 +276,24 @@ git clone --depth 1 https://gitlab.com/kalilinux/packages/gcc-arm-linux-gnueabih
|
||||
# Kernel section. If you want to use a custom kernel, or configuration, replace
|
||||
# them in this section.
|
||||
cd "${basedir}"
|
||||
git clone --depth 1 https://chromium.googlesource.com/chromiumos/third_party/kernel -b release-${kernel_release} "${basedir}"/kali-${architecture}/usr/src/kernel
|
||||
cd "${basedir}"/kali-${architecture}/usr/src/kernel
|
||||
mkdir -p "${basedir}"/kali-${architecture}/usr/src/kernel/firmware/nvidia/tegra124/
|
||||
cp "${basedir}"/kali-${architecture}/lib/firmware/nvidia/tegra124/xusb.bin firmware/nvidia/tegra124/
|
||||
cp "${basedir}"/../kernel-configs/chromebook-3.10.config .config
|
||||
cp "${basedir}"/../kernel-configs/chromebook-3.10.config "${basedir}"/kali-${architecture}/usr/src/nyan.config
|
||||
git rev-parse HEAD > "${basedir}"/kali-${architecture}/usr/src/kernel-at-commit
|
||||
git clone --depth 1 https://chromium.googlesource.com/chromiumos/third_party/kernel -b release-${kernel_release} ${work_dir}/usr/src/kernel
|
||||
cd ${work_dir}/usr/src/kernel
|
||||
mkdir -p ${work_dir}/usr/src/kernel/firmware/nvidia/tegra124/
|
||||
cp ${work_dir}/lib/firmware/nvidia/tegra124/xusb.bin firmware/nvidia/tegra124/
|
||||
cp ${current_dir}/kernel-configs/chromebook-3.10.config .config
|
||||
cp ${current_dir}/kernel-configs/chromebook-3.10.config ${work_dir}/usr/src/nyan.config
|
||||
git rev-parse HEAD > ${work_dir}/usr/src/kernel-at-commit
|
||||
export ARCH=arm
|
||||
# Edit the CROSS_COMPILE variable as needed.
|
||||
export CROSS_COMPILE="${basedir}"/gcc-arm-linux-gnueabihf-4.7/bin/arm-linux-gnueabihf-
|
||||
patch -p1 --no-backup-if-mismatch < "${basedir}"/../patches/mac80211-3.8.patch
|
||||
patch -p1 --no-backup-if-mismatch < "${basedir}"/../patches/0001-mwifiex-do-not-create-AP-and-P2P-interfaces-upon-dri-3.8.patch
|
||||
patch -p1 --no-backup-if-mismatch < "${basedir}"/../patches/0001-Comment-out-a-pr_debug-print.patch
|
||||
patch -p1 --no-backup-if-mismatch < ${current_dir}/patches/mac80211-3.8.patch
|
||||
patch -p1 --no-backup-if-mismatch < ${work_dir}/patches/0001-mwifiex-do-not-create-AP-and-P2P-interfaces-upon-dri-3.8.patch
|
||||
patch -p1 --no-backup-if-mismatch < ${work_dir}/patches/0001-Comment-out-a-pr_debug-print.patch
|
||||
make WIFIVERSION="-3.8" oldconfig || die "Kernel config options added"
|
||||
make WIFIVERSION="-3.8" -j $(grep -c processor /proc/cpuinfo)
|
||||
make WIFIVERSION="-3.8" dtbs
|
||||
make WIFIVERSION="-3.8" modules_install INSTALL_MOD_PATH="${basedir}"/kali-${architecture}
|
||||
cat << __EOF__ > "${basedir}"/kali-${architecture}/usr/src/kernel/arch/arm/boot/kernel-nyan.its
|
||||
make WIFIVERSION="-3.8" modules_install INSTALL_MOD_PATH=${work_dir}
|
||||
cat << __EOF__ > ${work_dir}/usr/src/kernel/arch/arm/boot/kernel-nyan.its
|
||||
/dts-v1/;
|
||||
|
||||
/ {
|
||||
@@ -381,7 +428,7 @@ cat << __EOF__ > "${basedir}"/kali-${architecture}/usr/src/kernel/arch/arm/boot/
|
||||
};
|
||||
};
|
||||
__EOF__
|
||||
cd "${basedir}"/kali-${architecture}/usr/src/kernel/arch/arm/boot
|
||||
cd ${work_dir}/usr/src/kernel/arch/arm/boot
|
||||
mkimage -f kernel-nyan.its nyan-big-kernel
|
||||
|
||||
# BEHOLD THE POWER OF PARTUUID/PARTNROFF
|
||||
@@ -393,7 +440,7 @@ dd if=/dev/zero of=bootloader.bin bs=512 count=1
|
||||
|
||||
vbutil_kernel --arch arm --pack "${basedir}"/kernel.bin --keyblock /usr/share/vboot/devkeys/kernel.keyblock --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk --version 1 --config cmdline --bootloader bootloader.bin --vmlinuz nyan-big-kernel
|
||||
|
||||
cd "${basedir}"/kali-${architecture}/usr/src/kernel
|
||||
cd ${work_dir}/usr/src/kernel
|
||||
# Clean up our build of the kernel, then copy the config and run make
|
||||
# modules_prepare so that users can more easily build kernel modules...
|
||||
make WIFIVERSION="-3.8" mrproper
|
||||
@@ -403,8 +450,8 @@ cd "${basedir}"
|
||||
# Fix up the symlink for building external modules
|
||||
# kernver is used so we don't need to keep track of what the current compiled
|
||||
# version is
|
||||
kernver=$(ls "${basedir}"/kali-${architecture}/lib/modules/)
|
||||
cd "${basedir}"/kali-${architecture}/lib/modules/${kernver}
|
||||
kernver=$(ls ${work_dir}/lib/modules/)
|
||||
cd ${work_dir}/lib/modules/${kernver}
|
||||
rm build
|
||||
rm source
|
||||
ln -s /usr/src/kernel build
|
||||
@@ -412,23 +459,23 @@ ln -s /usr/src/kernel source
|
||||
cd "${basedir}"
|
||||
|
||||
# Lid switch
|
||||
cat << EOF > "${basedir}"/kali-${architecture}/etc/udev/rules.d/99-tegra-lid-switch.rules
|
||||
cat << EOF > ${work_dir}/etc/udev/rules.d/99-tegra-lid-switch.rules
|
||||
ACTION=="remove", GOTO="tegra_lid_switch_end"
|
||||
SUBSYSTEM=="input", KERNEL=="event*", SUBSYSTEMS=="platform", KERNELS=="gpio-keys.4", TAG+="power-switch"
|
||||
LABEL="tegra_lid_switch_end"
|
||||
EOF
|
||||
|
||||
# Bit of a hack, this is so the eMMC doesn't show up on the desktop
|
||||
cat << EOF > "${basedir}"/kali-${architecture}/etc/udev/rules.d/99-hide-emmc-partitions.rules
|
||||
cat << EOF > ${work_dir}/etc/udev/rules.d/99-hide-emmc-partitions.rules
|
||||
KERNEL=="mmcblk0*", ENV{UDISKS_IGNORE}="1"
|
||||
EOF
|
||||
|
||||
# Disable uap0 and p2p0 interfaces in NetworkManager
|
||||
mkdir -p "${basedir}"/kali-${architecture}/etc/NetworkManager/
|
||||
printf '\n[keyfile]\nunmanaged-devices=interface-name:p2p0\n' >> "${basedir}"/kali-${architecture}/etc/NetworkManager/NetworkManager.conf
|
||||
mkdir -p ${work_dir}/etc/NetworkManager/
|
||||
printf '\n[keyfile]\nunmanaged-devices=interface-name:p2p0\n' >> ${work_dir}/etc/NetworkManager/NetworkManager.conf
|
||||
|
||||
#nvidia device nodes
|
||||
cat << EOF > "${basedir}"/kali-${architecture}/lib/udev/rules.d/51-nvrm.rules
|
||||
cat << EOF > ${work_dir}/lib/udev/rules.d/51-nvrm.rules
|
||||
KERNEL=="knvmap", GROUP="video", MODE="0660"
|
||||
KERNEL=="nvhdcp1", GROUP="video", MODE="0660"
|
||||
KERNEL=="nvhost-as-gpu", GROUP="video", MODE="0660"
|
||||
@@ -447,8 +494,8 @@ KERNEL=="tegra_dc_ctrl", GROUP="video", MODE="0660"
|
||||
EOF
|
||||
|
||||
# Touchpad configuration
|
||||
mkdir -p "${basedir}"/kali-${architecture}/etc/X11/xorg.conf.d
|
||||
cp "${basedir}"/../bsp/xorg/10-synaptics-chromebook.conf "${basedir}"/kali-${architecture}/etc/X11/xorg.conf.d/
|
||||
mkdir -p ${work_dir}/etc/X11/xorg.conf.d
|
||||
cp ${current_dir}/bsp/xorg/10-synaptics-chromebook.conf ${work_dir}/etc/X11/xorg.conf.d/
|
||||
|
||||
# lp0 resume firmware...
|
||||
# Check https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/master/sys-kernel/tegra_lp0_resume/
|
||||
@@ -458,20 +505,27 @@ git clone https://chromium.googlesource.com/chromiumos/third_party/coreboot
|
||||
cd "${basedir}"/coreboot
|
||||
git checkout fb840ee4195f9c365375e8914e243ce2f5e4f7bf
|
||||
make -C src/soc/nvidia/tegra124/lp0 GCC_PREFIX=arm-linux-gnueabihf-
|
||||
mkdir -p "${basedir}"/kali-${architecture}/lib/firmware/tegra12x/
|
||||
cp src/soc/nvidia/tegra124/lp0/tegra_lp0_resume.fw "${basedir}"/kali-${architecture}/lib/firmware/tegra12x/
|
||||
mkdir -p ${work_dir}/lib/firmware/tegra12x/
|
||||
cp src/soc/nvidia/tegra124/lp0/tegra_lp0_resume.fw ${work_dir}/lib/firmware/tegra12x/
|
||||
cd "${basedir}"
|
||||
|
||||
sed -i -e 's/^#PermitRootLogin.*/PermitRootLogin yes/' "${basedir}"/kali-${architecture}/etc/ssh/sshd_config
|
||||
# Calculate the space to create the image.
|
||||
free_space=$((${free_space}*1024))
|
||||
bootstart=$((${bootsize}*1024/1000*2*1024/2))
|
||||
bootend=$((${bootstart}+1024))
|
||||
rootsize=$(du -s --block-size KiB ${work_dir} --exclude boot | cut -f1)
|
||||
rootsize=$((${free_space}+${rootsize//KiB/ }/1000*2*1024/2))
|
||||
raw_size=$((${free_space}+${rootsize}+${bootstart}))
|
||||
|
||||
echo "Creating image file for ${imagename}.img"
|
||||
dd if=/dev/zero of="${basedir}"/${imagename}.img bs=1M count=${size}
|
||||
parted ${imagename}.img --script -- mklabel gpt
|
||||
cgpt create -z ${imagename}.img
|
||||
cgpt create ${imagename}.img
|
||||
# Create the disk and partition it
|
||||
echo "Creating image file for Veyron Chromebooks"
|
||||
dd if=/dev/zero of=${basedir}/${imagename}.img bs=1KiB count=0 seek=${raw_size} && sync
|
||||
parted ${basedir}/${imagename}.img --script -- mklabel gpt
|
||||
cgpt create -z ${basedir}/${imagename}.img
|
||||
cgpt create ${basedir}/${imagename}.img
|
||||
|
||||
cgpt add -i 1 -t kernel -b 8192 -s 32768 -l kernel -S 1 -T 5 -P 10 ${imagename}.img
|
||||
cgpt add -i 2 -t data -b 40960 -s `expr $(cgpt show ${imagename}.img | grep 'Sec GPT table' | awk '{ print \$1 }') - 40960` -l Root ${imagename}.img
|
||||
cgpt add -i 1 -t kernel -b 8192 -s 32768 -l kernel -S 1 -T 5 -P 10 ${basedir}/${imagename}.img
|
||||
cgpt add -i 2 -t data -b 40960 -s `expr $(cgpt show ${basedir}/${imagename}.img | grep 'Sec GPT table' | awk '{ print \$1 }') - 40960` -l Root ${basedir}/${imagename}.img
|
||||
|
||||
loopdevice=`losetup -f --show "${basedir}"/${imagename}.img`
|
||||
device=`kpartx -va ${loopdevice} | sed 's/.*\(loop[0-9]\+\)p.*/\1/g' | head -1`
|
||||
@@ -480,22 +534,22 @@ device="/dev/mapper/${device}"
|
||||
bootp=${device}p1
|
||||
rootp=${device}p2
|
||||
|
||||
mkfs.ext3 -O ^flex_bg -O ^metadata_csum -L rootfs ${rootp}
|
||||
mkfs.ext3 -O ^64bit -O ^flex_bg -O ^metadata_csum -L rootfs ${rootp}
|
||||
|
||||
mkdir -p "${basedir}"/root
|
||||
mount ${rootp} "${basedir}"/root
|
||||
|
||||
# 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 > ${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 / ext3 errors=remount-ro 0 1" >> "${basedir}"/kali-${architecture}/etc/fstab
|
||||
echo "UUID=$UUID / ext3 errors=remount-ro 0 1" >> ${work_dir}/etc/fstab
|
||||
|
||||
echo "Rsyncing rootfs into image file"
|
||||
rsync -HPavz -q "${basedir}"/kali-${architecture}/ "${basedir}"/root/
|
||||
rsync -HPavz -q ${work_dir}/ ${basedir}/root/
|
||||
|
||||
# Unmount partitions
|
||||
sync
|
||||
@@ -513,11 +567,15 @@ losetup -d ${loopdevice}
|
||||
# don't need to compress the image, since you will be testing it
|
||||
# soon.
|
||||
# Don't pixz on 32bit, there isn't enough memory to compress the images.
|
||||
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
|
||||
if [ $(arch) == 'x86_64' ]; then
|
||||
echo "Compressing ${imagename}.img"
|
||||
cd ${current_dir}
|
||||
rand=$(tr -cd 'A-Za-z0-9' < /dev/urandom | head -c4 ; echo) # Randowm name group
|
||||
cgcreate -g cpu:/cpulimit-${rand} # Name of group
|
||||
cgset -r cpu.shares=800 cpulimit-${rand} # Max 1024
|
||||
cgset -r cpu.cfs_quota_us=80000 cpulimit-${rand} # Max 100000
|
||||
cgexec -g cpu:cpulimit-${rand} pixz -p 2 "${basedir}"/${imagename}.img ${imagename}.img.xz # -p Nº cpu cores use
|
||||
cgdelete cpu:/cpulimit-${rand} # Delete group
|
||||
fi
|
||||
|
||||
# Clean up all the temporary build stuff and remove the directories.
|
||||
|
||||
Reference in New Issue
Block a user