-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall-lib.sh
More file actions
executable file
·133 lines (116 loc) · 3.84 KB
/
Copy pathinstall-lib.sh
File metadata and controls
executable file
·133 lines (116 loc) · 3.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
#!/bin/bash
# install-lib.sh - Install SochDB native library for Go SDK
#
# This script installs libsochdb_storage to system paths so the Go SDK
# can find it automatically without manual CGO_LDFLAGS setup.
set -e
# Determine OS
OS="$(uname -s)"
ARCH="$(uname -m)"
# Color output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo "🔧 SochDB Native Library Installer"
echo "=================================="
echo ""
# Check if running as root for system install
NEED_SUDO=""
if [ "$EUID" -ne 0 ]; then
NEED_SUDO="sudo"
echo -e "${YELLOW}Note: System installation requires sudo privileges${NC}"
fi
# Find the native library
SOCHDB_ROOT="${SOCHDB_ROOT:-}"
if [ -z "$SOCHDB_ROOT" ]; then
# Try to find it relative to this script
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [ -f "$SCRIPT_DIR/../sochdb/target/debug/libsochdb_storage.dylib" ]; then
SOCHDB_ROOT="$SCRIPT_DIR/../sochdb"
elif [ -f "$SCRIPT_DIR/../sochdb/target/release/libsochdb_storage.dylib" ]; then
SOCHDB_ROOT="$SCRIPT_DIR/../sochdb"
elif [ -f "$SCRIPT_DIR/../sochdb/target/debug/libsochdb_storage.so" ]; then
SOCHDB_ROOT="$SCRIPT_DIR/../sochdb"
else
echo -e "${RED}Error: Cannot find libsochdb_storage${NC}"
echo "Please set SOCHDB_ROOT environment variable to the sochdb repository path"
echo "Example: export SOCHDB_ROOT=/path/to/sochdb"
exit 1
fi
fi
# Determine build type (prefer release, fallback to debug)
BUILD_TYPE="release"
if [ ! -d "$SOCHDB_ROOT/target/release" ]; then
BUILD_TYPE="debug"
echo -e "${YELLOW}Using debug build (release not found)${NC}"
fi
# Set library source and destination based on OS
case "$OS" in
Darwin)
LIB_SRC="$SOCHDB_ROOT/target/$BUILD_TYPE/libsochdb_storage.dylib"
LIB_DEST="/usr/local/lib/libsochdb_storage.dylib"
PKG_CONFIG_DEST="/usr/local/lib/pkgconfig/libsochdb_storage.pc"
;;
Linux)
LIB_SRC="$SOCHDB_ROOT/target/$BUILD_TYPE/libsochdb_storage.so"
LIB_DEST="/usr/local/lib/libsochdb_storage.so"
PKG_CONFIG_DEST="/usr/local/lib/pkgconfig/libsochdb_storage.pc"
;;
MINGW*|MSYS*|CYGWIN*)
echo -e "${RED}Windows installation not yet supported${NC}"
echo "Please add the library path to your PATH environment variable manually"
exit 1
;;
*)
echo -e "${RED}Unsupported operating system: $OS${NC}"
exit 1
;;
esac
# Check if library exists
if [ ! -f "$LIB_SRC" ]; then
echo -e "${RED}Error: Library not found at $LIB_SRC${NC}"
echo "Please build SochDB first:"
echo " cd $SOCHDB_ROOT"
echo " cargo build --release"
exit 1
fi
echo "📦 Found library: $LIB_SRC"
echo "📍 Install destination: $LIB_DEST"
echo ""
# Create directories if needed
$NEED_SUDO mkdir -p "$(dirname "$LIB_DEST")"
$NEED_SUDO mkdir -p "$(dirname "$PKG_CONFIG_DEST")"
# Copy library
echo "📋 Copying library..."
$NEED_SUDO cp "$LIB_SRC" "$LIB_DEST"
$NEED_SUDO chmod 755 "$LIB_DEST"
# Create pkg-config file
echo "📝 Creating pkg-config file..."
cat > /tmp/libsochdb_storage.pc <<EOF
prefix=/usr/local
exec_prefix=\${prefix}
libdir=\${exec_prefix}/lib
includedir=\${prefix}/include
Name: libsochdb_storage
Description: SochDB Native Storage Library
Version: 0.4.0
Libs: -L\${libdir} -lsochdb_storage
Cflags: -I\${includedir}
EOF
$NEED_SUDO mv /tmp/libsochdb_storage.pc "$PKG_CONFIG_DEST"
# Update library cache on Linux
if [ "$OS" = "Linux" ]; then
echo "🔄 Updating library cache..."
$NEED_SUDO ldconfig
fi
echo ""
echo -e "${GREEN}✅ Installation complete!${NC}"
echo ""
echo "The Go SDK will now work without manual CGO_LDFLAGS setup:"
echo " go get github.com/sochdb/sochdb-go@v0.4.0"
echo " go run your-app.go"
echo ""
echo "To uninstall:"
echo " $NEED_SUDO rm $LIB_DEST"
echo " $NEED_SUDO rm $PKG_CONFIG_DEST"