-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
113 lines (92 loc) · 2.74 KB
/
install.sh
File metadata and controls
113 lines (92 loc) · 2.74 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
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env bash
set -euo pipefail
REPO="misaelabanto/commita"
BINARY_NAME="commita"
INSTALL_DIR="/usr/local/bin"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
info() { echo -e "${CYAN}[commita]${NC} $*"; }
success() { echo -e "${GREEN}[commita]${NC} $*"; }
warn() { echo -e "${YELLOW}[commita]${NC} $*"; }
error() { echo -e "${RED}[commita]${NC} $*" >&2; exit 1; }
# Detect OS
detect_os() {
local os
os=$(uname -s | tr '[:upper:]' '[:lower:]')
case "$os" in
darwin) echo "darwin" ;;
linux) echo "linux" ;;
msys*|mingw*|cygwin*) echo "windows" ;;
*) error "Unsupported OS: $os" ;;
esac
}
# Detect architecture
detect_arch() {
local arch
arch=$(uname -m)
case "$arch" in
x86_64|amd64) echo "amd64" ;;
arm64|aarch64) echo "arm64" ;;
*) error "Unsupported architecture: $arch" ;;
esac
}
# Check for required tools
check_deps() {
for cmd in curl; do
if ! command -v "$cmd" &>/dev/null; then
error "'$cmd' is required but not installed."
fi
done
}
# Get latest release tag from GitHub API
get_latest_tag() {
local tag
tag=$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" \
| grep '"tag_name"' \
| sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$tag" ]; then
error "Failed to fetch the latest release tag. Check your internet connection or visit https://github.com/${REPO}/releases."
fi
echo "$tag"
}
main() {
check_deps
local os arch
os=$(detect_os)
arch=$(detect_arch)
# Windows is not supported via this script — direct users to releases
if [ "$os" = "windows" ]; then
error "Windows is not supported by this install script. Please download the binary manually from: https://github.com/${REPO}/releases"
fi
local tag
tag=$(get_latest_tag)
local binary_file="${BINARY_NAME}-${os}-${arch}"
local download_url="https://github.com/${REPO}/releases/download/${tag}/${binary_file}"
local tmp_file
tmp_file=$(mktemp)
info "Detected platform: ${os}/${arch}"
info "Latest version: ${tag}"
info "Downloading ${binary_file}..."
if ! curl -fsSL --progress-bar "$download_url" -o "$tmp_file"; then
rm -f "$tmp_file"
error "Download failed. Please check: ${download_url}"
fi
chmod +x "$tmp_file"
# Install to INSTALL_DIR, using sudo if needed
if [ -w "$INSTALL_DIR" ]; then
mv "$tmp_file" "${INSTALL_DIR}/${BINARY_NAME}"
else
warn "Installing to ${INSTALL_DIR} requires elevated privileges."
sudo mv "$tmp_file" "${INSTALL_DIR}/${BINARY_NAME}"
fi
success "${BINARY_NAME} ${tag} installed to ${INSTALL_DIR}/${BINARY_NAME}"
echo ""
echo " Get started: commita --help"
echo " Docs: https://github.com/${REPO}#readme"
echo ""
}
main "$@"