-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathreset-node
More file actions
executable file
·247 lines (201 loc) · 5.87 KB
/
reset-node
File metadata and controls
executable file
·247 lines (201 loc) · 5.87 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#!/bin/bash
# ============================================================================
# Reset Node - Clean reinstall of Demos Network node
# ============================================================================
#
# This script performs a clean reinstall while preserving:
# - .demos_identity (your node identity)
# - demos_peerlist.json (your peer list)
#
# ============================================================================
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m'
# Configuration
REPO_URL="https://github.com/kynesyslabs/node"
IDENTITY_FILE=".demos_identity"
PEERLIST_FILE="demos_peerlist.json"
# ============================================================================
# Helper Functions
# ============================================================================
print_step() {
echo -e "${CYAN}▶${NC} $1"
}
print_success() {
echo -e "${GREEN}✓${NC} $1"
}
print_error() {
echo -e "${RED}✗${NC} $1"
}
print_warning() {
echo -e "${YELLOW}⚠${NC} $1"
}
show_help() {
cat <<EOF
🔄 Reset Node - Clean reinstall of Demos Network node
USAGE:
./reset-node [OPTIONS]
OPTIONS:
-y, --yes Skip confirmation prompt
-h, --help Show this help message
DESCRIPTION:
This script performs a complete clean reinstall of the node software
while preserving your identity and peer list files.
Files preserved:
- .demos_identity (your node identity - IMPORTANT!)
- demos_peerlist.json (your peer connections)
What happens:
1. Backs up identity and peerlist to parent directory
2. Removes the entire node directory
3. Clones fresh copy from GitHub
4. Restores identity and peerlist
5. Runs bun install
WARNING:
This will delete ALL local changes, logs, and data!
Make sure you have backed up anything important.
EOF
}
# ============================================================================
# Main Script
# ============================================================================
main() {
local skip_confirm=false
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
-y | --yes)
skip_confirm=true
shift
;;
-h | --help)
show_help
exit 0
;;
*)
echo "Unknown option: $1"
echo "Use --help for usage information"
exit 1
;;
esac
done
echo ""
echo -e "${BOLD}🔄 Reset Node - Demos Network${NC}"
echo ""
# Check we're in the right directory
if [[ ! -f "package.json" ]] || ! grep -q "demos" package.json 2>/dev/null; then
print_error "This doesn't look like the node directory"
echo " Please run this script from inside the 'node' directory"
exit 1
fi
# Get current directory name and parent
local node_dir=$(basename "$(pwd)")
local parent_dir=$(dirname "$(pwd)")
echo " Current directory: $(pwd)"
echo " Will clone to: ${parent_dir}/${node_dir}"
echo ""
# Check for files to preserve
local has_identity=false
local has_peerlist=false
if [[ -f "${IDENTITY_FILE}" ]]; then
has_identity=true
print_success "Found ${IDENTITY_FILE} (will be preserved)"
else
print_warning "No ${IDENTITY_FILE} found"
fi
if [[ -f "${PEERLIST_FILE}" ]]; then
has_peerlist=true
print_success "Found ${PEERLIST_FILE} (will be preserved)"
else
print_warning "No ${PEERLIST_FILE} found"
fi
echo ""
# Confirmation
if [[ "${skip_confirm}" = false ]]; then
echo -e "${YELLOW}${BOLD}⚠️ WARNING: This will delete ALL local changes, logs, and data!${NC}"
echo ""
read -p "Are you sure you want to continue? [y/N] " -n 1 -r
echo ""
if [[ ! ${REPLY} =~ ^[Yy]$ ]]; then
echo "Aborted."
exit 0
fi
fi
echo ""
# Step 1: Backup identity and peerlist
print_step "Backing up identity files..."
if [[ "${has_identity}" = true ]]; then
if cp "${IDENTITY_FILE}" "${parent_dir}/${IDENTITY_FILE}.backup"; then
print_success "Backed up ${IDENTITY_FILE}"
else
print_error "Failed to backup ${IDENTITY_FILE}"
exit 1
fi
fi
if [[ "${has_peerlist}" = true ]]; then
if cp "${PEERLIST_FILE}" "${parent_dir}/${PEERLIST_FILE}.backup"; then
print_success "Backed up ${PEERLIST_FILE}"
else
print_error "Failed to backup ${PEERLIST_FILE}"
exit 1
fi
fi
# Step 2: Move to parent and remove node directory
print_step "Removing old node directory..."
cd "${parent_dir}" || exit 1
if rm -rf "${node_dir}"; then
print_success "Removed ${node_dir}"
else
print_error "Failed to remove ${node_dir}"
exit 1
fi
# Step 3: Clone fresh copy
print_step "Cloning fresh copy from GitHub..."
if git clone "${REPO_URL}" "${node_dir}"; then
print_success "Cloned repository"
else
print_error "Failed to clone repository"
# Try to restore backups
print_warning "Attempting to restore backups..."
mkdir -p "${node_dir}"
[[ -f "${IDENTITY_FILE}.backup" ]] && mv "${IDENTITY_FILE}.backup" "${node_dir}/${IDENTITY_FILE}"
[[ -f "${PEERLIST_FILE}.backup" ]] && mv "${PEERLIST_FILE}.backup" "${node_dir}/${PEERLIST_FILE}"
exit 1
fi
# Step 4: Restore identity files
print_step "Restoring identity files..."
cd "${node_dir}" || exit 1
if [[ -f "${parent_dir}/${IDENTITY_FILE}.backup" ]]; then
if mv "${parent_dir}/${IDENTITY_FILE}.backup" "${IDENTITY_FILE}"; then
print_success "Restored ${IDENTITY_FILE}"
else
print_error "Failed to restore ${IDENTITY_FILE}"
fi
fi
if [[ -f "${parent_dir}/${PEERLIST_FILE}.backup" ]]; then
if mv "${parent_dir}/${PEERLIST_FILE}.backup" "${PEERLIST_FILE}"; then
print_success "Restored ${PEERLIST_FILE}"
else
print_error "Failed to restore ${PEERLIST_FILE}"
fi
fi
# Step 5: Install dependencies
print_step "Installing dependencies..."
if bun install; then
print_success "Dependencies installed"
else
print_error "Failed to install dependencies"
exit 1
fi
# Done
echo ""
echo -e "${GREEN}${BOLD}✓ Node reset complete!${NC}"
echo ""
echo " You can now start your node with: ./run"
echo ""
}
# Run main
main "$@"