🔧 修正脚本库更新脚本公网仓库地址
This commit is contained in:
@@ -1,8 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
REPO_URL="${REPO_URL:-http://127.0.0.1:3000/orion/filecodebox.git}"
|
REPO_URL="${REPO_URL:-https://git.orionc.me/orion/filecodebox.git}"
|
||||||
TOKEN_FILE="${TOKEN_FILE:-/root/.cache/gitea-filecodebox-token}"
|
|
||||||
PROD_REPO_DIR="${PROD_REPO_DIR:-/opt/src/filecodebox-production}"
|
PROD_REPO_DIR="${PROD_REPO_DIR:-/opt/src/filecodebox-production}"
|
||||||
PROD_DIR="${PROD_DIR:-/opt/1panel/apps/filecodebox/filecodebox}"
|
PROD_DIR="${PROD_DIR:-/opt/1panel/apps/filecodebox/filecodebox}"
|
||||||
BRANCH="${BRANCH:-master}"
|
BRANCH="${BRANCH:-master}"
|
||||||
@@ -17,19 +16,13 @@ command -v docker >/dev/null 2>&1 || fail '缺少 docker'
|
|||||||
command -v curl >/dev/null 2>&1 || fail '缺少 curl'
|
command -v curl >/dev/null 2>&1 || fail '缺少 curl'
|
||||||
[[ -d "$PROD_DIR" ]] || fail "生产目录不存在:$PROD_DIR"
|
[[ -d "$PROD_DIR" ]] || fail "生产目录不存在:$PROD_DIR"
|
||||||
|
|
||||||
AUTH_REPO_URL="$REPO_URL"
|
log "拉取公开仓库 $REPO_URL 的 $BRANCH 分支"
|
||||||
if [[ -f "$TOKEN_FILE" && "$REPO_URL" == http://127.0.0.1:3000/* ]]; then
|
|
||||||
TOKEN="$(tr -d '\n' < "$TOKEN_FILE")"
|
|
||||||
AUTH_REPO_URL="http://orion:${TOKEN}@127.0.0.1:3000/orion/filecodebox.git"
|
|
||||||
fi
|
|
||||||
|
|
||||||
log "拉取 $BRANCH 分支"
|
|
||||||
if [[ ! -d "$PROD_REPO_DIR/.git" ]]; then
|
if [[ ! -d "$PROD_REPO_DIR/.git" ]]; then
|
||||||
rm -rf "$PROD_REPO_DIR"
|
rm -rf "$PROD_REPO_DIR"
|
||||||
git clone "$AUTH_REPO_URL" "$PROD_REPO_DIR"
|
git clone "$REPO_URL" "$PROD_REPO_DIR"
|
||||||
fi
|
fi
|
||||||
cd "$PROD_REPO_DIR"
|
cd "$PROD_REPO_DIR"
|
||||||
git remote set-url origin "$AUTH_REPO_URL"
|
git remote set-url origin "$REPO_URL"
|
||||||
git fetch origin "$BRANCH"
|
git fetch origin "$BRANCH"
|
||||||
git checkout -B "$BRANCH" "origin/$BRANCH"
|
git checkout -B "$BRANCH" "origin/$BRANCH"
|
||||||
git reset --hard "origin/$BRANCH"
|
git reset --hard "origin/$BRANCH"
|
||||||
@@ -45,21 +38,21 @@ cp -a docker-compose.yml "backups/docker-compose.yml.before-update.$TS"
|
|||||||
log "同步 1Panel Compose 为本地 master 构建"
|
log "同步 1Panel Compose 为本地 master 构建"
|
||||||
python3 - <<PY
|
python3 - <<PY
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
p=Path('docker-compose.yml')
|
p = Path('docker-compose.yml')
|
||||||
s=p.read_text()
|
s = p.read_text()
|
||||||
lines=[]
|
lines = []
|
||||||
for line in s.splitlines():
|
for line in s.splitlines():
|
||||||
stripped=line.strip()
|
stripped = line.strip()
|
||||||
if stripped.startswith('image:'):
|
if stripped.startswith('image:'):
|
||||||
indent=line[:len(line)-len(line.lstrip())]
|
indent = line[:len(line) - len(line.lstrip())]
|
||||||
lines.append(indent+'image: $IMAGE')
|
lines.append(indent + 'image: $IMAGE')
|
||||||
lines.append(indent+'build:')
|
lines.append(indent + 'build:')
|
||||||
lines.append(indent+' context: $PROD_REPO_DIR')
|
lines.append(indent + ' context: $PROD_REPO_DIR')
|
||||||
elif stripped.startswith('build:') or stripped.startswith('context:'):
|
elif stripped.startswith('build:') or stripped.startswith('context:'):
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
lines.append(line)
|
lines.append(line)
|
||||||
p.write_text('\n'.join(lines)+'\n')
|
p.write_text('\n'.join(lines) + '\n')
|
||||||
PY
|
PY
|
||||||
|
|
||||||
log "构建并重建生产容器"
|
log "构建并重建生产容器"
|
||||||
@@ -86,11 +79,12 @@ log "同步 1Panel 安装实例记录"
|
|||||||
python3 - <<'PY'
|
python3 - <<'PY'
|
||||||
import sqlite3
|
import sqlite3
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
DB='/opt/1panel/db/agent.db'
|
DB = '/opt/1panel/db/agent.db'
|
||||||
compose=Path('/opt/1panel/apps/filecodebox/filecodebox/docker-compose.yml').read_text()
|
compose = Path('/opt/1panel/apps/filecodebox/filecodebox/docker-compose.yml').read_text()
|
||||||
conn=sqlite3.connect(DB)
|
conn = sqlite3.connect(DB)
|
||||||
conn.execute("update app_installs set docker_compose=?, status='Running', container_name='filecodebox', service_name='filecodebox', http_port=40157, updated_at=datetime('now','localtime') where name='filecodebox'", (compose,))
|
conn.execute("update app_installs set docker_compose=?, status='Running', container_name='filecodebox', service_name='filecodebox', http_port=40157, updated_at=datetime('now','localtime') where name='filecodebox'", (compose,))
|
||||||
conn.commit(); conn.close()
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
PY
|
PY
|
||||||
|
|
||||||
(systemctl restart 1panel-agent >/dev/null 2>&1 || true)
|
(systemctl restart 1panel-agent >/dev/null 2>&1 || true)
|
||||||
|
|||||||
Reference in New Issue
Block a user