-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcvs-sync.sh
103 lines (82 loc) · 3.63 KB
/
cvs-sync.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env bash
# --- Configuration ---
CVS_WORKING_DIR="/path/to/your/cvs/working/copy" # *** MUST BE CONFIGURED ***
GITHUB_REPO="fermi-ad/acnetd"
CVS_COMMIT_MESSAGE="Sync from Git - Release (automated script)"
CVS_TAG_PREFIX="git-hash-"
# --- Script Logic ---
# Function to check if a command is available
check_command() {
if ! command -v "$1" >/dev/null 2>&1; then
echo "Error: Required command '$1' is not installed or not in PATH."
return 1 # Indicate failure
fi
return 0 # Indicate success
}
# --- Dependency Check ---
echo "Checking for required commands..."
REQUIRED_COMMANDS=("curl" "jq" "patch" "cvs")
for cmd in "${REQUIRED_COMMANDS[@]}"; do
if ! check_command "$cmd"; then
echo "Please ensure all required commands are installed before running this script."
exit 1
fi
done
echo "All required commands are present."
# 1. Ensure we are in the CVS working directory
cd "$CVS_WORKING_DIR" || { echo "Error: Could not change directory to CVS working copy: $CVS_WORKING_DIR"; exit 1; }
# 2. Get the latest GitHub Release using curl and GitHub API (simplified - get latest release directly)
GITHUB_API_URL="https://api.github.com/repos/$GITHUB_REPO/releases"
# Get releases, sort by created_at (descending), get the first one (latest)
LATEST_RELEASE_JSON=$(curl -s "${GITHUB_API_URL}" | jq -s "sort_by(.created_at) | reverse | .[0]")
if [ -z "$LATEST_RELEASE_JSON" ] || [[ "$LATEST_RELEASE_JSON" == "null" ]]; then
echo "Error: No GitHub Releases found in repository: $GITHUB_REPO"
exit 1
fi
RELEASE_NAME=$(echo "$LATEST_RELEASE_JSON" | jq -r '.name')
RELEASE_TAG_NAME=$(echo "$LATEST_RELEASE_JSON" | jq -r '.tag_name') # Still get tag name for logging
PATCH_ASSET_URL=$(echo "$LATEST_RELEASE_JSON" | jq -r '.assets[0].browser_download_url') # Use browser_download_url for direct download
GIT_COMMIT_SHA=$(echo "$LATEST_RELEASE_JSON" | jq -r '.target_commitish') # <--- Get commit SHA directly from API response
if [ -z "$PATCH_ASSET_URL" ]; then
echo "Error: No patch file asset found in the latest GitHub Release: $RELEASE_NAME"
exit 1
fi
PATCH_FILE_NAME=$(basename "$PATCH_ASSET_URL")
PATCH_FILE_LOCAL="./$PATCH_FILE_NAME"
# 3. Download the patch file using curl (same as before)
echo "Downloading patch file: $PATCH_FILE_NAME from Release: $RELEASE_NAME ($RELEASE_TAG_NAME) - Commit: $GIT_COMMIT_SHA"
curl -L -o "$PATCH_FILE_LOCAL" "$PATCH_ASSET_URL" # -L to follow redirects, -o for output file
if [ ! -f "$PATCH_FILE_LOCAL" ]; then
echo "Error: Failed to download patch file: $PATCH_FILE_NAME"
exit 1
fi
# 4. Apply the patch (same as before)
echo "Applying patch: $PATCH_FILE_NAME"
if patch -p1 < "$PATCH_FILE_LOCAL"; then
echo "Patch applied successfully."
else
echo "Error: Patch application failed! Manual conflict resolution required."
echo "Please resolve conflicts in your CVS working copy, then re-run this script."
exit 1 # Exit script - manual intervention needed
fi
# 5. CVS Commit (same as before)
echo "Committing changes to CVS..."
cvs commit -m "$CVS_COMMIT_MESSAGE - Release: $RELEASE_NAME ($RELEASE_TAG_NAME) - Git Commit: $GIT_COMMIT_SHA" .
if [ $? -eq 0 ]; then
echo "CVS Commit successful."
else
echo "Error: CVS Commit failed!"
exit 1
fi
# 6. CVS Tagging (Now using the Commit SHA from API)
CVS_TAG_NAME="${CVS_TAG_PREFIX}${GIT_COMMIT_SHA}"
echo "Tagging CVS with tag: $CVS_TAG_NAME"
cvs tag "$CVS_TAG_NAME"
if [ $? -eq 0 ]; then
echo "CVS Tagging successful."
else
echo "Error: CVS Tagging failed!"
exit 1
fi
echo "CVS Sync Patch process completed for Release: $RELEASE_NAME ($RELEASE_TAG_NAME) - Git Commit: $GIT_COMMIT_SHA"
exit 0 # Exit script - explicit success