Created
January 1, 2026 20:15
-
-
Save naranyala/321b4802113fa247a8f333030e8e361c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Install MSYS2 if missing, then install GNU utilities and expose them in Git Bash | |
| # Includes silent installer run, path conversion, error handling, and visible linking progress | |
| set -euo pipefail | |
| MSYS_DIR="/c/msys64" | |
| MSYS_BIN="$MSYS_DIR/usr/bin" | |
| INSTALLER_URL="https://github.com/msys2/msys2-installer/releases/latest/download/msys2-x86_64-latest.exe" | |
| INSTALLER_PATH="/c/Users/$(whoami)/Downloads/msys2-installer.exe" | |
| error_exit() { | |
| echo "β ERROR: $1" | |
| exit 1 | |
| } | |
| to_winpath() { | |
| echo "$1" | sed 's#^/c/#C:\\#; s#/#\\#g' | |
| } | |
| # --- Install MSYS2 if missing --- | |
| if [ ! -d "$MSYS_DIR" ]; then | |
| echo "β οΈ MSYS2 not found. Downloading installer..." | |
| curl -L -o "$INSTALLER_PATH" "$INSTALLER_URL" || error_exit "Download failed." | |
| WIN_INSTALLER_PATH=$(to_winpath "$INSTALLER_PATH") | |
| WIN_MSYS_DIR=$(to_winpath "$MSYS_DIR") | |
| echo "π¦ Running MSYS2 installer silently..." | |
| powershell.exe -Command "Start-Process -FilePath '$WIN_INSTALLER_PATH' -ArgumentList '/SILENT','/VERYSILENT','/SUPPRESSMSGBOXES','/NORESTART','/DIR=$WIN_MSYS_DIR' -Wait -NoNewWindow" || error_exit "Installer failed." | |
| [ -d "$MSYS_DIR" ] || error_exit "MSYS2 directory not found after installation." | |
| echo "β MSYS2 installed at $MSYS_DIR" | |
| fi | |
| # --- Update and install GNU utilities --- | |
| echo "π Updating MSYS2..." | |
| "$MSYS_BIN/pacman.exe" -Sy --noconfirm || error_exit "Update failed." | |
| echo "π¦ Installing GNU coreutils, grep, sed, awk, etc..." | |
| "$MSYS_BIN/pacman.exe" -S --noconfirm coreutils grep sed gawk findutils diffutils || error_exit "Package install failed." | |
| # --- Linking process with progress --- | |
| mkdir -p ~/bin | |
| echo "π Linking GNU utilities into ~/bin..." | |
| executables=("$MSYS_BIN"/*.exe) | |
| total=${#executables[@]} | |
| count=0 | |
| for exe in "${executables[@]}"; do | |
| count=$((count+1)) | |
| exe_name=$(basename "$exe") | |
| link_name="${exe_name%.exe}" | |
| if ln -sf "$exe" "$HOME/bin/$link_name"; then | |
| percent=$((count * 100 / total)) | |
| echo "β‘οΈ [$count/$total] Linked $link_name ($percent%)" | |
| else | |
| echo "β οΈ Skipped $exe_name due to error." | |
| fi | |
| done | |
| echo "β Finished linking $count GNU utilities." | |
| echo "β‘οΈ Restart Git Bash or run: source ~/.bashrc" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment