This repository has been archived by the owner on Jan 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup_libraries.sh
138 lines (117 loc) · 3.58 KB
/
setup_libraries.sh
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
#!/bin/bash
VERSION="v1.2.3"
ARCHITECTURE=$(uname -m)
DEBUG_MODE=false
parse_arguments() {
for arg in "$@"; do
case $arg in
--debug)
DEBUG_MODE=true
shift
;;
*)
;;
esac
done
}
download_library() {
local url=$1
local output_file=$2
echo -e "\e[34mDownloading library from: $url\e[0m"
wget -q -O "$output_file" "$url"
# shellcheck disable=SC2181
if [ $? -eq 0 ]; then
echo -e "\e[32mDownload successful: $output_file\e[0m"
else
echo -e "\e[31m[ERROR] Download failed!\e[0m"
exit 1
fi
}
unzip_library() {
local file=$1
local destination=$2
echo -e "\e[34mUnzipping $file to $destination\e[0m"
unzip -q "$file" -d "$destination"
# shellcheck disable=SC2181
if [ $? -eq 0 ]; then
echo -e "\e[32mUnzip successful!\e[0m"
else
echo -e "\e[31m[ERROR] Unzip failed!\e[0m"
exit 1
fi
}
clear_workspace() {
local file=$1
local destination=$2
if [ "$DEBUG_MODE" == true ]; then
echo -e "\e[34m[DEBUG] Clearing workspace: Removing $file and $destination\e[0m"
fi
rm -rf "$file" "$destination"
}
copy_files() {
local source_folder=$1
local header_file="$source_folder/include/ntgcalls.h"
if [ -f "$header_file" ]; then
cp -r "$header_file" "bindings/"
echo -e "\e[32mHeader file copied to bindings/ntgcalls.h\e[0m"
else
echo -e "\e[31m[ERROR] Header file ntgcalls.h not found in $source_folder/include/\e[0m"
exit 1
fi
local library_file="$source_folder/libntgcalls.so"
if [ -f "$library_file" ]; then
cp -r "$library_file" "bindings/lib/"
echo -e "\e[32mLibrary file copied to bindings/lib/libntgcalls.so\e[0m"
else
echo -e "\e[31m[ERROR] Library file libntgcalls.so not found in $source_folder/\e[0m"
exit 1
fi
}
parse_arguments "$@"
OS=$(uname -s)
echo -e "\e[34mDetected OS: $OS ($ARCHITECTURE)\e[0m"
case $OS in
Linux)
if [ "$ARCHITECTURE" == "x86_64" ]; then
URL="https://github.com/pytgcalls/ntgcalls/releases/download/$VERSION/ntgcalls.linux-x86_64-shared_libs.zip"
FILE_NAME="ntgcalls.linux-x86_64-shared_libs.zip"
# elif [ "$ARCHITECTURE" == "aarch64" ]; then
# URL="https://github.com/pytgcalls/ntgcalls/releases/download/$VERSION/ntgcalls.linux-arm64-shared_libs.zip"
# FILE_NAME="ntgcalls.linux-arm64-shared_libs.zip"
else
echo -e "\e[31m[ERROR] Unsupported architecture: $ARCHITECTURE\e[0m"
exit 1
fi
;;
# Darwin)
# if [ "$ARCHITECTURE" == "arm64" ]; then
# URL="https://github.com/pytgcalls/ntgcalls/releases/download/$VERSION/ntgcalls.macos-arm64-shared_libs.zip"
# FILE_NAME="ntgcalls.macos-arm64-shared_libs.zip"
# else
# echo -e "\e[31m[ERROR] Unsupported architecture: $ARCHITECTURE\e[0m"
# exit 1
# fi
# ;;
# MINGW*|MSYS*)
# URL="https://github.com/pytgcalls/ntgcalls/releases/download/$VERSION/ntgcalls.windows-x86_64-shared_libs.zip"
# FILE_NAME="ntgcalls.windows-x86_64-shared_libs.zip"
# ;;
*)
echo -e "\e[31m[ERROR] Unsupported OS: $OS\e[0m"
exit 1
;;
esac
echo -e "\e[34mEnter the folder to use for extraction ('release' or 'debug'). Default is 'release' if no input is provided:\e[0m"
read -r FOLDER_CHOICE
if [ -z "$FOLDER_CHOICE" ]; then
FOLDER_CHOICE="release"
fi
EXTRACT_FOLDER="$FOLDER_CHOICE"
echo -e "\e[32mUsing the '$EXTRACT_FOLDER' folder for extraction.\e[0m"
DEST_DIR="./output_folder"
clear_workspace "$FILE_NAME" "$DEST_DIR"
download_library "$URL" "$FILE_NAME"
unzip_library "$FILE_NAME" "$DEST_DIR"
copy_files "$DEST_DIR/$EXTRACT_FOLDER"
echo -e "\e[32mSetup completed successfully!\e[0m"
clear_workspace "$FILE_NAME" "$DEST_DIR"