Files
scripts-organizer/build.sh
2026-04-04 23:21:53 +09:00

65 lines
3.0 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
set -euo pipefail
BINARY_NAME="scripts-organizer"
BIN_DIR="$HOME/.local/bin"
BASHRC="$HOME/.bashrc"
RELEASE_BINARY="$(pwd)/target/release/$BINARY_NAME"
SYMLINK_TARGET="$BIN_DIR/$BINARY_NAME"
# ── Colours ────────────────────────────────────────────────────────────────────
BOLD='\033[1m'
DIM='\033[2m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
CYAN='\033[0;36m'
RESET='\033[0m'
step() { echo -e "\n${BOLD}${CYAN}$1${RESET}"; }
ok() { echo -e " ${GREEN}${RESET} $1"; }
skip() { echo -e " ${DIM} $1${RESET}"; }
warn() { echo -e " ${YELLOW}$1${RESET}"; }
divider() { echo -e "${DIM} ──────────────────────────────────────${RESET}"; }
# ── Header ─────────────────────────────────────────────────────────────────────
echo -e "\n${BOLD} scripts-organizer — build${RESET}"
divider
# ── 1. Build release ───────────────────────────────────────────────────────────
step "Building release binary"
cargo build --release --quiet
ok "Build complete → target/release/$BINARY_NAME"
# ── 2. Ensure ~/.local/bin exists ─────────────────────────────────────────────
step "Checking $BIN_DIR"
mkdir -p "$BIN_DIR"
ok "$BIN_DIR exists"
# ── 3. Add ~/.local/bin to PATH in ~/.bashrc if not already present ───────────
step "Checking PATH in $BASHRC"
PATH_EXPORT='export PATH="$HOME/.local/bin:$PATH"'
PATH_MARKER="# scripts-organizer: bin_dir"
if grep -qE '(^|:)[^#]*\.local/bin([^a-zA-Z0-9_]|$)' "$BASHRC" 2>/dev/null; then
skip "$BIN_DIR already declared in $BASHRC"
else
echo "" >> "$BASHRC"
echo "$PATH_MARKER" >> "$BASHRC"
echo "$PATH_EXPORT" >> "$BASHRC"
ok "Added $BIN_DIR to PATH in $BASHRC"
warn "Restart your shell or run: source $BASHRC"
fi
# ── 4. Symlink binary ──────────────────────────────────────────────────────────
step "Symlinking binary"
if [[ ! -L "$SYMLINK_TARGET" ]]; then
ln -sf "$RELEASE_BINARY" "$SYMLINK_TARGET"
ok "Symlinked → $SYMLINK_TARGET"
else
skip "$SYMLINK_TARGET already exists"
fi
# ── Done ───────────────────────────────────────────────────────────────────────
divider
echo -e "\n${BOLD}${GREEN} ✔ Done.${RESET} Run: ${BOLD}$BINARY_NAME${RESET}\n"