forked from kalipso/infrastructure
currently only allows forwarding to port 80, i was to lazy to handle two arguments in bash
68 lines
2.2 KiB
Bash
68 lines
2.2 KiB
Bash
usage() {
|
|
echo "Usage: run-vm <hostname> [--networking] [--dummy-secrets] [--no-disko]"
|
|
echo "ATTENTION: This script must be run from the flakes root directory"
|
|
echo "--networking setup interfaces. requires root and hostbridge enabled on the host"
|
|
echo "--dummy-secrets run vm with dummy sops secrets"
|
|
echo "--no-disko disable disko and initrd secrets. needed for real hosts like fanny"
|
|
echo "--writable-store enables writable store. necessary for host with nested imperative microvms like fanny"
|
|
echo "--var path to directory that should be shared as /var. may require root otherwise some systemd units fail within vm. if dir is empty vm will populate"
|
|
echo "--fwd-port forwards the given port to port 80 on vm"
|
|
exit 1
|
|
}
|
|
|
|
# check at least one arg was given
|
|
if [ "$#" -lt 1 ]; then
|
|
usage
|
|
fi
|
|
|
|
HOSTNAME=$1
|
|
|
|
# Optionale Argumente
|
|
NETWORK=false
|
|
DUMMY_SECRETS=false
|
|
NO_DISKO=false
|
|
RW_STORE=false
|
|
VAR_PATH=""
|
|
FWD_PORT=0
|
|
|
|
# check argws
|
|
shift
|
|
while [[ "$#" -gt 0 ]]; do
|
|
case $1 in
|
|
--networking) NETWORK=true ;;
|
|
--dummy-secrets) DUMMY_SECRETS=true ;;
|
|
--no-disko) NO_DISKO=true ;;
|
|
--writable-store) RW_STORE=true ;;
|
|
--var)
|
|
if [[ -n "$2" && ! "$2" =~ ^- ]]; then
|
|
VAR_PATH="$2"
|
|
shift
|
|
else
|
|
echo "Error: --var requires a non-empty string argument."
|
|
usage
|
|
fi
|
|
;;
|
|
--fwd-port)
|
|
if [[ -n "$2" && ! "$2" =~ ^- ]]; then
|
|
FWD_PORT="$2"
|
|
shift
|
|
else
|
|
echo "Error: --var requires a non-empty string argument."
|
|
usage
|
|
fi
|
|
;;
|
|
*) echo "Unknown argument: $1"; usage ;;
|
|
esac
|
|
shift
|
|
done
|
|
echo "starting host $HOSTNAME"
|
|
echo "enable networking: $NETWORK"
|
|
echo "deploy dummy secrets: $DUMMY_SECRETS"
|
|
echo "disable disko and initrd secrets: $NO_DISKO"
|
|
echo "use writable store: $RW_STORE"
|
|
if [ -n "$VAR_PATH" ]; then
|
|
echo "sharing var directory: $VAR_PATH"
|
|
fi
|
|
|
|
nix run --show-trace --impure --expr "((builtins.getFlake \"$(pwd)\").vmBuilder.x86_64-linux \"$HOSTNAME\" $NETWORK $DUMMY_SECRETS $NO_DISKO \"$VAR_PATH\" $RW_STORE $FWD_PORT).config.microvm.declaredRunner"
|