Last active
June 19, 2025 12:32
-
-
Save svyatogor/d62ea99aadac7723956a2c688ee3d06f to your computer and use it in GitHub Desktop.
Setup basic modern tools in remote env
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 | |
# | |
# Quick EC2 SSM User Setup for Amazon Linux 2023 (x86_64 & aarch64) | |
# | |
# This script configures the shell environment with modern, high-performance tools. | |
# It automatically detects the system architecture, downloads the correct binaries, | |
# and is idempotent (safe to run multiple times). | |
# | |
# Hosted as a Gist, it can be run via curl: | |
# curl -sSL "https://gist.githubusercontent.com/svyatogor/d62ea99aadac7723956a2c688ee3d06f/raw/oh-my-shell.sh" | bash | |
# | |
set -euo pipefail | |
# --- 1. Setup Environment --- | |
echo "--- Setting up user environment ---" | |
BIN_DIR="$HOME/.local/bin" | |
CONFIG_DIR="$HOME/.config" | |
BASHRC="$HOME/.bashrc" | |
mkdir -p "$BIN_DIR" "$CONFIG_DIR" | |
# --- 2. Architecture Detection --- | |
echo "--- Detecting system architecture ---" | |
UNAME_ARCH=$(uname -m) | |
case $UNAME_ARCH in | |
x86_64) | |
ARCH="x86_64" | |
FZF_ARCH="amd64" | |
RIPGRIP_ARCH="x86_64-unknown-linux-musl" | |
EZA_ARCH="x86_64" | |
HL_ARCH="x86_64" | |
;; | |
aarch64) | |
ARCH="aarch64" | |
HL_ARCH="arm64" | |
FZF_ARCH="arm64" | |
RIPGRIP_ARCH="aarch64-unknown-linux-gnu" | |
EZA_ARCH="aarch64" | |
;; | |
*) | |
echo "Unsupported architecture: $ARCH. This script only supports x86_64 and aarch64." | |
exit 1 | |
;; | |
esac | |
echo "✅ Detected $ARCH architecture. Using corresponding binaries." | |
# --- 3. Install Tools --- | |
echo "--- Installing modern tools to $BIN_DIR ---" | |
# Create a temporary directory for downloads that cleans up on exit | |
TMP_DIR=$(mktemp -d) | |
trap 'rm -rf -- "$TMP_DIR"' EXIT | |
cd "$TMP_DIR" | |
# Helper function to get the latest release tag from a GitHub repository | |
get_latest_gh_tag() { | |
local repo="$1" | |
curl -sL "https://api.github.com/repos/${repo}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' | |
} | |
# --- Tool Installation with Idempotency Checks --- | |
# -- Starship -- | |
if [ ! -f "$BIN_DIR/starship" ]; then | |
echo "Installing Starship..." | |
curl -sLo starship.tar.gz "https://github.com/starship/starship/releases/latest/download/starship-${ARCH}-unknown-linux-musl.tar.gz" | |
tar -xzf starship.tar.gz | |
mv ./starship "$BIN_DIR/starship" | |
chmod +x "$BIN_DIR/starship" | |
echo "✅ Starship installed." | |
else | |
echo "✅ Starship is already installed. Skipping." | |
fi | |
# -- Zellij -- | |
if [ ! -f "$BIN_DIR/zellij" ]; then | |
echo "Installing Zellij..." | |
curl -sLo zellij.tar.gz "https://github.com/zellij-org/zellij/releases/latest/download/zellij-${ARCH}-unknown-linux-musl.tar.gz" | |
tar -xzf zellij.tar.gz | |
mv ./zellij "$BIN_DIR/zellij" | |
chmod +x "$BIN_DIR/zellij" | |
echo "✅ Zellij installed." | |
else | |
echo "✅ Zellij is already installed. Skipping." | |
fi | |
# -- Eza -- | |
if [ ! -f "$BIN_DIR/eza" ]; then | |
echo "Installing Eza..." | |
curl -sLo eza.tar.gz "https://github.com/eza-community/eza/releases/latest/download/eza_${EZA_ARCH}-unknown-linux-gnu.tar.gz" | |
tar -xzf eza.tar.gz | |
mv ./eza "$BIN_DIR/eza" | |
chmod +x "$BIN_DIR/eza" | |
echo "✅ Eza installed." | |
else | |
echo "✅ Eza is already installed. Skipping." | |
fi | |
# -- Ripgrep (rg) -- | |
if [ ! -f "$BIN_DIR/rg" ]; then | |
echo "Installing Ripgrep (rg)..." | |
RG_TAG=$(get_latest_gh_tag "BurntSushi/ripgrep") | |
RG_TARBALL="ripgrep-${RG_TAG}-${RIPGRIP_ARCH}.tar.gz" | |
curl -sLo rg.tar.gz "https://github.com/BurntSushi/ripgrep/releases/download/${RG_TAG}/${RG_TARBALL}" | |
tar -xzf rg.tar.gz | |
mv "./${RG_TARBALL%.tar.gz}/rg" "$BIN_DIR/rg" | |
chmod +x "$BIN_DIR/rg" | |
echo "✅ Ripgrep installed." | |
else | |
echo "✅ Ripgrep is already installed. Skipping." | |
fi | |
# -- hl -- | |
if [ ! -f "$BIN_DIR/hl" ]; then | |
echo "Installing hl..." | |
curl -sLo hl.tar.gz "https://github.com/pamburus/hl/releases/latest/download/hl-linux-${HL_ARCH}-musl.tar.gz" | |
tar -xzf hl.tar.gz | |
mv ./hl "$BIN_DIR/hl" | |
chmod +x "$BIN_DIR/hl" | |
echo "✅ hl installed." | |
else | |
echo "✅ hl is already installed. Skipping." | |
fi | |
if [ ! -f "$BIN_DIR/bat" ]; then | |
echo "Installing bat..." | |
BAT_TAG=$(get_latest_gh_tag "sharkdp/bat") | |
BAT_TARBALL="bat-${BAT_TAG}-${ARCH}-unknown-linux-gnu.tar.gz" | |
curl -sLo rg.tar.gz "https://github.com/sharkdp/bat/releases/download/${BAT_TAG}/${BAT_TARBALL}" | |
tar -xzf rg.tar.gz | |
mv "./${BAT_TARBALL%.tar.gz}/bat" "$BIN_DIR/bat" | |
chmod +x "$BIN_DIR/bat" | |
echo "✅ Bat installed." | |
else | |
echo "✅ Bat is already installed. Skipping." | |
fi | |
if [ ! -f "$BIN_DIR/bat" ]; then | |
echo "Installing bat..." | |
BAT_TAG=$(get_latest_gh_tag "sharkdp/bat") | |
BAT_TARBALL="bat-${BAT_TAG}-${ARCH}-unknown-linux-gnu.tar.gz" | |
curl -sLo bat.tar.gz "https://github.com/sharkdp/bat/releases/download/${BAT_TAG}/${BAT_TARBALL}" | |
tar -xzf bat.tar.gz | |
mv "./${BAT_TARBALL%.tar.gz}/bat" "$BIN_DIR/bat" | |
chmod +x "$BIN_DIR/bat" | |
echo "✅ Bat installed." | |
else | |
echo "✅ Bat is already installed. Skipping." | |
fi | |
if [ ! -f "$BIN_DIR/hx" ]; then | |
echo "Installing helix..." | |
HELIX_TAG=$(get_latest_gh_tag "helix-editor/helix") | |
HELIX_TARBALL="helix-${HELIX_TAG}-${ARCH}-linux.tar.xz" | |
curl -sLo helix.tar.gz "https://github.com/helix-editor/helix/releases/download/${HELIX_TAG}/${HELIX_TARBALL}" | |
tar -xf helix.tar.gz | |
mkdir -p "$CONFIG_DIR/helix/" | |
mv "./${HELIX_TARBALL%.tar.xz}/hx" "$BIN_DIR/hx" | |
mv "./${HELIX_TARBALL%.tar.xz}/runtime" "$CONFIG_DIR/helix" | |
chmod +x "$BIN_DIR/hx" | |
echo "✅ helix installed." | |
else | |
echo "✅ helix is already installed. Skipping." | |
fi | |
# -- Fzf -- | |
if [ ! -f "$BIN_DIR/fzf" ]; then | |
echo "Installing Fzf..." | |
FZF_TAG=$(get_latest_gh_tag "junegunn/fzf") | |
FZF_VERSION="${FZF_TAG#v}" | |
FZF_TARBALL="fzf-${FZF_VERSION}-linux_${FZF_ARCH}.tar.gz" | |
curl -sLo fzf.tar.gz "https://github.com/junegunn/fzf/releases/download/${FZF_TAG}/${FZF_TARBALL}" | |
tar -xzf fzf.tar.gz | |
mv ./fzf "$BIN_DIR/fzf" | |
chmod +x "$BIN_DIR/fzf" | |
echo "✅ Fzf installed." | |
else | |
echo "✅ Fzf is already installed. Skipping." | |
fi | |
# -- btop -- | |
if [ ! -f "$BIN_DIR/btop" ]; then | |
echo "Installing btop..." | |
BTOP_TAG=$(get_latest_gh_tag "aristocratos/btop") | |
BTOP_TARBALL="btop-${ARCH}-linux-musl.tbz" | |
curl -sLo btop.tbz "https://github.com/aristocratos/btop/releases/download/${BTOP_TAG}/${BTOP_TARBALL}" | |
tar -xjf btop.tbz | |
cp -p "./btop/btop" "${HOME}/.local/bin/" | |
chmod 755 "${HOME}/.local/bin/btop" | |
mkdir -p "${HOME}/.local/share/btop" | |
cp -pr ./bat/themes "${HOME}/.local/share/btop/" | |
echo "✅ btop installed." | |
else | |
echo "✅ btop is already installed. Skipping." | |
fi | |
# --- 4. Configure Shell --- | |
echo "--- Configuring shell settings ---" | |
# Configure Starship with a clean, AWS-aware prompt | |
echo "Configuring Starship prompt..." | |
cat > "$CONFIG_DIR/starship.toml" << 'EOF' | |
format = """🌐 $all""" | |
# Disable the default line break | |
[line_break] | |
disabled = true | |
[python] | |
disabled = true | |
[username] | |
show_always = true | |
format = '[$user]($style)@' | |
[status] | |
disabled = false | |
[cmd_duration] | |
disabled = false | |
# AWS module: Shows if AWS env vars/config are present | |
[aws] | |
symbol = "☁️ " | |
style = "bold yellow" | |
format = '[$symbol($profile)]($style) ' | |
disabled = false | |
# Hostname module: Always shows the machine name | |
[hostname] | |
ssh_only = false | |
style = "bold cyan" | |
format = '[$hostname]($style) ' | |
# Directory module: Shows the current working directory | |
[directory] | |
style = "bold blue" | |
[os] | |
disabled = false | |
EOF | |
cat > "$HOME/.oh-my-shell.bash" << 'EOF' | |
export PATH="$HOME/.local/bin:$PATH" | |
eval "$(starship init bash)" | |
eval "$(fzf --bash)" | |
eval "$(hl --shell-completions bash)" | |
# Modern tool aliases with icons | |
alias ls='eza -F --icons' | |
alias l='eza -lF --icons' | |
alias ll='eza -alF --icons' | |
alias grep='rg' | |
alias zj='zellij' | |
alias cat='bat --paging=never' | |
alias less='bat' | |
alias vim='hx' | |
alias top='btop' | |
alias sudo='sudo --preserve-env=PATH,HOME,STARSHIP_CONFIG,EZA_ICONS_AUTO,PROMPT_COMMAND -s' | |
export EZA_ICONS_AUTO=true | |
export COLORTERM=truecolor | |
EOF | |
if ! grep -q "# --- Custom Tools Setup ---" "$BASHRC"; then | |
echo "Updating .bashrc..." | |
cat >> "$BASHRC" << 'EOF' | |
source "$HOME/.oh-my-shell.bash" | |
EOF | |
fi | |
# --- 5. Finish --- | |
cat << EOF | |
-------------------------------------------------- | |
✅ Setup complete! Reloading shell to apply changes... | |
-------------------------------------------------- | |
EOF | |
# Reload the shell to activate all changes immediately | |
bash --login |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment