Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 31fcc4a8a7 | |||
| 2ff60280ef | |||
| 9118bbdd64 | |||
| cdb74393aa | |||
| b6d9901f05 | |||
| 619cc9e1ac |
@@ -1,41 +0,0 @@
|
||||
# Push main to a mirror remote with host-specific doc URLs, without leaving URL churn on main.
|
||||
# Usage: .\scripts\Push-Mirror.ps1 github|kalinamall|papatramp
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateSet('github', 'kalinamall', 'papatramp')]
|
||||
[string]$Target
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$Root = Split-Path -Parent $PSScriptRoot
|
||||
Set-Location $Root
|
||||
|
||||
$remote = switch ($Target) {
|
||||
'github' { 'github' }
|
||||
'kalinamall' { 'kalinamall' }
|
||||
'papatramp' { 'papatramp' }
|
||||
}
|
||||
|
||||
git remote get-url $remote 2>$null | Out-Null
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "remote not configured: $remote"
|
||||
}
|
||||
|
||||
if ((git status --porcelain)) {
|
||||
throw 'working tree not clean; commit or stash first'
|
||||
}
|
||||
|
||||
$before = (git rev-parse HEAD).Trim()
|
||||
& "$PSScriptRoot\Rewrite-GitHostUrls.ps1" -Target $Target
|
||||
|
||||
if (-not (git status --porcelain)) {
|
||||
Write-Output "no URL changes for $Target; pushing as-is"
|
||||
git push $remote main
|
||||
exit 0
|
||||
}
|
||||
|
||||
git add -A
|
||||
git commit -m "chore(docs): sync repository URLs for ${Target} mirror"
|
||||
git push $remote main
|
||||
git reset --hard $before
|
||||
Write-Output "pushed $remote with ${Target} URLs; local main reset to $before"
|
||||
@@ -1,57 +0,0 @@
|
||||
# Rewrite cross-repo URLs in tracked docs/config for the target Git host.
|
||||
# Usage: .\scripts\Rewrite-GitHostUrls.ps1 github|kalinamall|papatramp
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateSet('github', 'kalinamall', 'papatramp')]
|
||||
[string]$Target
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$Root = Split-Path -Parent $PSScriptRoot
|
||||
Set-Location $Root
|
||||
|
||||
switch ($Target) {
|
||||
'github' {
|
||||
$Base = 'https://github.com/PTah'
|
||||
$BlobSuffix = '/blob/main'
|
||||
}
|
||||
'kalinamall' {
|
||||
$Base = 'https://git.kalinamall.ru/PapaTramp'
|
||||
$BlobSuffix = '/src/branch/main'
|
||||
}
|
||||
'papatramp' {
|
||||
$Base = 'https://git.papatramp.ru/PTah'
|
||||
$BlobSuffix = '/src/branch/main'
|
||||
}
|
||||
}
|
||||
|
||||
$BaseHost = $Base -replace '^https://', ''
|
||||
|
||||
$patterns = @(
|
||||
@{ From = 'https://git.kalinamall.ru/PapaTramp/([^)/''"\s]+)/blob/main/'; To = "$Base/`$1$BlobSuffix/" }
|
||||
@{ From = 'https://git.kalinamall.ru/PapaTramp/([^)/''"\s]+)/src/branch/main/'; To = "$Base/`$1$BlobSuffix/" }
|
||||
@{ From = 'https://git.kalinamall.ru/PapaTramp/([^)/''"\s]+)/src/branch/main/'; To = "$Base/`$1$BlobSuffix/" }
|
||||
@{ From = 'https://git.kalinamall.ru/PapaTramp/'; To = "$Base/" }
|
||||
@{ From = 'https://git.kalinamall.ru/PapaTramp/'; To = "$Base/" }
|
||||
@{ From = 'https://git.kalinamall.ru/PapaTramp/'; To = "$Base/" }
|
||||
@{ From = 'git.kalinamall.ru/PapaTramp/'; To = "$BaseHost/" }
|
||||
@{ From = 'git.kalinamall.ru/PapaTramp/'; To = "$BaseHost/" }
|
||||
@{ From = 'git.kalinamall.ru/PapaTramp/'; To = "$BaseHost/" }
|
||||
)
|
||||
|
||||
$extensions = @('*.md', '*.json', '*.service', '*.example', '*.sh', '*.ps1', '*.yml', '*.yaml')
|
||||
$files = git ls-files $extensions 2>$null | Where-Object { $_ -and (Test-Path $_) }
|
||||
|
||||
foreach ($file in $files) {
|
||||
$content = [System.IO.File]::ReadAllText((Join-Path $Root $file))
|
||||
$updated = $content
|
||||
foreach ($p in $patterns) {
|
||||
$updated = [regex]::Replace($updated, $p.From, $p.To)
|
||||
}
|
||||
if ($updated -ne $content) {
|
||||
[System.IO.File]::WriteAllText((Join-Path $Root $file), $updated, [System.Text.UTF8Encoding]::new($false))
|
||||
Write-Output "updated: $file"
|
||||
}
|
||||
}
|
||||
|
||||
Write-Output "Rewrite-GitHostUrls: target=$Target base=$Base"
|
||||
@@ -1,43 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Push main to a mirror remote with host-specific doc URLs, without leaving URL churn on main.
|
||||
# Usage: push-mirror.sh github|kalinamall|papatramp
|
||||
set -euo pipefail
|
||||
|
||||
TARGET="${1:?usage: push-mirror.sh github|kalinamall|papatramp}"
|
||||
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
cd "$ROOT"
|
||||
|
||||
case "$TARGET" in
|
||||
github) REMOTE=github ;;
|
||||
kalinamall) REMOTE=kalinamall ;;
|
||||
papatramp) REMOTE=papatramp ;;
|
||||
*)
|
||||
echo "unknown target: $TARGET" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
if ! git remote get-url "$REMOTE" >/dev/null 2>&1; then
|
||||
echo "remote not configured: $REMOTE" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! git diff --quiet || ! git diff --cached --quiet; then
|
||||
echo "working tree not clean; commit or stash first" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BEFORE="$(git rev-parse HEAD)"
|
||||
bash "$ROOT/scripts/rewrite-git-host-urls.sh" "$TARGET"
|
||||
|
||||
if git diff --quiet; then
|
||||
echo "no URL changes for $TARGET; pushing as-is"
|
||||
git push "$REMOTE" main
|
||||
exit 0
|
||||
fi
|
||||
|
||||
git add -A
|
||||
git commit -m "chore(docs): sync repository URLs for ${TARGET} mirror"
|
||||
git push "$REMOTE" main
|
||||
git reset --hard "$BEFORE"
|
||||
echo "pushed $REMOTE with ${TARGET} URLs; local main reset to $BEFORE"
|
||||
@@ -1,67 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Rewrite cross-repo URLs in tracked docs/config for the target Git host.
|
||||
# Usage: rewrite-git-host-urls.sh github|kalinamall|papatramp
|
||||
set -euo pipefail
|
||||
|
||||
TARGET="${1:?usage: rewrite-git-host-urls.sh github|kalinamall|papatramp}"
|
||||
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
cd "$ROOT"
|
||||
|
||||
case "$TARGET" in
|
||||
github)
|
||||
BASE='https://github.com/PTah'
|
||||
BLOB_SUFFIX='/blob/main'
|
||||
;;
|
||||
kalinamall)
|
||||
BASE='https://git.kalinamall.ru/PapaTramp'
|
||||
BLOB_SUFFIX='/src/branch/main'
|
||||
;;
|
||||
papatramp)
|
||||
BASE='https://git.papatramp.ru/PTah'
|
||||
BLOB_SUFFIX='/src/branch/main'
|
||||
;;
|
||||
*)
|
||||
echo "unknown target: $TARGET" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Order matters: longer patterns first.
|
||||
PATTERNS=(
|
||||
's|https://git.kalinamall.ru/PapaTramp/\([^)/"'"'"' ]*\)/blob/main/|'"${BASE}"'/\1'"${BLOB_SUFFIX}"'/|g'
|
||||
's|https://git.kalinamall.ru/PapaTramp/\([^)/"'"'"' ]*\)/src/branch/main/|'"${BASE}"'/\1'"${BLOB_SUFFIX}"'/|g'
|
||||
's|https://git.kalinamall.ru/PapaTramp/\([^)/"'"'"' ]*\)/src/branch/main/|'"${BASE}"'/\1'"${BLOB_SUFFIX}"'/|g'
|
||||
's|https://git.kalinamall.ru/PapaTramp/|'"${BASE}"'/|g'
|
||||
's|https://git.kalinamall.ru/PapaTramp/|'"${BASE}"'/|g'
|
||||
's|https://git.kalinamall.ru/PapaTramp/|'"${BASE}"'/|g'
|
||||
's|git.kalinamall.ru/PapaTramp/|'"${BASE#https://}"'/|g'
|
||||
's|git.kalinamall.ru/PapaTramp/|'"${BASE#https://}"'/|g'
|
||||
's|git.kalinamall.ru/PapaTramp/|'"${BASE#https://}"'/|g'
|
||||
)
|
||||
|
||||
FILES=()
|
||||
while IFS= read -r -d '' f; do
|
||||
FILES+=("$f")
|
||||
done < <(git ls-files '*.md' '*.json' '*.service' '*.example' '*.sh' '*.ps1' '*.yml' '*.yaml' 2>/dev/null | tr '\n' '\0')
|
||||
|
||||
if [ "${#FILES[@]}" -eq 0 ]; then
|
||||
echo "no files to rewrite" >&2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
for f in "${FILES[@]}"; do
|
||||
[ -f "$f" ] || continue
|
||||
tmp="$(mktemp)"
|
||||
cp "$f" "$tmp"
|
||||
for pat in "${PATTERNS[@]}"; do
|
||||
sed -i "$pat" "$tmp" 2>/dev/null || sed -i '' "$pat" "$tmp"
|
||||
done
|
||||
if ! cmp -s "$f" "$tmp"; then
|
||||
mv "$tmp" "$f"
|
||||
echo "updated: $f"
|
||||
else
|
||||
rm -f "$tmp"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "rewrite-git-host-urls: target=$TARGET base=$BASE"
|
||||
+1
-1
@@ -7,7 +7,7 @@ IFS=$'\n\t'
|
||||
# ============================================
|
||||
|
||||
CONFIG_FILE="/etc/ssh-monitor.conf"
|
||||
SSH_MONITOR_VERSION="2.1.0-SAC"
|
||||
SSH_MONITOR_VERSION="2.1.1-SAC"
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
if [ -f "$SCRIPT_DIR/sac-client.sh" ]; then
|
||||
|
||||
+14
-23
@@ -3,7 +3,8 @@
|
||||
# === Конфигурация скрипта ===
|
||||
UPDATE_DIR="/opt/scripts/update"
|
||||
SCRIPT_NAME="ssh-monitor"
|
||||
REPO_URL="https://git.kalinamall.ru/PapaTramp/ssh-monitor.git"
|
||||
REPO_URL="${REPO_URL:-https://git.kalinamall.ru/PapaTramp/ssh-monitor.git}"
|
||||
GIT_BRANCH="${GIT_BRANCH:-main}"
|
||||
LOCAL_SCRIPT_PATH="/usr/local/bin/ssh-monitor"
|
||||
LOG_FILE="/var/log/update_script.log"
|
||||
|
||||
@@ -34,7 +35,7 @@ WATCHDOG_SERVICE_PATH="/etc/systemd/system/ssh-monitor-watchdog.service"
|
||||
WATCHDOG_TIMER_PATH="/etc/systemd/system/ssh-monitor-watchdog.timer"
|
||||
|
||||
# === Список переменных, объявленных в скрипте (для логирования при DEBUG=1) ===
|
||||
SCRIPT_VARS=("UPDATE_DIR" "SCRIPT_NAME" "REPO_URL" "LOCAL_SCRIPT_PATH" "LOG_FILE" "DEBUG" "REMOTE_SCRIPT_PATH" "LOCAL_CHECKSUM" "REMOTE_CHECKSUM")
|
||||
SCRIPT_VARS=("UPDATE_DIR" "SCRIPT_NAME" "REPO_URL" "GIT_BRANCH" "LOCAL_SCRIPT_PATH" "LOG_FILE" "DEBUG" "REMOTE_SCRIPT_PATH" "LOCAL_CHECKSUM" "REMOTE_CHECKSUM")
|
||||
|
||||
# === Функции ===
|
||||
|
||||
@@ -339,27 +340,17 @@ get_git_short_rev() {
|
||||
git -C "$repo_dir" rev-parse --short HEAD 2>/dev/null || printf 'unknown'
|
||||
}
|
||||
|
||||
# Remote с URL закрытого зеркала (не GitHub), если настроен.
|
||||
# Remote для fetch/pull: всегда kalinamall с URL из REPO_URL (SAC передаёт REPO_URL при SSH-обновлении).
|
||||
resolve_git_remote_name() {
|
||||
local repo="$1" name url
|
||||
if git -C "$repo" remote get-url kalinamall &>/dev/null; then
|
||||
printf '%s' kalinamall
|
||||
return 0
|
||||
local repo="$1"
|
||||
local name=kalinamall
|
||||
if git -C "$repo" remote get-url "$name" &>/dev/null; then
|
||||
git -C "$repo" remote set-url "$name" "$REPO_URL" >> "$LOG_FILE" 2>&1
|
||||
else
|
||||
git -C "$repo" remote add "$name" "$REPO_URL" >> "$LOG_FILE" 2>&1 \
|
||||
|| git -C "$repo" remote set-url "$name" "$REPO_URL" >> "$LOG_FILE" 2>&1
|
||||
fi
|
||||
while read -r name; do
|
||||
[ -n "$name" ] || continue
|
||||
url=$(git -C "$repo" remote get-url "$name" 2>/dev/null || true)
|
||||
case "$url" in
|
||||
*git.kalinamall.ru*) printf '%s' "$name"; return 0 ;;
|
||||
esac
|
||||
done < <(git -C "$repo" remote 2>/dev/null)
|
||||
if git -C "$repo" remote get-url origin &>/dev/null; then
|
||||
printf '%s' origin
|
||||
return 0
|
||||
fi
|
||||
git -C "$repo" remote add kalinamall "$REPO_URL" >> "$LOG_FILE" 2>&1 \
|
||||
|| git -C "$repo" remote set-url kalinamall "$REPO_URL" >> "$LOG_FILE" 2>&1
|
||||
printf '%s' kalinamall
|
||||
printf '%s' "$name"
|
||||
}
|
||||
|
||||
# fetch + ff-only pull; при расхождении истории (force-push) — reset --hard.
|
||||
@@ -1068,7 +1059,7 @@ update_script() {
|
||||
|
||||
debug_step "Проверяем наличие репозитория и обновляем/клонируем"
|
||||
if [ -d "$SCRIPT_NAME" ]; then
|
||||
if sync_git_repository "$git_repo" main; then
|
||||
if sync_git_repository "$git_repo" "$GIT_BRANCH"; then
|
||||
pull_ok=1
|
||||
else
|
||||
pull_ok=0
|
||||
@@ -1077,7 +1068,7 @@ update_script() {
|
||||
else
|
||||
log_action "git: clone $REPO_URL → $UPDATE_DIR/$SCRIPT_NAME"
|
||||
debug_step "Выполняем git clone $REPO_URL $SCRIPT_NAME"
|
||||
if ! git clone "$REPO_URL" "$SCRIPT_NAME" >> "$LOG_FILE" 2>&1; then
|
||||
if ! git clone -b "$GIT_BRANCH" "$REPO_URL" "$SCRIPT_NAME" >> "$LOG_FILE" 2>&1; then
|
||||
SUMMARY_GIT="clone FAILED"
|
||||
SUMMARY_SCRIPT="ошибка"
|
||||
SUMMARY_SCRIPT_REASON="git clone failed"
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
2.1.0-SAC
|
||||
2.1.1-SAC
|
||||
|
||||
Reference in New Issue
Block a user