-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support for multiple sdks and abstract machine making into crea…
…te_image script in sdk This probably requires upping CARTESI_DEFAULT_SDK_VERSION as well. Signed-off-by: Carsten Munk <carsten@zippie.com>
- Loading branch information
Showing
3 changed files
with
96 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/bin/bash | ||
|
||
# Define function to display usage | ||
usage() { | ||
echo "Usage: $0 [options]" | ||
echo "Options:" | ||
echo " -r, --ram-length <size> Specify RAM size" | ||
echo " -d, --drive-label <label> Specify drive label, filename for input" | ||
echo " -m, --machine-rootfs <path> Specify machine root filesystem path" | ||
echo " -o, --output <path> Specify output directory" | ||
echo " -w, --workdir <path> Set the working directory" | ||
echo " -e, --entrypoint <cmd> Set the entrypoint command" | ||
echo " -v, --env <var=value> Add an environment variable" | ||
echo " -h, --help Display this help and exit" | ||
} | ||
|
||
# Initialize variables with default values | ||
ram_length="" | ||
drive_label="" | ||
input_filename="" | ||
output_path="" | ||
workdir="" | ||
entrypoint="" | ||
declare -a env_vars | ||
|
||
# Parse command line options using getopt | ||
TEMP=$(getopt -o r:d:m:o:w:e:v:h --long ram-length:,drive-label:,machine-rootfs:,output:,workdir:,entrypoint:,env:,help -- "$@") | ||
eval set -- "$TEMP" | ||
|
||
# Extract options and their arguments into variables. | ||
while true ; do | ||
case "$1" in | ||
-r|--ram-length) | ||
ram_length="$2" | ||
shift 2 ;; | ||
-d|--drive-label) | ||
drive_label="$2" | ||
shift 2 ;; | ||
-m|--machine-rootfs) | ||
input_filename="$2" | ||
shift 2 ;; | ||
-o|--output) | ||
output_path="$2" | ||
shift 2 ;; | ||
-w|--workdir) | ||
workdir="$2" | ||
shift 2 ;; | ||
-e|--entrypoint) | ||
entrypoint="$2" | ||
shift 2 ;; | ||
-v|--env) | ||
env_vars+=("$2") | ||
shift 2 ;; | ||
--) | ||
shift ; break ;; | ||
-h|--help) | ||
usage | ||
exit 0 ;; | ||
*) | ||
echo "Invalid option: $1" >&2 | ||
usage | ||
exit 1 ;; | ||
esac | ||
done | ||
|
||
# Construct the command line for cartesi-machine | ||
cmd=("cartesi-machine") | ||
for env_var in "${env_vars[@]}"; do | ||
cmd+=("--append-entrypoint=export $env_var") | ||
done | ||
[[ -n "$ram_length" ]] && cmd+=("--ram-length=$ram_length") | ||
[[ -n "$drive_label" ]] && [[ -n $input_filename ]] && cmd+=("--flash-drive=label:$drive_label,filename:$input_filename") | ||
[[ -n "$output_path" ]] && cmd+=("--store=$output_path") | ||
[[ -n "$workdir" ]] && cmd+=("--append-init=WORKDIR=$workdir") | ||
[[ -n "$entrypoint" ]] && cmd+=("--append-entrypoint=$entrypoint") | ||
cmd+=("--append-bootargs=no4lvl") | ||
cmd+=("--assert-rolling-template") | ||
cmd+=("--final-hash") | ||
|
||
# Execute the command | ||
"${cmd[@]}" |