-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·204 lines (166 loc) · 5.84 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·204 lines (166 loc) · 5.84 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/bin/bash
# Installation script for auditmysite CLI
# Usage: curl -fsSL https://raw.githubusercontent.com/casoon/auditmysite/main/install.sh | bash
set -e
REPO="casoon/auditmysite"
BINARY_NAME="auditmysite"
INSTALL_DIR="${INSTALL_DIR:-$HOME/.local/bin}"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
error() {
echo -e "${RED}[ERROR]${NC} $1"
exit 1
}
# Detect OS and architecture
detect_platform() {
local os arch
os=$(uname -s | tr '[:upper:]' '[:lower:]')
arch=$(uname -m)
case "$os" in
linux)
case "$arch" in
x86_64|amd64)
echo "x86_64-unknown-linux-gnu"
;;
aarch64|arm64)
echo "aarch64-unknown-linux-gnu"
;;
*)
error "Unsupported architecture: $arch"
;;
esac
;;
darwin)
case "$arch" in
x86_64|amd64)
echo "x86_64-apple-darwin"
;;
aarch64|arm64)
echo "aarch64-apple-darwin"
;;
*)
error "Unsupported architecture: $arch"
;;
esac
;;
*)
error "Unsupported operating system: $os"
;;
esac
}
# Get latest version from GitHub
get_latest_version() {
curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'
}
verify_checksum() {
local archive_path checksum_path expected actual
archive_path="$1"
checksum_path="$2"
expected=$(awk '{print $1}' "$checksum_path")
if command -v sha256sum >/dev/null 2>&1; then
actual=$(sha256sum "$archive_path" | awk '{print $1}')
elif command -v shasum >/dev/null 2>&1; then
actual=$(shasum -a 256 "$archive_path" | awk '{print $1}')
else
error "sha256sum or shasum is required for checksum verification"
fi
if [ "$actual" != "$expected" ]; then
error "Checksum verification failed for $(basename "$archive_path")"
fi
}
# Resolve the install directory: use the directory of any existing installation
# found in PATH, so upgrades always replace the binary in the right place.
resolve_install_dir() {
local existing
existing=$(command -v "$BINARY_NAME" 2>/dev/null || true)
if [ -n "$existing" ]; then
dirname "$existing"
else
echo "${INSTALL_DIR:-$HOME/.local/bin}"
fi
}
# Download and install
install() {
local platform version archive_name checksum_name url checksum_url tmp_dir
platform=$(detect_platform)
version=$(get_latest_version)
if [ -z "$version" ]; then
error "Could not determine latest version"
fi
# Install into the directory of any existing binary so PATH order never
# causes an old installation to shadow the new one.
INSTALL_DIR=$(resolve_install_dir)
info "Installing $BINARY_NAME $version for $platform"
archive_name="${BINARY_NAME}-${version}-${platform}.tar.gz"
checksum_name="${archive_name}.sha256"
url="https://github.com/$REPO/releases/download/$version/${archive_name}"
checksum_url="https://github.com/$REPO/releases/download/$version/${checksum_name}"
tmp_dir=$(mktemp -d)
trap "rm -rf $tmp_dir" EXIT
info "Downloading from $url"
curl -fsSL "$url" -o "$tmp_dir/$archive_name"
info "Downloading checksum from $checksum_url"
curl -fsSL "$checksum_url" -o "$tmp_dir/$checksum_name"
info "Verifying checksum"
verify_checksum "$tmp_dir/$archive_name" "$tmp_dir/$checksum_name"
info "Extracting..."
tar -xzf "$tmp_dir/$archive_name" -C "$tmp_dir"
# Create install directory if it doesn't exist
mkdir -p "$INSTALL_DIR"
info "Installing to $INSTALL_DIR"
mv "$tmp_dir/$BINARY_NAME" "$INSTALL_DIR/"
chmod +x "$INSTALL_DIR/$BINARY_NAME"
# Check if install dir is in PATH
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
warn "$INSTALL_DIR is not in your PATH"
echo ""
echo "Add the following to your shell profile (.bashrc, .zshrc, etc.):"
echo ""
echo " export PATH=\"\$PATH:$INSTALL_DIR\""
echo ""
fi
info "Successfully installed $BINARY_NAME $version"
echo ""
echo "Run 'auditmysite --help' to get started"
}
# Check dependencies
check_dependencies() {
if ! command -v curl &> /dev/null; then
error "curl is required but not installed"
fi
if ! command -v tar &> /dev/null; then
error "tar is required but not installed"
fi
if ! command -v sha256sum &> /dev/null && ! command -v shasum &> /dev/null; then
error "sha256sum or shasum is required but not installed"
fi
# Check for Chrome (optional but recommended)
if ! command -v google-chrome &> /dev/null && ! command -v chromium &> /dev/null; then
if [ ! -f "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" ]; then
warn "Chrome/Chromium not found. auditmysite requires Chrome for accessibility checks."
echo " Install Chrome: https://www.google.com/chrome/"
echo " Or use: auditmysite --detect-chrome to check available browsers"
echo ""
fi
fi
}
main() {
echo ""
echo " ╔═══════════════════════════════════════╗"
echo " ║ auditmysite CLI Installer ║"
echo " ║ WCAG 2.1 Accessibility Checker ║"
echo " ╚═══════════════════════════════════════╝"
echo ""
check_dependencies
install
}
main "$@"