|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +if ! command -v go >/dev/null 2>&1; then |
| 6 | + echo "Error: Go is not installed. Please install Go 1.26.3 or higher." >&2 |
| 7 | + exit 1 |
| 8 | +fi |
| 9 | + |
| 10 | +echo "Building tusshi..." |
| 11 | +go build -o tusshi cmd/tusshi/main.go |
| 12 | + |
| 13 | +# determine target directories depending on privilege level |
| 14 | +if [ "$(id -u)" -eq 0 ]; then |
| 15 | + BIN_DIR="/usr/local/bin" |
| 16 | + APP_DIR="/usr/share/applications" |
| 17 | + ICON_DIR="/usr/share/icons/hicolor/512x512/apps" |
| 18 | + PIXMAP_DIR="/usr/share/pixmaps" |
| 19 | + echo "Installing system-wide..." |
| 20 | +else |
| 21 | + BIN_DIR="${HOME}/.local/bin" |
| 22 | + APP_DIR="${HOME}/.local/share/applications" |
| 23 | + ICON_DIR="${HOME}/.local/share/icons/hicolor/512x512/apps" |
| 24 | + PIXMAP_DIR="${HOME}/.local/share/icons" |
| 25 | + echo "Installing user-local (run with sudo for system-wide installation)..." |
| 26 | +fi |
| 27 | + |
| 28 | +mkdir -p "$BIN_DIR" "$APP_DIR" "$ICON_DIR" "$PIXMAP_DIR" |
| 29 | + |
| 30 | +cp -f tusshi "$BIN_DIR/" |
| 31 | +chmod +x "$BIN_DIR/tusshi" |
| 32 | + |
| 33 | +if [ -f "assets/tusshi.png" ]; then |
| 34 | + cp -f assets/tusshi.png "$ICON_DIR/tusshi.png" |
| 35 | + cp -f assets/tusshi.png "$PIXMAP_DIR/tusshi.png" |
| 36 | +fi |
| 37 | + |
| 38 | +if [ -f "tusshi.desktop" ]; then |
| 39 | + cp -f tusshi.desktop "$APP_DIR/" |
| 40 | +fi |
| 41 | + |
| 42 | +# update desktop environment database to pick up the new shortcut |
| 43 | +if command -v update-desktop-database >/dev/null 2>&1; then |
| 44 | + update-desktop-database "$APP_DIR" || true |
| 45 | +fi |
| 46 | + |
| 47 | +echo "Installation complete!" |
| 48 | +if [ "$(id -u)" -ne 0 ]; then |
| 49 | + # alert user if bin dir is not in PATH |
| 50 | + case ":$PATH:" in |
| 51 | + *:"$BIN_DIR":*) ;; |
| 52 | + *) |
| 53 | + echo "Warning: $BIN_DIR is not in your PATH." |
| 54 | + echo "Please add it to your shell configuration (e.g. ~/.bashrc or ~/.zshrc):" |
| 55 | + echo " export PATH=\"\$PATH:$BIN_DIR\"" |
| 56 | + ;; |
| 57 | + esac |
| 58 | +fi |
0 commit comments