-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.sh
More file actions
99 lines (81 loc) · 3.15 KB
/
install.sh
File metadata and controls
99 lines (81 loc) · 3.15 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
#!/bin/bash
set -e
# Check if a custom pg_config path is provided
if [ $# -eq 1 ]; then
PG_CONFIG="$1"
else
PG_CONFIG=$(which pg_config 2>/dev/null || true)
fi
# Check if pg_config exists and is executable
if [ -z "$PG_CONFIG" ] || [ ! -x "$PG_CONFIG" ]; then
echo "Error: pg_config not found or not executable."
echo "Please install PostgreSQL development packages or provide the path to pg_config as an argument."
echo "Usage: $0 [/path/to/pg_config]"
exit 1
fi
echo "Using pg_config: $PG_CONFIG"
# Function to get the latest release version
get_latest_release() {
if [ -n "$GITHUB_TOKEN" ]; then
curl --silent -H "Authorization: Bearer $GITHUB_TOKEN" \
"https://api.github.com/repos/blitss/typeid-postgres/releases/latest"
else
curl --silent "https://api.github.com/repos/blitss/typeid-postgres/releases/latest"
fi \
| grep '"tag_name":' \
| sed -E 's/.*"([^"]+)".*/\1/'
}
# Detect OS and architecture
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
if [ "$ARCH" = "x86_64" ]; then
ARCH="amd64"
elif [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then
ARCH="arm64"
else
echo "Unsupported architecture: $ARCH"
exit 1
fi
# Get PostgreSQL version
PG_VERSION=$("$PG_CONFIG" --version | awk '{print $2}' | cut -d. -f1)
if [ -z "$PG_VERSION" ]; then
echo "PostgreSQL not found. Please install PostgreSQL and make sure 'pg_config' is in your PATH or provide the path to pg_config as an argument."
exit 1
fi
# Determine which TypeID-Postgres release to install.
# If the user sets the RELEASE_VERSION environment variable we honour it,
# otherwise fall back to fetching the latest release tag from GitHub.
if [ -z "$RELEASE_VERSION" ]; then
echo "RELEASE_VERSION not provided – fetching the latest release tag from GitHub …"
RELEASE_VERSION=$(get_latest_release)
echo "Latest release version: $RELEASE_VERSION"
else
echo "Using user-supplied RELEASE_VERSION: $RELEASE_VERSION"
fi
# Download URL
DOWNLOAD_URL="https://github.com/blitss/typeid-postgres/releases/download/${RELEASE_VERSION}/typeid-pg${PG_VERSION}-${OS}-${ARCH}.tar.gz"
# Temporary directory for extraction
TMP_DIR=$(mktemp -d)
# Download and extract
echo "Downloading TypeID extension from $DOWNLOAD_URL"
curl -L "$DOWNLOAD_URL" | tar xz -C "$TMP_DIR"
# Get PostgreSQL directories
EXTENSION_DIR=$("$PG_CONFIG" --sharedir)/extension
LIB_DIR=$("$PG_CONFIG" --pkglibdir)
# Install files
echo "Installing TypeID extension..."
if [ "$OS" = "darwin" ]; then
# macOS with Homebrew paths
cp "$TMP_DIR"/opt/homebrew/opt/postgresql*/share/postgresql*/extension/typeid.control "$EXTENSION_DIR"
cp "$TMP_DIR"/opt/homebrew/opt/postgresql*/share/postgresql*/extension/typeid--*.sql "$EXTENSION_DIR"
cp "$TMP_DIR"/opt/homebrew/opt/postgresql*/lib/postgresql/typeid.dylib "$LIB_DIR"
else
# Linux paths
cp "$TMP_DIR"/usr/share/postgresql/*/extension/typeid.control "$EXTENSION_DIR"
cp "$TMP_DIR"/usr/share/postgresql/*/extension/typeid--*.sql "$EXTENSION_DIR"
cp "$TMP_DIR"/usr/lib/postgresql/*/lib/typeid.so "$LIB_DIR"
fi
# Clean up
rm -rf "$TMP_DIR"
echo "TypeID extension installed successfully."
echo "To enable the extension, run: CREATE EXTENSION typeid;"