mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-11-29 02:42:51 +00:00
Merge branch 'feature/bash-scripts-update' into develop
This commit is contained in:
commit
522a2f7349
6 changed files with 177 additions and 36 deletions
|
|
@ -6,4 +6,6 @@ Dockerfile
|
||||||
docker-compose.yml
|
docker-compose.yml
|
||||||
.tmp
|
.tmp
|
||||||
.idea
|
.idea
|
||||||
.vscode
|
.vscode
|
||||||
|
LICENSE
|
||||||
|
README.*
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# Start fail2ban
|
# Start fail2ban
|
||||||
[ $XUI_ENABLE_FAIL2BAN == "true" ] && fail2ban-client -x start
|
[ "$XUI_ENABLE_FAIL2BAN" = "true" ] && fail2ban-client -x start
|
||||||
|
|
||||||
# Run x-ui
|
# Run x-ui
|
||||||
exec /app/x-ui
|
exec /app/x-ui
|
||||||
|
|
|
||||||
40
Dockerfile
40
Dockerfile
|
|
@ -2,38 +2,56 @@
|
||||||
# Stage: Builder
|
# Stage: Builder
|
||||||
# ========================================================
|
# ========================================================
|
||||||
FROM golang:1.25-alpine AS builder
|
FROM golang:1.25-alpine AS builder
|
||||||
WORKDIR /app
|
|
||||||
ARG TARGETARCH
|
|
||||||
|
|
||||||
RUN apk --no-cache --update add \
|
WORKDIR /app
|
||||||
|
|
||||||
|
RUN apk add --no-cache \
|
||||||
build-base \
|
build-base \
|
||||||
gcc \
|
gcc
|
||||||
wget \
|
|
||||||
unzip
|
# docker CACHE
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
ENV CGO_ENABLED=1
|
ENV CGO_ENABLED=1
|
||||||
ENV CGO_CFLAGS="-D_LARGEFILE64_SOURCE"
|
ENV CGO_CFLAGS="-D_LARGEFILE64_SOURCE"
|
||||||
RUN go build -ldflags "-w -s" -o build/x-ui main.go
|
RUN go build -ldflags "-w -s" -o build/x-ui main.go
|
||||||
RUN ./DockerInit.sh "$TARGETARCH"
|
|
||||||
|
# ========================================================
|
||||||
|
# Stage: Xray downloader
|
||||||
|
# ========================================================
|
||||||
|
FROM alpine AS xray-downloader
|
||||||
|
|
||||||
|
ARG TARGETARCH
|
||||||
|
ARG XRAY_VERSION
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
RUN apk add --no-cache wget unzip && mkdir -p /app/bin
|
||||||
|
|
||||||
|
COPY xray-tools.sh .
|
||||||
|
RUN chmod +x /app/xray-tools.sh && \
|
||||||
|
./xray-tools.sh install_xray_core "$TARGETARCH" "/app/bin" "$XRAY_VERSION" && \
|
||||||
|
./xray-tools.sh update_geodata_in_docker "/app/bin"
|
||||||
|
|
||||||
# ========================================================
|
# ========================================================
|
||||||
# Stage: Final Image of 3x-ui
|
# Stage: Final Image of 3x-ui
|
||||||
# ========================================================
|
# ========================================================
|
||||||
FROM alpine
|
FROM alpine
|
||||||
ENV TZ=Asia/Tehran
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
RUN apk add --no-cache --update \
|
RUN apk add --no-cache \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
tzdata \
|
tzdata \
|
||||||
fail2ban \
|
fail2ban \
|
||||||
bash
|
bash
|
||||||
|
|
||||||
|
COPY DockerEntrypoint.sh /app/
|
||||||
COPY --from=builder /app/build/ /app/
|
COPY --from=builder /app/build/ /app/
|
||||||
COPY --from=builder /app/DockerEntrypoint.sh /app/
|
|
||||||
COPY --from=builder /app/x-ui.sh /usr/bin/x-ui
|
COPY --from=builder /app/x-ui.sh /usr/bin/x-ui
|
||||||
|
COPY --from=xray-downloader /app/bin /app/bin
|
||||||
|
|
||||||
|
|
||||||
# Configure fail2ban
|
# Configure fail2ban
|
||||||
|
|
@ -51,5 +69,5 @@ RUN chmod +x \
|
||||||
ENV XUI_ENABLE_FAIL2BAN="true"
|
ENV XUI_ENABLE_FAIL2BAN="true"
|
||||||
EXPOSE 2053
|
EXPOSE 2053
|
||||||
VOLUME [ "/etc/x-ui" ]
|
VOLUME [ "/etc/x-ui" ]
|
||||||
CMD [ "./x-ui" ]
|
|
||||||
ENTRYPOINT [ "/app/DockerEntrypoint.sh" ]
|
ENTRYPOINT [ "/app/DockerEntrypoint.sh" ]
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,17 @@ services:
|
||||||
3xui:
|
3xui:
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: ./Dockerfile
|
args:
|
||||||
|
XRAY_VERSION: "v25.10.15"
|
||||||
|
GEOUPDATE_CRON_SCHEDULE: "0 */6 * * *"
|
||||||
container_name: 3xui_app
|
container_name: 3xui_app
|
||||||
# hostname: yourhostname <- optional
|
|
||||||
volumes:
|
volumes:
|
||||||
- $PWD/db/:/etc/x-ui/
|
- $PWD/db/:/etc/x-ui/
|
||||||
- $PWD/cert/:/root/cert/
|
- $PWD/cert/:/root/cert/
|
||||||
environment:
|
environment:
|
||||||
|
TZ: "Asia/Tehran"
|
||||||
XRAY_VMESS_AEAD_FORCED: "false"
|
XRAY_VMESS_AEAD_FORCED: "false"
|
||||||
XUI_ENABLE_FAIL2BAN: "true"
|
XUI_ENABLE_FAIL2BAN: "true"
|
||||||
tty: true
|
tty: true
|
||||||
network_mode: host
|
network_mode: host
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
42
x-ui.sh
42
x-ui.sh
|
|
@ -6,6 +6,8 @@ blue='\033[0;34m'
|
||||||
yellow='\033[0;33m'
|
yellow='\033[0;33m'
|
||||||
plain='\033[0m'
|
plain='\033[0m'
|
||||||
|
|
||||||
|
source xray-tools.sh
|
||||||
|
|
||||||
#Add some basic function here
|
#Add some basic function here
|
||||||
function LOGD() {
|
function LOGD() {
|
||||||
echo -e "${yellow}[DEG] $* ${plain}"
|
echo -e "${yellow}[DEG] $* ${plain}"
|
||||||
|
|
@ -863,26 +865,26 @@ delete_ports() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
update_all_geofiles() {
|
#update_all_geofiles() {
|
||||||
update_main_geofiles
|
# update_main_geofiles
|
||||||
update_ir_geofiles
|
# update_ir_geofiles
|
||||||
update_ru_geofiles
|
# update_ru_geofiles
|
||||||
}
|
#}
|
||||||
|
#
|
||||||
update_main_geofiles() {
|
#update_main_geofiles() {
|
||||||
wget -O geoip.dat https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat
|
# wget -O geoip.dat https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat
|
||||||
wget -O geosite.dat https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat
|
# wget -O geosite.dat https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat
|
||||||
}
|
#}
|
||||||
|
#
|
||||||
update_ir_geofiles() {
|
#update_ir_geofiles() {
|
||||||
wget -O geoip_IR.dat https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geoip.dat
|
# wget -O geoip_IR.dat https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geoip.dat
|
||||||
wget -O geosite_IR.dat https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geosite.dat
|
# wget -O geosite_IR.dat https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geosite.dat
|
||||||
}
|
#}
|
||||||
|
#
|
||||||
update_ru_geofiles() {
|
#update_ru_geofiles() {
|
||||||
wget -O geoip_RU.dat https://github.com/runetfreedom/russia-v2ray-rules-dat/releases/latest/download/geoip.dat
|
# wget -O geoip_RU.dat https://github.com/runetfreedom/russia-v2ray-rules-dat/releases/latest/download/geoip.dat
|
||||||
wget -O geosite_RU.dat https://github.com/runetfreedom/russia-v2ray-rules-dat/releases/latest/download/geosite.dat
|
# wget -O geosite_RU.dat https://github.com/runetfreedom/russia-v2ray-rules-dat/releases/latest/download/geosite.dat
|
||||||
}
|
#}
|
||||||
|
|
||||||
update_geo() {
|
update_geo() {
|
||||||
echo -e "${green}\t1.${plain} Loyalsoldier (geoip.dat, geosite.dat)"
|
echo -e "${green}\t1.${plain} Loyalsoldier (geoip.dat, geosite.dat)"
|
||||||
|
|
|
||||||
117
xray-tools.sh
Normal file
117
xray-tools.sh
Normal file
|
|
@ -0,0 +1,117 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
update_all_geofiles() {
|
||||||
|
update_main_geofiles
|
||||||
|
update_ir_geofiles
|
||||||
|
update_ru_geofiles
|
||||||
|
}
|
||||||
|
|
||||||
|
update_main_geofiles() {
|
||||||
|
wget -O geoip.dat https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat
|
||||||
|
wget -O geosite.dat https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat
|
||||||
|
}
|
||||||
|
|
||||||
|
update_ir_geofiles() {
|
||||||
|
wget -O geoip_IR.dat https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geoip.dat
|
||||||
|
wget -O geosite_IR.dat https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geosite.dat
|
||||||
|
}
|
||||||
|
|
||||||
|
update_ru_geofiles() {
|
||||||
|
wget -O geoip_RU.dat https://github.com/runetfreedom/russia-v2ray-rules-dat/releases/latest/download/geoip.dat
|
||||||
|
wget -O geosite_RU.dat https://github.com/runetfreedom/russia-v2ray-rules-dat/releases/latest/download/geosite.dat
|
||||||
|
}
|
||||||
|
|
||||||
|
update_geodata_in_docker() {
|
||||||
|
WORKDIR="$1"
|
||||||
|
OLD_DIR=$(pwd)
|
||||||
|
trap 'cd "$OLD_DIR"' EXIT
|
||||||
|
|
||||||
|
echo "[$(date)] Running update_geodata"
|
||||||
|
|
||||||
|
if [ ! -d "$WORKDIR" ]; then
|
||||||
|
mkdir -p "$WORKDIR"
|
||||||
|
fi
|
||||||
|
cd "$WORKDIR"
|
||||||
|
|
||||||
|
update_all_geofiles
|
||||||
|
echo "[$(date)] All geo files have been updated successfully!"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
install_xray_core() {
|
||||||
|
TARGETARCH="$1"
|
||||||
|
WORKDIR="$2"
|
||||||
|
XRAY_VERSION="$3"
|
||||||
|
|
||||||
|
OLD_DIR=$(pwd)
|
||||||
|
trap 'cd "$OLD_DIR"' EXIT
|
||||||
|
|
||||||
|
echo "[$(date)] Running install_xray_core"
|
||||||
|
|
||||||
|
case $1 in
|
||||||
|
amd64)
|
||||||
|
ARCH="64"
|
||||||
|
FNAME="amd64"
|
||||||
|
;;
|
||||||
|
i386)
|
||||||
|
ARCH="32"
|
||||||
|
FNAME="i386"
|
||||||
|
;;
|
||||||
|
armv8 | arm64 | aarch64)
|
||||||
|
ARCH="arm64-v8a"
|
||||||
|
FNAME="arm64"
|
||||||
|
;;
|
||||||
|
armv7 | arm | arm32)
|
||||||
|
ARCH="arm32-v7a"
|
||||||
|
FNAME="arm32"
|
||||||
|
;;
|
||||||
|
armv6)
|
||||||
|
ARCH="arm32-v6"
|
||||||
|
FNAME="armv6"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
ARCH="64"
|
||||||
|
FNAME="amd64"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ ! -d "$WORKDIR" ]; then
|
||||||
|
mkdir -p "$WORKDIR"
|
||||||
|
fi
|
||||||
|
cd "$WORKDIR"
|
||||||
|
|
||||||
|
wget -q "https://github.com/XTLS/Xray-core/releases/download/${XRAY_VERSION}/Xray-linux-${ARCH}.zip"
|
||||||
|
unzip "Xray-linux-${ARCH}.zip" -d ./xray-unzip
|
||||||
|
cp ./xray-unzip/xray ./"xray-linux-${FNAME}"
|
||||||
|
rm -r xray-unzip
|
||||||
|
rm "Xray-linux-${ARCH}.zip"
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- dispatcher: вызываем функции по имени ТОЛЬКО если скрипт запущен как файл ---
|
||||||
|
# Предполагаем, что файл называется xray-updates.sh
|
||||||
|
if [ "${0##*/}" = "xray-tools.sh" ]; then
|
||||||
|
cmd="$1"
|
||||||
|
shift || true
|
||||||
|
|
||||||
|
case "$cmd" in
|
||||||
|
install_xray_core)
|
||||||
|
# args: TARGETARCH WORKDIR XRAY_VERSION
|
||||||
|
install_xray_core "$@"
|
||||||
|
;;
|
||||||
|
update_geodata_in_docker)
|
||||||
|
# args: WORKDIR
|
||||||
|
update_geodata_in_docker "$@"
|
||||||
|
;;
|
||||||
|
""|help|-h|--help)
|
||||||
|
echo "Usage:"
|
||||||
|
echo " $0 install_xray_core TARGETARCH WORKDIR XRAY_VERSION"
|
||||||
|
echo " $0 update_geodata_in_docker WORKDIR"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unknown command: $cmd" >&2
|
||||||
|
echo "Try: $0 help" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
Loading…
Reference in a new issue