-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
107 lines (86 loc) · 3.18 KB
/
install.sh
File metadata and controls
107 lines (86 loc) · 3.18 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
#!/bin/bash
set -e
echo "Checking for Clang installation..."
if ! command -v clang &>/dev/null; then
echo "Clang not found. Installing LLVM, Clang, and libclang..."
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
if command -v apt-get &>/dev/null; then
echo "Detected Ubuntu/Debian"
sudo apt-get update
sudo apt-get install -y llvm-dev libclang-dev clang
elif command -v pacman &>/dev/null; then
echo "Detected Arch Linux"
sudo pacman -Syu --noconfirm llvm clang
elif command -v dnf &>/dev/null; then
echo "Detected Fedora"
sudo dnf install -y llvm-devel clang
else
echo "Unsupported Linux distribution. Please install LLVM & Clang manually"
exit 1
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
echo "Detected macOS"
if ! command -v brew &>/dev/null; then
echo "Homebrew not found. Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
brew update
brew install llvm
else
echo "Unsupported OS : $OSTYPE"
exit 1
fi
else
echo "Clang is already installed"
fi
if ! command -v cargo &> /dev/null; then
echo "Cargo is not installed. Installing Rust toolchain..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"
else
echo "Cargo is installed. Updating Rust toolchain..."
rustup update
fi
echo "Cleaning and building the project in release mode..."
cargo clean
cargo build --release
echo "Build complete !"
OS=$(uname)
if [[ "$OS" == "MINGW"* ]] || [[ "$OS" == "MSYS"* ]] || [[ "$OS" == "CYGWIN"* ]]; then
EXT_SUFFIX="dll"
elif [[ "$OS" == "Darwin" ]]; then
EXT_SUFFIX="dylib"
else
EXT_SUFFIX="so"
fi
echo "Detected OS : $OS , using extension : $EXT_SUFFIX"
EXT_FILE=$(find / -type f -iname "libtgcrypto.${EXT_SUFFIX}" 2>/dev/null | head -n 1)
if [ -z "$EXT_FILE" ]; then
echo "Error : No extension file found in target/release"
exit 1
fi
echo "Found extension file : $EXT_FILE"
EXT_DIR=$(php-config --extension-dir 2>/dev/null)
if [ -z "$EXT_DIR" ]; then
echo "Error : Could not determine PHP extension directory via php-config"
exit 1
fi
echo "PHP extension directory : $EXT_DIR"
OUTPUT_FILE="$EXT_DIR/tgcrypto.$EXT_SUFFIX"
cp "$EXT_FILE" "$OUTPUT_FILE" || { echo "Failed to copy extension file"; exit 1; }
PHP_INI=$(php --ini | awk -F': ' '/Loaded Configuration File/ {print $2}' | xargs)
if [ -z "$PHP_INI" ]; then
echo "Error: Could not find php.ini file."
exit 1
fi
if grep -q "^extension=tgcrypto.$EXT_SUFFIX" "$PHP_INI"; then
echo "tgcrypto.$EXT_SUFFIX is already enabled in php.ini"
else
echo "Adding extension=tgcrypto.$EXT_SUFFIX to php.ini"
echo -e "\nextension=tgcrypto.$EXT_SUFFIX" >> "$PHP_INI"
echo "tgcrypto.$EXT_SUFFIX has been added to php.ini"
fi
echo "Verifying PHP extension load..."
php -m | grep -i tgcrypto && echo "extension is loaded !" || echo "extension is not loaded. Check your configuration"
php -r "print('Version : '.TGCRYPTO_VERSION.PHP_EOL);"
echo "Installation successful !"