Skip to content

Commit

Permalink
add build.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyShorokhov committed Apr 23, 2024
1 parent e3464be commit 2d7492f
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 15 deletions.
117 changes: 117 additions & 0 deletions .vscode/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#!/bin/bash

# Define color codes
RED="\e[31m"
ORANGE="\e[33m"
GREEN="\e[32m"
WHITE_BG="\e[47m"
RESET="\e[0m"

# Function to print colored messages
print_color() {
local color="$1"
local message="$2"
echo -e "${color}${message}${RESET}"
}


# Define directories
srcDir="$1"

# Check if directory is not empty
if [ -z "$srcDir" ]; then
print_color $RED "❌ Error: Argument 1 not provided"
exit 1
fi

# Check if directory does not exist
if [ ! -d "$srcDir" ]; then
print_color $RED "❌ Error: Directory '$srcDir' not found"
exit 1
fi

# Make amxxpc happy to find amxxpc32.so nearly
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$srcDir/scripting

destinationDir="$2"

# Check if directory is not empty
if [ -z "$destinationDir" ]; then
print_color $RED "❌ Error: Argument 2 not provided"
exit 1
fi

# Check if directory does not exist
if [ ! -d "$destinationDir" ]; then
print_color $RED "❌ Error: Directory '$destinationDir' not found"
exit 1
fi

scriptingDir="$destinationDir/scripting"



# Function to compile a .sma file
compile_sma() {
local smaFile="$1"
local outputPluginDir="$2"

pluginName=$(basename "${smaFile%.sma}")
relativeDir=$(dirname "${smaFile#$srcDir}")
outputPlugin="$outputPluginDir/${pluginName}.amxx"

# Create the output plugin directory if it doesn't exist
mkdir -p "$outputPluginDir"

# Print the name of the .sma file with white background
# print_color $WHITE_BG " - Compiling: $(basename $smaFile)"

# Get the last modification time of the output plugin file
lastModTime=$(stat -c %Y "$smaFile" 2>/dev/null)
now=$(date +%s)
diff=$((now-lastModTime))

# Check if the file exists and its last modification time is within the last minute

# Compile the .sma file and capture its output, excluding the lines with version and copyright info
compile_output=$("$scriptingDir/amxxpc" \
"$smaFile" \
-i"$srcDir/scripting" \
-i"$srcDir/scripting/include" \
-i"$srcDir/scripting/ReDeathmatch" \
-o"$outputPlugin" 2>&1 | grep -vE "AMX Mod X Compiler|Copyright|Could not locate output file")

# Check if there are any errors or warnings in the compile output
if echo "$compile_output" | grep -qi "error"; then
error_lines=$(echo "$compile_output" | grep -i "error" | sed 's/.*scripting\///')
warning_lines=$(echo "$compile_output" | grep -i "warning" | sed 's/.*scripting\///')
print_color $RED "$error_lines"
if [ -n "$warning_lines" ]; then
print_color $ORANGE "⚠️ $warning_lines"
fi
elif echo "$compile_output" | grep -qi "warning"; then
warning_lines=$(echo "$compile_output" | grep -i "warning" | sed 's/.*scripting\///')
print_color $ORANGE "⚠️ $warning_lines"
else
print_color $GREEN " ✅ Compiled: $(basename $smaFile)"
fi

}

# Find and compile all .sma files in the source directory and its subdirectories
find $srcDir -name "*.sma" -type f | while read smaFile; do
relativeDir=$(dirname "${smaFile#$srcDir/scripting}")
outputPluginDir="$destinationDir/plugins$relativeDir"
compile_sma "$smaFile" "$outputPluginDir"
done

needCopyOther=$3
if [ "$needCopyOther" ]; then
echo ""

# Copy directories without confirmation with green messages
print_color $GREEN " - Copying configs..."
cp -an $srcDir/configs/* $destinationDir/configs/
print_color $GREEN " - Copying data..."
cp -an $srcDir/data/* $destinationDir/data/
fi
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"sarrus.sourcepawn-vscode"
]
}
7 changes: 5 additions & 2 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
"type": "shell",
"command": "bash",
"args": [
".vscode/build.sh"
".vscode/build.sh",
"$PWD/cstrike/addons/amxmodx",
"D:/Dev/HLDS_Server/cstrike/addons/amxmodx",
"1"
],
"group": {
"kind": "build",
Expand All @@ -31,7 +34,7 @@
{
"type": "shell",
"label": "Run HLDS container",
"command": "docker run --rm -ti -p 26900-27020:26900-27020/udp redeathmatch:${input:mod}",
"command": "docker run --rm -ti -p 26900-27020:26900-27020/udp redeathmatch:${input:mod} ./hlds_run -game ${input:mod} +maxplayers 32 -bots +ip 0.0.0.0 -port 27016 +map de_dust2",
"dependsOn": [
"Build ReDeathmatch Image"
],
Expand Down
26 changes: 13 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ RUN set -x \
ca-certificates=20240203 \
curl=8.5.0-2 \
libarchive-tools=3.7.2-1 \
lib32stdc++6=14-20240201-3 \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /usr/local/bin/
Expand All @@ -19,7 +20,7 @@ ADD --chmod=755 https://raw.githubusercontent.com/hldsdocker/rehlds/master/utils
WORKDIR /root/hlds/cstrike

# Install Metamod-R
RUN releaseLink=$(GetGithubReleaseUrl "theAsmodai/metamod-r" "latest") \
RUN releaseLink="https://github.com/theAsmodai/metamod-r/releases/download/1.3.0.149/metamod-bin-1.3.0.149.zip" \
&& curl -sSL ${releaseLink} | bsdtar -xf - --exclude='*.dll' --exclude='*.pdb' addons/*

# Install AMXModX 1.9.0
Expand All @@ -28,7 +29,7 @@ RUN curl -sSL ${AMXModX_URL} | bsdtar -xf - addons/ \
&& echo "linux addons/amxmodx/dlls/amxmodx_mm_i386.so" > addons/metamod/plugins.ini

# Install ReAPI
RUN releaseLink=$(GetGithubReleaseUrl "s1lentq/reapi" "latest") \
RUN releaseLink="https://github.com/s1lentq/reapi/releases/download/5.24.0.300/reapi-bin-5.24.0.300.zip" \
&& curl -sSL ${releaseLink} | bsdtar -xf - --exclude='*.dll' --exclude='*.pdb' addons/

# Inltall ReDeathmatch
Expand All @@ -40,19 +41,19 @@ RUN releaseLink=$(GetGithubReleaseUrl "s1lentq/reapi" "latest") \

COPY cstrike .

WORKDIR /root/hlds/cstrike/addons/amxmodx/scripting/

SHELL ["/bin/bash", "-c"]
RUN compile() { \
sourcefile=$1 \
amxxfile="$(echo $sourcefile | sed -e 's/\.sma$/.amxx/')" \
output_path="../plugins/$amxxfile" \
# mkdir -p $(dirname $output_path) \
echo -n "Compiling $sourcefile ... "; \
} \
&& export -f compile \
&& ls -la && find * -type f -name "*.sma" -exec bash -c 'compile "$0"' {} \;

WORKDIR /usr/local/bin/
COPY --chmod=755 .vscode/build.sh BuildAMXXPlugins

WORKDIR /root/hlds/cstrike/addons/amxmodx/
# COPY --chmod=755 .vscode/build.sh .

RUN BuildAMXXPlugins . .


WORKDIR /root/hlds/cstrike/
ARG YaPB_URL="https://github.com/yapb/yapb/releases/download/4.4.957/yapb-4.4.957-linux.tar.xz"
RUN curl -sSL ${YaPB_URL} | bsdtar -xf - addons/ \
&& echo "linux addons/yapb/bin/yapb.so" >> addons/metamod/plugins.ini
Expand All @@ -65,4 +66,3 @@ COPY --chown=${APPUSER}:${APPUSER} --chmod=755 --from=build_stage /root/hlds/cst

# Activate Metamod-R
RUN sed -i 's/gamedll_linux ".*"/gamedll_linux "addons\/metamod\/metamod_i386.so"/' ${MOD}/liblist.gam

0 comments on commit 2d7492f

Please sign in to comment.