-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdevpod-wrapper
More file actions
46 lines (39 loc) · 1.56 KB
/
devpod-wrapper
File metadata and controls
46 lines (39 loc) · 1.56 KB
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
#!/bin/sh
# Parse the env var DEVPOD_ADDITIONAL_ENV_VARS set by the desktop application when calling the CLI to propogate env vars back to the host from the sandbox
function env_to_args() {
local env_var="DEVPOD_ADDITIONAL_ENV_VARS"
local value="${!env_var}"
# Split the value by commas and process each entry
IFS=',' read -ra ENTRIES <<< "$value"
for entry in "${ENTRIES[@]}"; do
if [ -n "$entry" ]; then
echo "--env=$entry"
fi
done
}
# If we're outside the flatpak, we will run the flatpak command
if [ -z "${FLATPAK_ID}" ]; then
flatpak run --arch=x86_64 --command=devpod-cli sh.loft.devpod "$@"
result="$?"
# In case of error check if the flatpak has been uninstalled, and prompt to
# clean up this leftover
if [ "${result}" -gt 0 ]; then # I: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?.
if ! flatpak list --app | grep -q sh.loft.devpod; then
echo "Devpod flatpak is not installed anymore"
rm -i "$0"
fi
fi
exit "${result}"
fi
# copy over the binary file if absend
if [ ! -e "${XDG_DATA_HOME}/devpod-cli" ]; then
/usr/bin/cp /app/bin/devpod-bin "${XDG_DATA_HOME}/devpod-cli"
else
# or if it differs IE after an update
if ! /usr/bin/cmp --silent /app/bin/devpod-bin "${XDG_DATA_HOME}/devpod-cli"; then
/usr/bin/rm -f "${XDG_DATA_HOME}/devpod-cli"
/usr/bin/cp /app/bin/devpod-bin "${XDG_DATA_HOME}/devpod-cli"
fi
fi
# We need to have it into this path so that the host is able to open it with flatpak-spawn
/usr/bin/flatpak-spawn $(env_to_args) --host "${XDG_DATA_HOME}/devpod-cli" "$@"