forked from anomalyco/opentui
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·150 lines (124 loc) · 3.93 KB
/
install.sh
File metadata and controls
executable file
·150 lines (124 loc) · 3.93 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
#!/bin/bash
set -e
# OpenTUI System Installation Script
# Installs OpenTUI headers and libraries system-wide
REPO="sst/opentui"
RELEASE_URL="https://github.com/$REPO/releases/latest/download"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo -e "${GREEN}OpenTUI System Installer${NC}"
echo "Installing OpenTUI headers and libraries..."
# Detect platform
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
case "$ARCH" in
x86_64|amd64) ARCH="x86_64" ;;
arm64|aarch64) ARCH="aarch64" ;;
*) echo -e "${RED}Error: Unsupported architecture: $ARCH${NC}"; exit 1 ;;
esac
case "$OS" in
darwin) OS="macos" ;;
linux) OS="linux" ;;
mingw*|cygwin*|msys*) OS="windows" ;;
*) echo -e "${RED}Error: Unsupported OS: $OS${NC}"; exit 1 ;;
esac
PLATFORM="${ARCH}-${OS}"
echo "Detected platform: $PLATFORM"
# Determine installation paths
if [[ "$OS" == "macos" ]]; then
INCLUDE_DIR="/opt/homebrew/include"
LIB_DIR="/opt/homebrew/lib"
if [[ ! -d "$INCLUDE_DIR" ]]; then
INCLUDE_DIR="/usr/local/include"
LIB_DIR="/usr/local/lib"
fi
else
INCLUDE_DIR="/usr/local/include"
LIB_DIR="/usr/local/lib"
fi
echo "Installation paths:"
echo " Headers: $INCLUDE_DIR"
echo " Libraries: $LIB_DIR"
# Check for sudo if needed
if [[ ! -w "$INCLUDE_DIR" ]] || [[ ! -w "$LIB_DIR" ]]; then
if [[ $EUID -ne 0 ]]; then
echo -e "${YELLOW}Administrator privileges required for system installation${NC}"
echo "Please run with sudo or as administrator"
exit 1
fi
fi
# Create temporary directory
TEMP_DIR=$(mktemp -d)
trap "rm -rf $TEMP_DIR" EXIT
echo "Downloading assets..."
# Download header file
echo " - opentui.h"
curl -L -o "$TEMP_DIR/opentui.h" "$RELEASE_URL/opentui.h" || {
echo -e "${RED}Error: Failed to download header file${NC}"
exit 1
}
# Download library for current platform
case "$OS" in
macos)
LIB_FILE="libopentui.dylib"
ASSET_NAME="libopentui-$PLATFORM.dylib"
;;
linux)
LIB_FILE="libopentui.so"
ASSET_NAME="libopentui-$PLATFORM.so"
;;
windows)
LIB_FILE="opentui.dll"
ASSET_NAME="opentui-$PLATFORM.dll"
;;
esac
echo " - $ASSET_NAME"
curl -L -o "$TEMP_DIR/$LIB_FILE" "$RELEASE_URL/$ASSET_NAME" || {
echo -e "${RED}Error: Failed to download library for $PLATFORM${NC}"
exit 1
}
# Install files
echo "Installing files..."
echo " - Installing header to $INCLUDE_DIR/opentui.h"
cp "$TEMP_DIR/opentui.h" "$INCLUDE_DIR/opentui.h" || {
echo -e "${RED}Error: Failed to install header file${NC}"
exit 1
}
echo " - Installing library to $LIB_DIR/$LIB_FILE"
cp "$TEMP_DIR/$LIB_FILE" "$LIB_DIR/$LIB_FILE" || {
echo -e "${RED}Error: Failed to install library file${NC}"
exit 1
}
# Set permissions
chmod 644 "$INCLUDE_DIR/opentui.h"
chmod 755 "$LIB_DIR/$LIB_FILE"
# Install pkg-config file
PKG_CONFIG_DIR="/usr/local/lib/pkgconfig"
if [[ "$OS" == "macos" ]] && [[ -d "/opt/homebrew/lib/pkgconfig" ]]; then
PKG_CONFIG_DIR="/opt/homebrew/lib/pkgconfig"
fi
echo " - Installing pkg-config file to $PKG_CONFIG_DIR/opentui.pc"
mkdir -p "$PKG_CONFIG_DIR"
# Download and install pkg-config template
curl -L -o "$TEMP_DIR/opentui.pc.in" "$RELEASE_URL/opentui.pc.in" || {
echo -e "${YELLOW}Warning: Could not download pkg-config template${NC}"
}
if [[ -f "$TEMP_DIR/opentui.pc.in" ]]; then
sed "s|@PREFIX@|${INCLUDE_DIR%/include}|g; s|@VERSION@|latest|g" "$TEMP_DIR/opentui.pc.in" > "$PKG_CONFIG_DIR/opentui.pc"
chmod 644 "$PKG_CONFIG_DIR/opentui.pc"
fi
# Update library cache on Linux
if [[ "$OS" == "linux" ]]; then
echo "Updating library cache..."
ldconfig 2>/dev/null || true
fi
echo -e "${GREEN}✓ OpenTUI installed successfully!${NC}"
echo ""
echo "You can now use OpenTUI in your Go projects:"
echo " go get github.com/dnakov/opentui/packages/go"
echo ""
echo "To uninstall:"
echo " sudo rm $INCLUDE_DIR/opentui.h $LIB_DIR/$LIB_FILE"