mirror of
https://github.com/edera-dev/krata.git
synced 2025-08-03 05:10:55 +00:00
hack: rename scripts to hack
This commit is contained in:
22
hack/build/arch.sh
Executable file
22
hack/build/arch.sh
Executable file
@ -0,0 +1,22 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
TOOLS_DIR="$(dirname "${0}")"
|
||||
|
||||
RUST_TARGET="$("${TOOLS_DIR}/target.sh")"
|
||||
TARGET_ARCH="$(echo "${RUST_TARGET}" | awk -F '-' '{print $1}')"
|
||||
|
||||
if [ "${KRATA_ARCH_ALT_NAME}" = "1" ] || [ "${KRATA_ARCH_KERNEL_NAME}" = "1" ]
|
||||
then
|
||||
if [ "${TARGET_ARCH}" = "x86_64" ] && [ "${KRATA_ARCH_KERNEL_NAME}" != "1" ]
|
||||
then
|
||||
TARGET_ARCH="amd64"
|
||||
fi
|
||||
|
||||
if [ "${TARGET_ARCH}" = "aarch64" ]
|
||||
then
|
||||
TARGET_ARCH="arm64"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "${TARGET_ARCH}"
|
8
hack/build/cargo.sh
Executable file
8
hack/build/cargo.sh
Executable file
@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
TOOLS_DIR="$(dirname "${0}")"
|
||||
RUST_TARGET="$("${TOOLS_DIR}/target.sh")"
|
||||
|
||||
export CARGO_BUILD_TARGET="${RUST_TARGET}"
|
||||
exec cargo "${@}"
|
29
hack/build/target.sh
Executable file
29
hack/build/target.sh
Executable file
@ -0,0 +1,29 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
if [ -z "${RUST_LIBC}" ]
|
||||
then
|
||||
RUST_LIBC="gnu"
|
||||
fi
|
||||
|
||||
if [ -z "${RUST_TARGET}" ]
|
||||
then
|
||||
HOST_ARCH="$(uname -m)"
|
||||
if [ "${HOST_ARCH}" = "x86_64" ]
|
||||
then
|
||||
RUST_TARGET="x86_64-unknown-linux-${RUST_LIBC}"
|
||||
fi
|
||||
|
||||
if [ "${HOST_ARCH}" = "aarch64" ]
|
||||
then
|
||||
RUST_TARGET="aarch64-unknown-linux-${RUST_LIBC}"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "${RUST_TARGET}" ]
|
||||
then
|
||||
echo "ERROR: Unable to determine RUST_TARGET, your architecture may not be supported by krata." > /dev/stderr
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "${RUST_TARGET}"
|
8
hack/ci/install-deps.sh
Executable file
8
hack/ci/install-deps.sh
Executable file
@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y \
|
||||
build-essential libssl-dev libelf-dev musl-dev \
|
||||
flex bison bc protobuf-compiler musl-tools
|
||||
sudo gem install --no-document fpm
|
8
hack/code/autofix.sh
Executable file
8
hack/code/autofix.sh
Executable file
@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
REAL_SCRIPT="$(realpath "${0}")"
|
||||
cd "$(dirname "${REAL_SCRIPT}")/../.."
|
||||
|
||||
./hack/build/cargo.sh clippy --fix --allow-dirty --allow-staged
|
||||
cargo fmt --all
|
7
hack/code/shellcheck.sh
Executable file
7
hack/code/shellcheck.sh
Executable file
@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
REAL_SCRIPT="$(realpath "${0}")"
|
||||
cd "$(dirname "${REAL_SCRIPT}")/../.."
|
||||
|
||||
find hack -type f -name '*.sh' -print0 | xargs -0 shellcheck -x
|
31
hack/debug/common.sh
Normal file
31
hack/debug/common.sh
Normal file
@ -0,0 +1,31 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
REAL_SCRIPT="$(realpath "${0}")"
|
||||
cd "$(dirname "${REAL_SCRIPT}")/../.."
|
||||
|
||||
if [ -z "${RUST_LOG}" ]
|
||||
then
|
||||
RUST_LOG="INFO"
|
||||
fi
|
||||
|
||||
CARGO_BUILD_FLAGS=""
|
||||
|
||||
if [ "${KRATA_BUILD_QUIET}" = "1" ]
|
||||
then
|
||||
CARGO_BUILD_FLAGS="-q"
|
||||
fi
|
||||
|
||||
build_and_run() {
|
||||
EXE_TARGET="${1}"
|
||||
shift
|
||||
sudo mkdir -p /var/lib/krata/guest
|
||||
if [ "${KRATA_BUILD_INITRD}" = "1" ]
|
||||
then
|
||||
./hack/initrd/build.sh -q
|
||||
sudo cp "target/initrd/initrd" "/var/lib/krata/guest/initrd"
|
||||
fi
|
||||
RUST_TARGET="$(./hack/build/target.sh)"
|
||||
./hack/build/cargo.sh build ${CARGO_BUILD_FLAGS} --bin "${EXE_TARGET}"
|
||||
exec sudo RUST_LOG="${RUST_LOG}" "target/${RUST_TARGET}/debug/${EXE_TARGET}" "${@}"
|
||||
}
|
9
hack/debug/kratactl.sh
Executable file
9
hack/debug/kratactl.sh
Executable file
@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
REAL_SCRIPT="$(realpath "${0}")"
|
||||
DEBUG_DIR="$(dirname "${REAL_SCRIPT}")"
|
||||
# shellcheck source-path=SCRIPTDIR source=common.sh
|
||||
. "${DEBUG_DIR}/common.sh"
|
||||
|
||||
build_and_run kratactl "${@}"
|
9
hack/debug/kratad.sh
Executable file
9
hack/debug/kratad.sh
Executable file
@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
REAL_SCRIPT="$(realpath "${0}")"
|
||||
DEBUG_DIR="$(dirname "${REAL_SCRIPT}")"
|
||||
# shellcheck source-path=SCRIPTDIR source=common.sh
|
||||
. "${DEBUG_DIR}/common.sh"
|
||||
|
||||
KRATA_BUILD_INITRD=1 build_and_run kratad "${@}"
|
9
hack/debug/kratanet.sh
Executable file
9
hack/debug/kratanet.sh
Executable file
@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
REAL_SCRIPT="$(realpath "${0}")"
|
||||
DEBUG_DIR="$(dirname "${REAL_SCRIPT}")"
|
||||
# shellcheck source-path=SCRIPTDIR source=common.sh
|
||||
. "${DEBUG_DIR}/common.sh"
|
||||
|
||||
build_and_run kratanet "${@}"
|
14
hack/debug/session.sh
Executable file
14
hack/debug/session.sh
Executable file
@ -0,0 +1,14 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
stop_service_if_running() {
|
||||
if sudo systemctl is-active "${1}" > /dev/null 2>&1
|
||||
then
|
||||
sudo systemctl stop "${1}"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
stop_service_if_running "kratad.service"
|
||||
stop_service_if_running "kratanet.service"
|
||||
tmuxp load "$(dirname "${0}")/session.yml"
|
11
hack/debug/session.yml
Normal file
11
hack/debug/session.yml
Normal file
@ -0,0 +1,11 @@
|
||||
session_name: krata-dev
|
||||
start_directory: ../..
|
||||
sleep_after: 3
|
||||
windows:
|
||||
- window_name: live
|
||||
layout: tiled
|
||||
panes:
|
||||
- shell_command: ./hack/debug/kratad.sh
|
||||
- shell_command: ./hack/debug/kratanet.sh
|
||||
- focus: true
|
||||
shell_command: "alias kratactl=./hack/debug/kratactl.sh"
|
46
hack/dist/bundle.sh
vendored
Executable file
46
hack/dist/bundle.sh
vendored
Executable file
@ -0,0 +1,46 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
# shellcheck source-path=SCRIPTDIR source=common.sh
|
||||
. "$(dirname "${0}")/common.sh"
|
||||
|
||||
if [ -z "${KRATA_KERNEL_BUILD_JOBS}" ]
|
||||
then
|
||||
KRATA_KERNEL_BUILD_JOBS="2"
|
||||
fi
|
||||
|
||||
BUNDLE_TAR="${OUTPUT_DIR}/bundle.tgz"
|
||||
rm -f "${BUNDLE_TAR}"
|
||||
BUNDLE_DIR="$(mktemp -d /tmp/krata-bundle.XXXXXXXXXXXXX)"
|
||||
BUNDLE_DIR="${BUNDLE_DIR}/krata"
|
||||
mkdir -p "${BUNDLE_DIR}"
|
||||
for X in kratad kratanet kratactl
|
||||
do
|
||||
./hack/build/cargo.sh build --release --bin "${X}"
|
||||
RUST_TARGET="$(./hack/build/target.sh)"
|
||||
cp "${KRATA_DIR}/target/${RUST_TARGET}/release/${X}" "${BUNDLE_DIR}/${X}"
|
||||
done
|
||||
./hack/initrd/build.sh
|
||||
if [ "${KRATA_BUNDLE_SKIP_KERNEL_BUILD}" != "1" ]
|
||||
then
|
||||
./hack/kernel/build.sh "-j${KRATA_KERNEL_BUILD_JOBS}"
|
||||
fi
|
||||
|
||||
cd "${BUNDLE_DIR}"
|
||||
|
||||
cp "${KRATA_DIR}/target/initrd/initrd" initrd
|
||||
cp "${KRATA_DIR}/target/kernel/kernel" kernel
|
||||
cp "${KRATA_DIR}/resources/systemd/kratad.service" kratad.service
|
||||
cp "${KRATA_DIR}/resources/systemd/kratanet.service" kratanet.service
|
||||
cp "${KRATA_DIR}/resources/bundle/install.sh" install.sh
|
||||
cp "${KRATA_DIR}/resources/bundle/uninstall.sh" uninstall.sh
|
||||
|
||||
for X in install.sh uninstall.sh kratactl kratad kratanet
|
||||
do
|
||||
chmod +x "${X}"
|
||||
done
|
||||
|
||||
cd ..
|
||||
tar czf "${BUNDLE_TAR}" .
|
||||
cd "${KRATA_DIR}"
|
||||
rm -rf "$(dirname "${BUNDLE_DIR}")"
|
8
hack/dist/common.sh
vendored
Normal file
8
hack/dist/common.sh
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
REAL_SCRIPT="$(realpath "${0}")"
|
||||
cd "$(dirname "${REAL_SCRIPT}")/../.."
|
||||
KRATA_DIR="${PWD}"
|
||||
OUTPUT_DIR="${KRATA_DIR}/target/dist"
|
||||
mkdir -p "${OUTPUT_DIR}"
|
30
hack/dist/deb.sh
vendored
Executable file
30
hack/dist/deb.sh
vendored
Executable file
@ -0,0 +1,30 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
# shellcheck source-path=SCRIPTDIR source=common.sh
|
||||
. "$(dirname "${0}")/common.sh"
|
||||
|
||||
"${KRATA_DIR}/hack/dist/systar.sh"
|
||||
|
||||
KRATA_VERSION="$("${KRATA_DIR}/hack/dist/version.sh")"
|
||||
TARGET_ARCH="$(KRATA_ARCH_ALT_NAME=1 "${KRATA_DIR}/hack/build/arch.sh")"
|
||||
|
||||
cd "${OUTPUT_DIR}"
|
||||
|
||||
rm -f "krata_${KRATA_VERSION}_${TARGET_ARCH}.deb"
|
||||
|
||||
fpm -s tar -t deb \
|
||||
--name krata \
|
||||
--license agpl3 \
|
||||
--version "${KRATA_VERSION}" \
|
||||
--architecture "${TARGET_ARCH}" \
|
||||
--depends "xen-system-${TARGET_ARCH}" \
|
||||
--description "Krata Hypervisor" \
|
||||
--url "https://krata.dev" \
|
||||
--maintainer "Edera Team <contact@edera.dev>" \
|
||||
-x "usr/lib/**" \
|
||||
--deb-systemd "${KRATA_DIR}/resources/systemd/kratad.service" \
|
||||
--deb-systemd "${KRATA_DIR}/resources/systemd/kratanet.service" \
|
||||
--deb-systemd-enable \
|
||||
--deb-systemd-auto-start \
|
||||
"${OUTPUT_DIR}/system.tgz"
|
31
hack/dist/systar.sh
vendored
Executable file
31
hack/dist/systar.sh
vendored
Executable file
@ -0,0 +1,31 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
# shellcheck source-path=SCRIPTDIR source=common.sh
|
||||
. "$(dirname "${0}")/common.sh"
|
||||
|
||||
"${KRATA_DIR}/hack/dist/bundle.sh"
|
||||
|
||||
SYSTAR="${OUTPUT_DIR}/system.tgz"
|
||||
rm -f "${SYSTAR}"
|
||||
SYSTAR_DIR="$(mktemp -d /tmp/krata-systar.XXXXXXXXXXXXX)"
|
||||
cd "${SYSTAR_DIR}"
|
||||
tar xf "${OUTPUT_DIR}/bundle.tgz"
|
||||
|
||||
mkdir sys
|
||||
cd sys
|
||||
|
||||
mkdir -p usr/bin usr/libexec
|
||||
mv ../krata/kratactl usr/bin
|
||||
mv ../krata/kratanet ../krata/kratad usr/libexec/
|
||||
|
||||
mkdir -p usr/lib/systemd/system
|
||||
mv ../krata/kratad.service ../krata/kratanet.service usr/lib/systemd/system/
|
||||
|
||||
mkdir -p usr/share/krata/guest
|
||||
mv ../krata/kernel ../krata/initrd usr/share/krata/guest
|
||||
|
||||
tar czf "${SYSTAR}" --owner 0 --group 0 .
|
||||
|
||||
cd "${KRATA_DIR}"
|
||||
rm -rf "${SYSTAR_DIR}"
|
15
hack/dist/version.sh
vendored
Executable file
15
hack/dist/version.sh
vendored
Executable file
@ -0,0 +1,15 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
# shellcheck source-path=SCRIPTDIR source=common.sh
|
||||
. "$(dirname "${0}")/common.sh"
|
||||
cd "${KRATA_DIR}"
|
||||
|
||||
KRATA_VERSION="$(grep -A1 -F '[workspace.package]' Cargo.toml | grep 'version' | awk '{print $3}' | sed 's/"//g')"
|
||||
if [ -z "${KRATA_VERSION}" ]
|
||||
then
|
||||
echo "ERROR: failed to determine krata version" > /dev/stderr
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "${KRATA_VERSION}"
|
20
hack/initrd/build.sh
Executable file
20
hack/initrd/build.sh
Executable file
@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
REAL_SCRIPT="$(realpath "${0}")"
|
||||
cd "$(dirname "${REAL_SCRIPT}")/../.."
|
||||
KRATA_DIR="${PWD}"
|
||||
cd "${KRATA_DIR}"
|
||||
|
||||
export RUST_LIBC="musl"
|
||||
RUST_TARGET="$(./hack/build/target.sh)"
|
||||
export RUSTFLAGS="-Ctarget-feature=+crt-static"
|
||||
|
||||
./hack/build/cargo.sh build "${@}" --release --bin krataguest
|
||||
INITRD_DIR="$(mktemp -d /tmp/krata-initrd.XXXXXXXXXXXXX)"
|
||||
cp "target/${RUST_TARGET}/release/krataguest" "${INITRD_DIR}/init"
|
||||
chmod +x "${INITRD_DIR}/init"
|
||||
cd "${INITRD_DIR}"
|
||||
mkdir -p "${KRATA_DIR}/target/initrd"
|
||||
find . | cpio -R 0:0 --reproducible -o -H newc --quiet > "${KRATA_DIR}/target/initrd/initrd"
|
||||
rm -rf "${INITRD_DIR}"
|
56
hack/kernel/build.sh
Executable file
56
hack/kernel/build.sh
Executable file
@ -0,0 +1,56 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
REAL_SCRIPT="$(realpath "${0}")"
|
||||
cd "$(dirname "${REAL_SCRIPT}")/../.."
|
||||
KRATA_DIR="${PWD}"
|
||||
KERNEL_DIR="${KRATA_DIR}/kernel"
|
||||
|
||||
cd "${KRATA_DIR}"
|
||||
|
||||
# shellcheck source-path=SCRIPTDIR source=../../kernel/config.sh
|
||||
. "${KERNEL_DIR}/config.sh"
|
||||
KERNEL_SRC="${KERNEL_DIR}/linux-${KERNEL_VERSION}"
|
||||
|
||||
if [ ! -f "${KERNEL_SRC}/Makefile" ]
|
||||
then
|
||||
rm -rf "${KERNEL_SRC}"
|
||||
curl --progress-bar -L -o "${KERNEL_SRC}.txz" "${KERNEL_SRC_URL}"
|
||||
tar xf "${KERNEL_SRC}.txz" -C "${KERNEL_DIR}"
|
||||
rm "${KERNEL_SRC}.txz"
|
||||
fi
|
||||
|
||||
OUTPUT_DIR="${KRATA_DIR}/target/kernel"
|
||||
mkdir -p "${OUTPUT_DIR}"
|
||||
|
||||
TARGET_ARCH="$(KRATA_ARCH_KERNEL_NAME=1 ./hack/build/arch.sh)"
|
||||
|
||||
KERNEL_CONFIG_FILE="${KERNEL_DIR}/krata-${TARGET_ARCH}.config"
|
||||
|
||||
if [ ! -f "${KERNEL_CONFIG_FILE}" ]
|
||||
then
|
||||
echo "ERROR: kernel config file not found for ${TARGET_ARCH}" > /dev/stderr
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cp "${KERNEL_CONFIG_FILE}" "${KERNEL_SRC}/.config"
|
||||
make -C "${KERNEL_SRC}" ARCH="${TARGET_ARCH}" "${@}" olddefconfig
|
||||
|
||||
if [ "${TARGET_ARCH}" = "x86_64" ]
|
||||
then
|
||||
make -C "${KERNEL_SRC}" ARCH="${TARGET_ARCH}" "${@}" bzImage
|
||||
elif [ "${TARGET_ARCH}" = "arm64" ]
|
||||
then
|
||||
make -C "${KERNEL_SRC}" ARCH="${TARGET_ARCH}" "${@}" Image.gz
|
||||
fi
|
||||
|
||||
if [ "${TARGET_ARCH}" = "x86_64" ]
|
||||
then
|
||||
cp "${KERNEL_SRC}/arch/x86/boot/bzImage" "${OUTPUT_DIR}/kernel"
|
||||
elif [ "${TARGET_ARCH}" = "arm64" ]
|
||||
then
|
||||
cp "${KERNEL_SRC}/arch/arm64/boot/Image.gz" "${OUTPUT_DIR}/kernel"
|
||||
else
|
||||
echo "ERROR: unable to determine what file is the vmlinuz for ${TARGET_ARCH}" > /dev/stderr
|
||||
exit 1
|
||||
fi
|
13
hack/kernel/clean.sh
Executable file
13
hack/kernel/clean.sh
Executable file
@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
REAL_SCRIPT="$(realpath "${0}")"
|
||||
cd "$(dirname "${REAL_SCRIPT}")/../.."
|
||||
KRATA_DIR="${PWD}"
|
||||
KERNEL_DIR="${KRATA_DIR}/kernel"
|
||||
|
||||
# shellcheck disable=SC2010
|
||||
for ITEM in $(ls "${KERNEL_DIR}" | grep "^linux-")
|
||||
do
|
||||
rm -rf "${KERNEL_DIR:?}/${ITEM}"
|
||||
done
|
Reference in New Issue
Block a user