-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·207 lines (172 loc) · 5.17 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·207 lines (172 loc) · 5.17 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
205
206
207
#!/bin/bash
set -e
# Tacet C/C++ Library Installer
# Downloads and installs pre-built tacet libraries from GitHub releases
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
info() {
echo -e "${GREEN}➜${NC} $*"
}
warn() {
echo -e "${YELLOW}⚠${NC} $*"
}
error() {
echo -e "${RED}✗${NC} $*" >&2
}
# Detect platform
detect_platform() {
local os arch target
os=$(uname -s | tr '[:upper:]' '[:lower:]')
arch=$(uname -m)
# Normalize architecture names
case "$arch" in
arm64|aarch64)
arch="arm64"
;;
x86_64|amd64)
arch="amd64"
;;
*)
error "Unsupported architecture: $arch"
error "Supported: arm64, amd64"
exit 1
;;
esac
# Normalize OS names
case "$os" in
darwin)
target="darwin-${arch}"
;;
linux)
target="linux-${arch}"
;;
*)
error "Unsupported operating system: $os"
error "Supported: macOS (darwin), Linux"
exit 1
;;
esac
echo "$target"
}
# Get latest release version from GitHub API
get_latest_version() {
local api_url="https://api.github.com/repos/agucova/tacet/releases/latest"
if command -v curl >/dev/null 2>&1; then
curl -fsSL "$api_url" | grep '"tag_name"' | sed -E 's/.*"tag_name": "([^"]+)".*/\1/'
else
error "curl is required but not installed"
exit 1
fi
}
# Download file from URL
download_file() {
local url=$1
local output=$2
info "Downloading $(basename "$output")..."
if ! curl -fSL --progress-bar -o "$output" "$url"; then
error "Failed to download: $url"
return 1
fi
return 0
}
# Check if we have write permissions to a directory
check_write_permission() {
local dir=$1
if [ -w "$dir" ] || touch "${dir}/.write_test" 2>/dev/null; then
rm -f "${dir}/.write_test" 2>/dev/null || true
return 0
else
return 1
fi
}
# Check sudo requirement and exit with instructions if needed
check_sudo_requirement() {
local prefix=$1
if ! check_write_permission "$prefix"; then
error "Installation to $prefix requires elevated privileges"
echo ""
echo "Please re-run the installation with sudo:"
echo ""
if [ -f "$0" ]; then
echo " sudo -E bash \"$0\""
else
echo " curl -fsSL https://raw.githubusercontent.com/agucova/tacet/main/install.sh | sudo -E bash"
fi
echo ""
echo "Or choose a different PREFIX where you have write access:"
echo ""
echo " PREFIX=\$HOME/.local bash <(curl -fsSL https://raw.githubusercontent.com/agucova/tacet/main/install.sh)"
echo ""
exit 1
fi
}
# Main installation function
main() {
info "Tacet C/C++ Library Installer"
echo
# Configuration
VERSION="${VERSION:-latest}"
PREFIX="${PREFIX:-/usr/local}"
TMPDIR=$(mktemp -d)
# Ensure cleanup on exit
trap 'rm -rf "$TMPDIR"' EXIT
# Detect platform
TARGET=$(detect_platform)
info "Detected platform: $TARGET"
# Resolve version
if [ "$VERSION" = "latest" ]; then
VERSION=$(get_latest_version)
if [ -z "$VERSION" ]; then
error "Failed to determine latest version"
exit 1
fi
info "Latest version: $VERSION"
else
info "Installing version: $VERSION"
fi
# Check write permissions (exit if sudo required)
check_sudo_requirement "$PREFIX"
# Download artifacts
BASE_URL="https://github.com/agucova/tacet/releases/download/${VERSION}"
cd "$TMPDIR"
download_file "${BASE_URL}/libtacet_c-${TARGET}.a" "libtacet_c.a" || exit 1
download_file "${BASE_URL}/tacet.h" "tacet.h" || exit 1
download_file "${BASE_URL}/tacet.hpp" "tacet.hpp" || exit 1
download_file "${BASE_URL}/tacet-${TARGET}.pc" "tacet.pc.template" || exit 1
# Create installation directories
info "Creating directories..."
mkdir -p "${PREFIX}/lib"
mkdir -p "${PREFIX}/include/tacet"
mkdir -p "${PREFIX}/lib/pkgconfig"
# Install files
info "Installing files to $PREFIX..."
cp libtacet_c.a "${PREFIX}/lib/"
cp tacet.h "${PREFIX}/include/tacet/"
cp tacet.hpp "${PREFIX}/include/tacet/"
# Generate final pkg-config file with actual paths
sed -e "s|@PREFIX@|${PREFIX}|g" \
-e "s|@LIBDIR@|${PREFIX}/lib|g" \
-e "s|@INCLUDEDIR@|${PREFIX}/include/tacet|g" \
tacet.pc.template > "${PREFIX}/lib/pkgconfig/tacet.pc"
# Get file sizes for display
LIB_SIZE=$(du -h "${PREFIX}/lib/libtacet_c.a" | cut -f1)
echo
info "Installation complete!"
echo
echo "Files installed:"
echo " ${PREFIX}/lib/libtacet_c.a ($LIB_SIZE)"
echo " ${PREFIX}/include/tacet/tacet.h"
echo " ${PREFIX}/include/tacet/tacet.hpp"
echo " ${PREFIX}/lib/pkgconfig/tacet.pc"
echo
echo "Verify installation:"
echo " pkg-config --modversion tacet"
echo
echo "Usage in your project:"
echo " cc myfile.c \$(pkg-config --cflags --libs tacet) -o myapp"
}
# Run main function
main "$@"