From 31872d0562ea63cd84f3c350d8d77b2d5060e552 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Sat, 30 Nov 2019 22:25:02 +0100 Subject: [PATCH] fix: include WSL support Signed-off-by: Valentin Lab --- bin/compose | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/bin/compose b/bin/compose index 3843d98..a5485b6 100755 --- a/bin/compose +++ b/bin/compose @@ -217,7 +217,15 @@ get_os() { local uname_output uname_output="$(uname -s)" case "${uname_output}" in - Linux*) e linux;; + Linux*) + if [[ "$(< /proc/version)" == *@(Microsoft|WSL)* ]]; then + e wsl + # elif [[ "$(< /proc/version)" == *"@(microsoft|WSL)"* ]]; then + # e wsl2 + else + e linux + fi + ;; Darwin*) e mac;; CYGWIN*) e cygwin;; MINGW*) e mingw;; @@ -648,6 +656,10 @@ pretty_print() { } +win_env() { "$CMD" /c "/dev/null; } +wsl_path_env() { wslpath "$(win_env "${1}")"; } + + set_os() { OS="$(get_os)" case "$OS" in @@ -680,6 +692,41 @@ set_os() { TZ_PATH=${TZ_PATH:-"$COMPOSE_LOCAL_ROOT"/timezones} COMPOSE_LAUNCHER_CACHE=${COMPOSE_LAUNCHER_CACHE:-"$COMPOSE_LOCAL_ROOT"/cache} ;; + wsl) + type -p cmd.exe >/dev/null || { + die "cmd.exe is not found in \$PATH." + } + + CMD=$(type -p cmd.exe >/dev/null) || { + for p in {/mnt,}/c/WINDOWS/SYSTEM32; do + if [ -x "$p"/cmd.exe ]; then + CMD="$p"/cmd.exe + fi + done + if [ -z "$CMD" ]; then + die "cmd.exe is not found in \$PATH." \ + "And could not find it in standard directories." + fi + } + + WIN_HOME="$(wsl_path_env UserProfile)" + WIN_PROGRAM_FILES="$(wsl_path_env ProgramFiles)" + + COMPOSE_LAUNCHER_APP_DIR="$WIN_PROGRAM_FILES/Compose" + COMPOSE_LOCAL_ROOT=${COMPOSE_LOCAL_ROOT:-"$WIN_HOME/AppData/Local/Compose/Launcher"} + + COMPOSE_VAR=${COMPOSE_VAR:-"$WIN_HOME/AppData/Local/Compose/lib"} + COMPOSE_CACHE=${COMPOSE_CACHE:-"$WIN_HOME/AppData/Local/Compose/cache"} + + DATASTORE=${DATASTORE:-"$WIN_HOME/AppData/Local/Compose/data"} + CONFIGSTORE=${CONFIGSTORE:-"$WIN_HOME/AppData/Local/Compose/config"} + + mkdir -p "$COMPOSE_VAR" "$COMPOSE_CACHE" "$DATASTORE" "$CONFIGSTORE" || return 1 + SESSION_DIR=${SESSION_DIR:-"$COMPOSE_LOCAL_ROOT"/sessions} + CHARM_STORE=${CHARM_STORE:-"$COMPOSE_LAUNCHER_APP_DIR/charm-store"} + TZ_PATH=${TZ_PATH:-"$COMPOSE_LOCAL_ROOT"/timezones} + COMPOSE_LAUNCHER_CACHE=${COMPOSE_LAUNCHER_CACHE:-"$COMPOSE_LOCAL_ROOT"/cache} + ;; *) echo "System '$os' not supported yet." >&2 return 1