Skip to content

Commit 4117515

Browse files
committed
Add cosa supermin-run
This is very close to `cosa supermin-shell` but instead expects a command to run inside the supermin VM. Essentially, it's a very thin wrapper around the `runvm` family of functions in `cmdlib.sh`. By having it be a dedicated function, it becomes like a utility command to have easy access to a privileged environment, with the working dir automatically mounted in, podman remote proxying, etc... Note also this *does not* require a cosa workdir. The podman machine OS pipeline will be using this temporarily.
1 parent 3ab61dd commit 4117515

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

src/cmd-supermin-run

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
dn=$(dirname "$0")
5+
# shellcheck source=src/cmdlib.sh
6+
. "${dn}"/cmdlib.sh
7+
8+
print_help() {
9+
echo "Usage: cosa supermin-run [--cache|--snapshot] COMMAND [ARG...]" >&2
10+
}
11+
12+
if [ $# = 0 ]; then
13+
print_help
14+
exit 1
15+
fi
16+
17+
need_cache_dir=0
18+
case "$1" in
19+
--cache)
20+
shift
21+
set -- runvm_with_cache -- "$@"
22+
need_cache_dir=1
23+
;;
24+
--snapshot)
25+
shift
26+
set -- runvm_with_cache_snapshot on -- "$@"
27+
need_cache_dir=1
28+
;;
29+
--*)
30+
echo "unrecognized option: $1"
31+
print_help
32+
exit 1
33+
;;
34+
*)
35+
set -- runvm -- "$@"
36+
;;
37+
esac
38+
39+
# force caller to create tmp/ and possibly cache/ rather than surprisingly
40+
# auto-create them
41+
if [ ! -d tmp ]; then
42+
echo 'Need tmp/ dir for supermin to work' >&2
43+
exit 1
44+
fi
45+
if [ $need_cache_dir = 1 ] && [ ! -d cache ]; then
46+
echo 'Need cache/ dir for caching' >&2
47+
exit 1
48+
fi
49+
50+
workdir=$(pwd)
51+
export workdir
52+
53+
"$@"

0 commit comments

Comments
 (0)