sqitchers / docker-sqitch

Docker Image packaging for Sqitch
MIT License
36 stars 39 forks source link

docker-sqitch.sh can't find getent (Docker toolbox for windows 7) #6

Closed RKCZ closed 5 years ago

RKCZ commented 5 years ago

Hello,

when docker-sqitch shell script is executed on Docker toolbox quickstart terminal for Windows 7 following message appears:

./sqitch: line 11: getent: command not found

theory commented 5 years ago

Can you install getent in that shell? If not, do you know how to detect when the script is running in that shell and execute an alternate command to get the user’s full name?

Iif not, just comment out line 11 and be sure to set your name manually via

sqitch config --user user.name "You Fullname"
theory commented 5 years ago

Hi @RKCZ, any thoughts on this?

RKCZ commented 5 years ago

Hi, I tried looking for a way to install getent in docker toolbox and on my personal pc I found it can probably use getent provided by Cygwin if it is installed. I can't say for sure if the Cygwin version is compatible because of cygwin issue on my side. I think that the best way would be to find full name with some windows provided command to avoid the need to install cygwin. Not sure if this is the optimal way but I have found user's full name with command net user <username>. I am not an expert on how this command works so maybe there is some option to show just the full name without other info.

Platform on which script is executed could be possibly determined as it is with uname command. For me it shows MINGW64_NT-

theory commented 5 years ago

Thanks. Does this patch work for you?

--- a/docker-sqitch.sh
+++ b/docker-sqitch.sh
@@ -13,8 +13,12 @@ passopt=(
 )

 # Handle OS-specific options.
-if [ "Darwin" = $(uname) ]; then
+os=$(uname)
+if [ "Darwin" = "$os" ]; then
     passopt+=(-e "SQITCH_ORIG_FULLNAME=$(id -P $user | awk -F '[:]' '{print $8}')")
+elif [ "MINGW64_NT" = "$os" ]; then
+    passopt+=(-e "SQITCH_ORIG_FULLNAME=$(net user $user)")
+    passopt+=(-u $(id -u ${user}):$(id -g ${user}))
 else
     passopt+=(-e "SQITCH_ORIG_FULLNAME=$(getent passwd $user | cut -d: -f5 | cut -d, -f1)")
     passopt+=(-u $(id -u ${user}):$(id -g ${user}))
theory commented 5 years ago

Better attempt to also cover Cygwin, more easily add other OS variants in the future:

--- a/docker-sqitch.sh
+++ b/docker-sqitch.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash

 # Determine which Docker image to run.
 SQITCH_IMAGE=${SQITCH_IMAGE:=sqitch/sqitch:latest}
@@ -13,12 +13,21 @@ passopt=(
 )

 # Handle OS-specific options.
-if [ "Darwin" = $(uname) ]; then
-    passopt+=(-e "SQITCH_ORIG_FULLNAME=$(id -P $user | awk -F '[:]' '{print $8}')")
-else
-    passopt+=(-e "SQITCH_ORIG_FULLNAME=$(getent passwd $user | cut -d: -f5 | cut -d, -f1)")
-    passopt+=(-u $(id -u ${user}):$(id -g ${user}))
-fi
+case "$(uname -s)" in
+    Linux*)
+        passopt+=(-e "SQITCH_ORIG_FULLNAME=$(getent passwd $user | cut -d: -f5 | cut -d, -f1)")
+        passopt+=(-u $(id -u ${user}):$(id -g ${user}))
+        ;;
+    Darwin*)
+        passopt+=(-e "SQITCH_ORIG_FULLNAME=$(id -P $user | awk -F '[:]' '{print $8}')")
+        ;;
+    MINGW*|CYGWIN*)
+        passopt+=(-e "SQITCH_ORIG_FULLNAME=$(net user $user)")
+        ;;
+    *)
+        echo "Unknown OS: $(uname -s)"
+        ;;
+esac

 # Iterate over optional Sqitch and engine variables.
 for var in \
@@ -38,7 +47,7 @@ done

 # Determine the name of the container home directory.
 homedst=/home
-if [ $(id -u) -eq 0 ]; then
+if [ $(id -u ${user}) -eq 0 ]; then
     homedst=/root
 fi
theory commented 5 years ago

I pushed that last patch in 119970a. LMK if it doesn't work for you.