diff --git a/lib.sh b/lib.sh index 02a7472..bcf2ecd 100644 --- a/lib.sh +++ b/lib.sh @@ -2,31 +2,54 @@ # lib_get_esptool_command() { - WIN_PYTHON="python" - MAC_ESPTOOL="esptool" - if command -v $MAC_ESPTOOL &> /dev/null - then - echo "$MAC_ESPTOOL" - return - else - if ! command -v $WIN_PYTHON &> /dev/null - then - $WIN_PYTHON - echo "エラー:Pythonコマンドを使用するため、まずPythonをインストールしてください。" - echo "$MAC_ESPTOOL nor $WIN_PYTHON could not be found. Please install it first." - exit 1 - else - # check if esptool is installed as a module - if $WIN_PYTHON -m esptool --help &> /dev/null - then - echo "$WIN_PYTHON -m esptool" - return + PYTHON="python" + ESPTOOL="esptool" + local OS_TYPE=$(uname -s) + case "$OS_TYPE" in + "CYGWIN"*|"MINGW"*|"MSYS"*) # Windows (Git Bash, Cygwin, etc.) + if ! command -v $PYTHON &> /dev/null + then + python + echo "エラー:Pythonコマンドを使用するため、まずPythonをインストールしてください。" + echo "$PYTHON could not be found. Please install it first." + exit 1 else - $WIN_PYTHON -m pip install --upgrade pip - $WIN_PYTHON -m pip install esptool --no-warn-script-location - return + if $PYTHON -m esptool --help &> /dev/null + then + echo "$PYTHON -m esptool" + return + else + $PYTHON -m pip install --upgrade pip + $PYTHON -m pip install esptool --no-warn-script-location + return + fi fi - echo "$WIN_PYTHON -m esptool" + echo "$PYTHON -m esptool" + return + ;; + "Darwin") # macOS + if command -v $ESPTOOL &> /dev/null + then + echo "$ESPTOOL" + else + brew install esptool + echo "$ESPTOOL" + fi + ;; + "Linux") # Linux + if command -v $ESPTOOL &> /dev/null + then + echo "$ESPTOOL" + else + sudo apt-get install -y pipx + pipx install esptool + pipx ensurepath + echo "エラー:esptoolを有効にするために、一度シェルのログアウトを行ってください。" + ;; + esac + + fi + # check if esptool is installed as a module fi fi }