-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-farmtest2.sh
More file actions
executable file
·179 lines (157 loc) · 5.99 KB
/
Copy pathupdate-farmtest2.sh
File metadata and controls
executable file
·179 lines (157 loc) · 5.99 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/bin/bash
# =============================================================================
# UPDATE FARMTEST2 SCRIPT
# =============================================================================
#
# PURPOSE: This script updates the farmtest2 folder by copying files from
# lib-lp-staking-frontend to liberdus.github.io/farmtest2
#
# PREREQUISITES:
# 1. This script must be located in the liberdus.github.io directory
# 2. The lib-lp-staking-frontend repository must be in the same parent directory as liberdus.github.io
# example structure:
# /path/to/parent/
# ├── liberdus.github.io/ (this repo, contains this script)
# └── lib-lp-staking-frontend/ (source repo)
# 3. The script must have execute permissions: chmod +x update-farmtest2.sh
#
# USAGE:
# 1. Run the script from anywhere: ./update-farmtest2.sh
# (or: cd liberdus.github.io && ./update-farmtest2.sh)
#
# WHAT IT DOES:
# - Copies all files from lib-lp-staking-frontend/* to liberdus.github.io/farmtest2/
# - Excludes README.md, legacy, and local test tooling files/folders
# - Replaces existing files in the farmtest2 folder
# - Preserves directory structure
# - Removes files that no longer exist in the source (syncs the folders)
# - Increments the patch version in farmtest2/version.html by 1
#
# =============================================================================
# Get the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# The script should be in liberdus.github.io, so that's our repo root
REPO_DIR="$SCRIPT_DIR"
# Source directory is in the sibling lib-lp-staking-frontend directory
SOURCE_DIR="$(dirname "$REPO_DIR")/lib-lp-staking-frontend"
# Target directory is the farmtest2 folder in this repo
TARGET_DIR="$REPO_DIR/farmtest2"
# Change to the repo directory
cd "$REPO_DIR" || exit 1
# Check if source directory exists
if [ ! -d "$SOURCE_DIR" ]; then
echo "Error: Source directory not found: $SOURCE_DIR"
echo "Please ensure lib-lp-staking-frontend exists in the same parent directory"
exit 1
fi
# Check if source directory is empty
if [ -z "$(ls -A "$SOURCE_DIR")" ]; then
echo "Error: Source directory is empty: $SOURCE_DIR"
exit 1
fi
# Check if target directory exists
if [ ! -d "$TARGET_DIR" ]; then
echo "Error: Target directory not found: $TARGET_DIR"
exit 1
fi
# Read current version from target before copying
VERSION_FILE="$TARGET_DIR/version.html"
current_version="1.0.0"
if [ -f "$VERSION_FILE" ]; then
current_version=$(cat "$VERSION_FILE" | tr -d '[:space:]')
fi
echo "Updating farmtest2 folder from lib-lp-staking-frontend..."
echo "Source: $SOURCE_DIR"
echo "Target: $TARGET_DIR"
echo "Current version: $current_version"
# Copy all files and directories from source to target
# Using rsync for better control with exclusions
if command -v rsync &> /dev/null; then
# Use rsync for efficient copying with exclusions
# Exclude README.md, legacy, and local test tooling files/folders
rsync -av --delete \
--exclude='README.md' \
--exclude='README' \
--exclude='legacy/' \
--exclude='legacy' \
--exclude='.git/' \
--exclude='.git' \
--exclude='.gitignore' \
--exclude='/.github/' \
--exclude='/tests/' \
--exclude='/package.json' \
--exclude='/package-lock.json' \
"$SOURCE_DIR/" "$TARGET_DIR/"
else
# Fallback to cp if rsync is not available
echo "Warning: rsync not found, using cp. This will overwrite all files."
read -p "Continue? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Aborted."
exit 1
fi
# Temporarily copy everything
temp_dir=$(mktemp -d)
cp -r "$SOURCE_DIR"/* "$temp_dir/" 2>/dev/null || true
# Remove excluded items
rm -f "$temp_dir/README.md" "$temp_dir/README" "$temp_dir/package.json" "$temp_dir/package-lock.json" 2>/dev/null || true
rm -rf "$temp_dir/legacy" "$temp_dir/tests" "$temp_dir/.github" 2>/dev/null || true
# Remove all files and directories in target except versioning and local test tooling
find "$TARGET_DIR" -mindepth 1 -maxdepth 1 \
! -name '.git' \
! -name 'version.html' \
! -name '.github' \
! -name 'tests' \
! -name 'package.json' \
! -name 'package-lock.json' \
-exec rm -rf {} +
# Copy all files from temp to target
cp -r "$temp_dir"/* "$TARGET_DIR/" 2>/dev/null || true
# Clean up temp directory
rm -rf "$temp_dir"
fi
# Remove excluded items if they were copied (safety check)
if [ -f "$TARGET_DIR/README.md" ]; then
rm -f "$TARGET_DIR/README.md"
echo "Removed README.md from target"
fi
if [ -d "$TARGET_DIR/legacy" ]; then
rm -rf "$TARGET_DIR/legacy"
echo "Removed legacy folder from target"
fi
# Increment the version (patch version)
if [[ $current_version =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
major="${BASH_REMATCH[1]}"
minor="${BASH_REMATCH[2]}"
patch="${BASH_REMATCH[3]}"
new_patch=$((patch + 1))
new_version="${major}.${minor}.${new_patch}"
else
# Fallback if version format is not found - try to increment as number
if [[ $current_version =~ ^([0-9]+)\.([0-9]+)$ ]]; then
major="${BASH_REMATCH[1]}"
minor="${BASH_REMATCH[2]}"
new_minor=$((minor + 1))
new_version="${major}.${new_minor}"
else
# Default fallback
echo "Warning: Could not parse version format, using default increment"
new_version="1.0.1"
fi
fi
# Write the new version to version.html
echo "$new_version" > "$VERSION_FILE"
# Verify the copy operation
if [ $? -eq 0 ]; then
echo "Farmtest2 update completed successfully!"
echo "Files copied from: $SOURCE_DIR"
echo "Files copied to: $TARGET_DIR"
echo "Version updated from $current_version to $new_version"
# Show some statistics
file_count=$(find "$TARGET_DIR" -type f | wc -l)
echo "Total files in farmtest2 folder: $file_count"
else
echo "Error: Copy operation failed"
exit 1
fi