-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·65 lines (65 loc) · 1.44 KB
/
install.sh
File metadata and controls
executable file
·65 lines (65 loc) · 1.44 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
#!/bin/bash
set -e
REPO_URL="${REPO_URL:-https://github.com/xscriptor/xclock.git}"
INSTALL_DIR="/usr/local/bin"
TEMP_DIR="$(mktemp -d)"
OS="$(uname -s)"
detect_id() {
if [ "$OS" = "Darwin" ]; then
echo "macos"
return
fi
if [ -f /etc/os-release ]; then
. /etc/os-release
echo "${ID}"
return
fi
echo "unknown"
}
ID="$(detect_id)"
ensure_tools() {
case "$ID" in
ubuntu|debian)
sudo apt-get update -y
sudo apt-get install -y build-essential curl git
;;
fedora)
sudo dnf install -y make gcc curl git
;;
arch|manjaro)
sudo pacman -Sy --noconfirm base-devel curl git
;;
macos)
xcode-select -p >/dev/null 2>&1 || xcode-select --install || true
;;
*)
:
;;
esac
}
ensure_rust() {
if ! command -v cargo >/dev/null 2>&1; then
curl -fsSL https://sh.rustup.rs | sh -s -- -y
if [ -f "$HOME/.cargo/env" ]; then
. "$HOME/.cargo/env"
fi
fi
}
ensure_tools
ensure_rust
if ! command -v cargo >/dev/null 2>&1; then
echo "Rust installation failed"
exit 1
fi
if [ -f "Cargo.toml" ] && grep -q "name = \"xclock\"" "Cargo.toml"; then
cargo build --release
sudo install -m 0755 target/release/xclock "$INSTALL_DIR/xclock"
else
git clone "$REPO_URL" "$TEMP_DIR/xclock"
cd "$TEMP_DIR/xclock"
cargo build --release
sudo install -m 0755 target/release/xclock "$INSTALL_DIR/xclock"
cd -
rm -rf "$TEMP_DIR"
fi
echo "Installed $INSTALL_DIR/xclock"