-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·103 lines (92 loc) · 3.48 KB
/
setup.sh
File metadata and controls
executable file
·103 lines (92 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env bash
# ktop installer — installs ktop as a command
# Usage:
# ./setup.sh Install to ~/.local/bin (no sudo needed)
# ./setup.sh --system Install to /usr/local/bin (needs sudo)
set -euo pipefail
REPO_DIR="$(cd "$(dirname "$0")" && pwd)"
VENV_DIR="$REPO_DIR/.venv"
# Checkout latest tagged release (skip if not a git repo, no tags, or on a feature branch)
if git -C "$REPO_DIR" rev-parse --git-dir &>/dev/null; then
CURRENT_BRANCH=$(git -C "$REPO_DIR" symbolic-ref --short HEAD 2>/dev/null || true)
DEFAULT_BRANCH=$(git -C "$REPO_DIR" symbolic-ref --short refs/remotes/origin/HEAD 2>/dev/null | sed 's|origin/||' || echo "master")
if [ "$CURRENT_BRANCH" != "$DEFAULT_BRANCH" ] && [ -n "$CURRENT_BRANCH" ]; then
echo "==> On branch $CURRENT_BRANCH — skipping tag checkout"
else
LATEST_TAG=$(git -C "$REPO_DIR" describe --tags --abbrev=0 2>/dev/null || true)
if [ -n "$LATEST_TAG" ]; then
echo "==> Checking out release $LATEST_TAG"
git -C "$REPO_DIR" checkout --quiet "$LATEST_TAG"
fi
fi
fi
# Determine install location
if [ "${1:-}" = "--system" ]; then
INSTALL_DIR="/usr/local/bin"
NEED_SUDO=true
else
INSTALL_DIR="$HOME/.local/bin"
NEED_SUDO=false
mkdir -p "$INSTALL_DIR"
fi
INSTALL_PATH="$INSTALL_DIR/ktop"
echo "==> Installing ktop from $REPO_DIR"
echo " Target: $INSTALL_PATH"
# 1. Create/update virtual environment
if [ ! -d "$VENV_DIR" ]; then
echo " Creating virtual environment..."
if ! python3 -m venv "$VENV_DIR" 2>/dev/null; then
echo " python3-venv not found, installing it..."
if command -v apt-get &>/dev/null; then
sudo apt-get install -y python3-venv
elif command -v dnf &>/dev/null; then
sudo dnf install -y python3-libs
elif command -v pacman &>/dev/null; then
sudo pacman -S --noconfirm python
else
echo "ERROR: python3-venv is required. Install it with your package manager."
exit 1
fi
python3 -m venv "$VENV_DIR"
fi
fi
echo " Installing dependencies..."
"$VENV_DIR/bin/pip" install --quiet --upgrade pip
"$VENV_DIR/bin/pip" install --quiet -r "$REPO_DIR/requirements.txt"
# 2. Write wrapper script
WRAPPER=$(mktemp)
cat > "$WRAPPER" <<EOF
#!/usr/bin/env bash
exec "$VENV_DIR/bin/python" "$REPO_DIR/ktop.py" "\$@"
EOF
if [ "$NEED_SUDO" = true ]; then
sudo install -m 755 "$WRAPPER" "$INSTALL_PATH"
else
install -m 755 "$WRAPPER" "$INSTALL_PATH"
fi
rm -f "$WRAPPER"
# 3. Ensure ~/.local/bin is in PATH
if [ "$NEED_SUDO" = false ]; then
case ":$PATH:" in
*":$INSTALL_DIR:"*) ;;
*)
export PATH="$INSTALL_DIR:$PATH"
# Offer to persist to shell profile
printf " Add $INSTALL_DIR to PATH in shell config? [Y/n] "
read -r reply
if [ -z "$reply" ] || [ "$reply" = "y" ] || [ "$reply" = "Y" ]; then
for rc in "$HOME/.bashrc" "$HOME/.zshrc"; do
if [ -f "$rc" ] && ! grep -q "$INSTALL_DIR" "$rc" 2>/dev/null; then
echo "export PATH=\"$INSTALL_DIR:\$PATH\"" >> "$rc"
echo " Updated $(basename "$rc")"
fi
done
fi
;;
esac
fi
echo "==> Done! Launching ktop..."
"$INSTALL_PATH" "$@"
echo ""
echo " To run ktop again, open a new terminal and type: ktop"
echo " (restart your terminal session for PATH changes to take effect)"