This commit is contained in:
Wang Sen Di
2025-11-23 14:15:20 +08:00
parent dbd83b7705
commit 6ba67a8d85
22 changed files with 519 additions and 0 deletions

15
boot/auto.sh Normal file
View File

@@ -0,0 +1,15 @@
#!/usr/bin/env bash
__main() {
:
}
__main
__help() {
cat >/dev/null <<-'AEOF'
AEOF
}

22
boot/conflict.sh Normal file
View File

@@ -0,0 +1,22 @@
#!/usr/bin/env bash
# shellcheck disable=SC1091
# shellcheck disable=SC2046
if [[ -d "/host/proc/1/" ]]; then source /apps/gitrce/hook/singleton.sh "$0"; fi
__main() {
:
}
# __main
nsenter --mount=/host/proc/1/ns/mnt bash <<<"$(declare -f __main | sed "\$a __main")"
__help() {
cat >/dev/null <<-'EOF'
bash -c 'cd /apps/gitrce/ && git pull -f; bash /apps/gitrce/boot/conflict.sh'
EOF
}

17
boot/cron.sh Normal file
View File

@@ -0,0 +1,17 @@
#!/usr/bin/env bash
# shellcheck disable=SC1091
# shellcheck disable=SC2009
# Admin https://www.yuque.com/wangsendi
__main() {
: # TODO
}
__main
__help() {
cat >/dev/null <<-'AEOF'
AEOF
}

8
boot/env.sh Normal file
View File

@@ -0,0 +1,8 @@
#!/usr/bin/env bash
# shellcheck disable=SC2034
# 在每一次间隔时间后读取的变量, 作用容易入口文件
# 用于在容器运行的状态下, 远程修改 git 拉取间隔时间
# 注意,最小值不能大于最大值, 否则客户端 Git 死循环
INTERVAL_MIN=200 # 间隔最小值
INTERVAL_MAX=300 # 间隔最大值

84
boot/install.sh Normal file
View File

@@ -0,0 +1,84 @@
#!/usr/bin/env bash
# shellcheck disable=SC2317,SC2086
# Admin https://www.yuque.com/wangsendi
__main() {
{
# 判断是否有 docker 和 docker-compose
if ! command -v docker >/dev/null 2>&1; then
echo "docker not installed"
return 1
fi
if [[ "$(docker compose version 2>/dev/null | grep version -c)" != "1" ]]; then
echo "docker compose not installed"
return 1
fi
}
{
# 镜像准备
_image1="1181.s.kuaicdn.cn:11818/ghcr.io/wangsendi/gitrce:bbiz-t2507281"
_image2="$(echo "$_image1" | awk -F '/' '{print $NF}')"
if [[ "$(docker images "$_image2" | wc -l)" != "2" ]]; then
docker pull $_image1 && docker tag "$_image1" "$_image2"
fi
}
{
_gre_remote_repo="https://codeberg.org/umi-edge/250924-s-speedtest.git"
_container_name="250924-s-speedtest"
_apps_data="/data/umi/gitrce/$_container_name/master"
_compose_file="$_apps_data/boot/docker-compose.yaml"
mkdir -p ${_compose_file%/*}
cat >$_compose_file <<EOF
services:
master:
container_name: $_container_name
image: $_image2
restart: always
network_mode: host
privileged: true
security_opt:
- apparmor:unconfined
environment:
- GIT_REMOTE_REPO=$_gre_remote_repo
- APPS_DATA=$_apps_data
- CONTAINER_NAME=$_container_name
volumes:
- /dev:/host/dev:ro
- /sys:/host/sys:ro
- /proc:/host/proc:ro
- /run:/host/run:rw
- /etc:/host/etc:rw
- /data:/data:rw,rshared
- /disk:/disk:rw,rshared
- "$_apps_data/:/apps/data"
EOF
}
{
# run
docker ps -f name="[0-9a-z]{12}_$_container_name" -aq | xargs -r docker rm -f # 删除变种容器
_cmd="docker compose -p $_container_name -f $_compose_file up -d --remove-orphans"
if ! eval "$_cmd"; then
docker ps -f name=$_container_name -aq | xargs -r -I{} echo 'ps -ef | grep -v $$ | grep {}' | sh | awk '{print $2}' | xargs -r -I{} kill -9 {}
docker rm -f $_container_name
eval "$_cmd"
fi
}
}
__main
__help() {
cat >/dev/null <<-'AEOF'
bash <(curl -fsSL https://codeberg.org/umi-edge/250924-s-speedtest/raw/branch/main/boot/install.sh)
AEOF
}

20
boot/start.sh Executable file
View File

@@ -0,0 +1,20 @@
#!/usr/bin/env bash
__main() {
:
ln -sf /host/run/docker.sock /var/run/docker.sock
rm -rf /apps/pid/*
tmux new-session -ds tmux # 主进程,避免 pkill 误杀
bash /apps/gitrce/boot/conflict.sh >/dev/null 2>&1
bash /apps/gitrce/deploy/release/default/start.sh >/dev/null 2>&1
}
__main
_help() {
cat >/dev/null <<EOF
容器启动, 拉取代码成功后执行的路径
EOF
}

20
boot/uninstall.sh Normal file
View File

@@ -0,0 +1,20 @@
#!/usr/bin/env bash
# shellcheck disable=SC1091
if [[ "$CONTAINER_NAME" == "" ]]; then CONTAINER_NAME=$(grep devices </proc/self/cgroup | grep -Po '[0-9a-z]{64}' | cut -c1-12); fi
__main() {
:
env
docker rm -f "$CONTAINER_NAME"
}
__main
__help() {
cat >/dev/null <<-'AEOF'
AEOF
}

12
boot/update.sh Executable file
View File

@@ -0,0 +1,12 @@
#!/usr/bin/env bash
# 每次 git 更行后的操作
__main() {
# service rsyslog restart
# service cron restart
service cron reload
pkill -f '/default/update.sh sleep'
}
__main

15
boot/upgrade.sh Normal file
View File

@@ -0,0 +1,15 @@
#!/usr/bin/env bash
__main() {
:
}
__help() {
cat >/dev/null <<-'AEOF'
AEOF
}
__main