-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.sh
executable file
·49 lines (41 loc) · 981 Bytes
/
util.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/sh -e
# Provides high-level functions for writing external scripts, such as fzf launchers.
die()
{
printf '%s: error: %s\n' "${0##*/}" "$*" >&2
exit 1
}
assertIsValidVM()
(
vm_name="$1"
test -n "$1" || die "no vm name specified"
test -e "$1" || die "unknown vm: '$vm_name'"
)
dumpFile()
(
filepath="$1"
test ! -e "$filepath" || cat "$filepath"
)
cmd="$1"
vm_name="$2" # only mandatory for some commands
cd "$(dirname "$0")/vm-configs/"
vm_data_mountpoint="/vm-data"
case "$cmd" in
listConfiguredVMs) printf '%s\n' *;;
listRunnableCommands)
assertIsValidVM "$vm_name"
dumpFile "$vm_name/packages"
dumpFile "$vm_name/custom-commands"
# List default apps
printf '%s\n' xterm
;;
listFlatpaks)
assertIsValidVM "$vm_name"
dumpFile "$vm_name/flatpaks"
;;
getHomedir)
assertIsValidVM "$vm_name"
printf '%s/%s/home\n' "$vm_data_mountpoint" "$vm_name"
;;
*) die "invalid command provided: '$cmd'";;
esac