Compare commits

..

No commits in common. "b8dc7b2c714e51f847070127a83ad1e21ab44870" and "e9757350f340e677127aeff1093fc2dd55c63c61" have entirely different histories.

3 changed files with 23 additions and 21 deletions

View file

@ -1,22 +1,19 @@
#!/bin/sh #!/bin/sh
set -eu
: "${MAX_GEODATA_DIR_WAIT:=30}"
: "${WAIT_INTERVAL:=10}"
: "${GEODATA_DIR:?GEODATA_DIR is required}"
FINISH_FILE="$GEODATA_DIR/cron-job-finished.txt" FINISH_FILE="$GEODATA_DIR/cron-job-finished.txt"
ELAPSED=0
while [ ! -f "$FINISH_FILE" ] && [ "$ELAPSED" -lt "$MAX_GEODATA_DIR_WAIT" ]; do MAX_WAIT=300 # 5 minutes
echo "Waiting for geodata initialization... ($ELAPSED/$MAX_GEODATA_DIR_WAIT seconds)" ELAPSED=0
sleep $WAIT_INTERVAL INTERVAL=10
ELAPSED=$((ELAPSED + WAIT_INTERVAL))
while [ ! -f "$FINISH_FILE" ] && [ $ELAPSED -lt $MAX_WAIT ]; do
echo "Still waiting for geodata initialization... ($ELAPSED/$MAX_WAIT seconds)"
sleep $INTERVAL
ELAPSED=$((ELAPSED + INTERVAL))
done done
if [ ! -f "$FINISH_FILE" ]; then if [ ! -f "$FINISH_FILE" ]; then
echo "ERROR: Geodata initialization timed out after $MAX_GEODATA_DIR_WAIT seconds" echo "ERROR: Geodata initialization timed out after $MAX_WAIT seconds"
echo "Container startup aborted." echo "Container startup aborted."
exit 1 exit 1
fi fi

View file

@ -17,6 +17,7 @@ RUN apk add --no-cache \
COPY xray-tools.sh entrypoint.sh cron-job-script.sh ./ COPY xray-tools.sh entrypoint.sh cron-job-script.sh ./
#RUN mkdir -p "$XRAY_BUILD_DIR"
RUN chmod +x /app/xray-tools.sh /app/entrypoint.sh /app/cron-job-script.sh \ RUN chmod +x /app/xray-tools.sh /app/entrypoint.sh /app/cron-job-script.sh \
&& mkdir -p "$XRAY_BUILD_DIR" \ && mkdir -p "$XRAY_BUILD_DIR" \
&& ./xray-tools.sh install_xray_core "$TARGETARCH" "$XRAY_BUILD_DIR" "$XRAY_VERSION" \ && ./xray-tools.sh install_xray_core "$TARGETARCH" "$XRAY_BUILD_DIR" "$XRAY_VERSION" \

View file

@ -126,20 +126,24 @@ install_xray_core() {
# Validate the downloaded zip file # Validate the downloaded zip file
if [ ! -f "Xray-linux-${ARCH}.zip" ] || [ ! -s "Xray-linux-${ARCH}.zip" ]; then if [ ! -f "Xray-linux-${ARCH}.zip" ] || [ ! -s "Xray-linux-${ARCH}.zip" ]; then
echo "[ERR] Failed to download Xray-core zip or file is empty" echo "[ERR] Failed to download Xray-core zip or file is empty"
exit 1 cd "$OLD_DIR"
return 1
fi fi
unzip -q "Xray-linux-${ARCH}.zip" -d ./xray-unzip unzip -q "Xray-linux-${ARCH}.zip" -d ./xray-unzip
# Validate the extracted xray binary # Validate the extracted xray binary
if [ -f "./xray-unzip/xray" ]; then if [ ! -f "./xray-unzip/xray" ] || [ ! -s "./xray-unzip/xray" ]; then
cp ./xray-unzip/xray ./"xray-linux-${FNAME}" echo "[ERR] Failed to extract xray binary"
rm -r xray-unzip rm -rf ./xray-unzip
rm "Xray-linux-${ARCH}.zip" rm -f "Xray-linux-${ARCH}.zip"
else cd "$OLD_DIR"
echo "[ERR] Failed to extract xray binary" return 1
exit 1
fi fi
cp ./xray-unzip/xray ./"xray-linux-${FNAME}"
rm -r xray-unzip
rm "Xray-linux-${ARCH}.zip"
} }
if [ "${0##*/}" = "xray-tools.sh" ]; then if [ "${0##*/}" = "xray-tools.sh" ]; then
@ -162,7 +166,7 @@ if [ "${0##*/}" = "xray-tools.sh" ]; then
echo "Usage:" echo "Usage:"
echo " $0 install_xray_core TARGETARCH XRAYDIR XRAY_VERSION" echo " $0 install_xray_core TARGETARCH XRAYDIR XRAY_VERSION"
echo " $0 update_geodata_in_docker XRAYDIR" echo " $0 update_geodata_in_docker XRAYDIR"
exit 0 exit 1
;; ;;
*) *)
echo "Unknown command: $cmd" >&2 echo "Unknown command: $cmd" >&2