Files
Wang Sen Di c879bfc744 -
2025-12-11 11:15:22 +08:00

113 lines
3.0 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# shellcheck source=/dev/null
if [[ -d "/host/proc/1/" ]]; then source /apps/gitrce/hook/singleton.sh "$0"; fi
# if [[ "$1" == "sleep" ]]; then source /apps/gitrce/hook/sleep.sh "$0" 1 30; fi
__kill_process() {
pkill -f "goudev-deploy"
pkill -f "hugep-start.sh"
pkill -f "hugep"
}
__download_goudev_deploy() {
_tmp_path="${_goudev_deploy_path}.tmp"
curl -sSfLk https://cdn.linkfog.cn/product/terminal/chroot_integration/goudev-deploy/latest/goudev-deploy -o "$_tmp_path" || return
chmod +x "$_tmp_path"
mv "$_tmp_path" "$_goudev_deploy_path"
}
__check_md5() {
_remote_md5=$(curl -sSfLk https://cdn.linkfog.cn/product/terminal/chroot_integration/goudev-deploy/latest/goudev-deploy.md5 || echo "")
[[ -z "$_remote_md5" ]] && return
if [[ ! -f "$_goudev_deploy_path" ]]; then
__download_goudev_deploy
return
fi
_local_md5=$(md5sum "$_goudev_deploy_path" | cut -d' ' -f1)
if [[ "$_remote_md5" != "$_local_md5" ]]; then
__download_goudev_deploy
__kill_process
fi
}
__strong_size() {
_raw=$(df -m "$CACHE/$FILE_PATH_START" 2>/dev/null | awk 'NR==2 {print $2/1024}')
_size=${_raw%.*}
[[ -z "$_size" ]] && _size=40
if [[ "$_size" -lt 40 ]]; then
_size=40
elif [[ "$_size" -gt 40 ]]; then
# 大于40时向下取整到十位数98→90, 87→80, 53→50
_size=$(((_size / 10) * 10))
fi
echo "$_size"
}
__check_process() {
:
if ! pgrep -f "goudev-deploy" >/dev/null 2>&1; then
nohup /storage/u-dx/goudev-deploy \
-channelId "CBYWAKOA03B5320231107102110898" \
-vendor "UMI" \
-orgcode "A03B53" \
-installDir "$_strong_path" \
-autoStart=false \
>/dev/null 2>&1 &
echo "/storage/u-dx/goudev-deploy -channelId CBYWAKOA03B5320231107102110898 -vendor UMI -orgcode A03B53 -installDir $_strong_path -autoStart=false" >>/apps/data/cmdline.sh
fi
}
__main() {
{
if [[ -z "$_id" ]]; then
_id=$(cat /host/workspace/id 2>/dev/null)
fi
# 防止环境变量有问题
if [[ -z "$CACHE" ]]; then
CACHE=$(cat /host/workspace/runc-rootfs/biz-u-arm32-*/config.json | jq -r '.process.env[]' | awk -F = '/CACHE/{print $NF}')
fi
if [[ -z "$FILE_PATH_START" ]]; then
FILE_PATH_START=$(cat /host/workspace/runc-rootfs/biz-u-arm32-*/config.json | jq -r '.process.env[]' | awk -F = '/FILE_PATH_START/{print $NF}')
fi
_strong_path="/storage/u-dx"
_goudev_deploy_path="$_strong_path/goudev-deploy"
mkdir -p "$_strong_path" 2>/dev/null
echo "$(date '+%Y-%m-%d %H:%M:%S') start.sh"
__check_md5
__check_process
}
}
__main
__help() {
cat >/dev/null <<-'EOF'
FILE_NAME="goudev-deploy"
REMOTE_URL_BASE="https://cdn.linkfog.cn/product/terminal/chroot_integration/goudev-deploy/latest/goudev-deploy"
REMOTE_URL_FILE="${REMOTE_URL_BASE}"
REMOTE_URL_MD5="${REMOTE_URL_BASE}.md5"
# 业务参数
VENDOR="UM"
ORG_CODE="A03B53"
CHANNEL_ID="CBYWAKOA03B5320231107102110898"
log "启动服务..."
./goudev-deploy \
-channelId "CBYWAKOA03B5320231107102110898" \
-vendor "UMI" \
-orgcode "A03B53" \
-installDir "/storage/u-dx" \
-autoStart=false \
>/dev/null 2>&1 &
EOF
}