Skip to content

Commit b7b5e00

Browse files
committed
Merge branch 'dev'
2 parents c145e99 + b23d441 commit b7b5e00

File tree

3 files changed

+209
-23
lines changed

3 files changed

+209
-23
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,22 @@ node dexbot keys
3333
node dexbot bots
3434
```
3535

36+
### Updating DEXBot2
37+
38+
To update DEXBot2 to the latest version from the main branch:
39+
40+
```bash
41+
# Run the update script from project root
42+
bash scripts/update.sh
43+
```
44+
45+
The update script automatically:
46+
- Fetches and pulls the latest code from GitHub
47+
- Installs any new dependencies
48+
- Reloads PM2 processes if running
49+
- Ensures your `profiles/` directory is protected and unchanged
50+
- Logs all operations to `update.log`
51+
3652
## 🔧 Configuration
3753

3854
Define each bot in `profiles/bots.json`. A minimal structure looks like this:

scripts/update-dev.sh

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
#!/bin/bash
2+
# DEXBot2 Auto Update Script (Development Branch)
3+
#
4+
# This script automatically updates DEXBot2 from the GitHub repository dev branch
5+
# Usage: ./scripts/update-dev.sh or bash scripts/update-dev.sh
6+
#
7+
# Features:
8+
# - Checks for updates from dev branch
9+
# - Performs git pull
10+
# - Installs/updates dependencies
11+
# - Restarts PM2 if running
12+
# - Logs all operations
13+
14+
set -e
15+
16+
# Colors for output
17+
RED='\033[0;31m'
18+
GREEN='\033[0;32m'
19+
YELLOW='\033[1;33m'
20+
BLUE='\033[0;34m'
21+
NC='\033[0m' # No Color
22+
23+
# Configuration
24+
REPO_URL="https://github.com/froooze/DEXBot2.git"
25+
REPO_BRANCH="dev"
26+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
27+
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
28+
LOG_FILE="${PROJECT_ROOT}/update-dev.log"
29+
TIMESTAMP=$(date '+%Y-%m-%d_%H-%M-%S')
30+
31+
# Functions
32+
log_info() {
33+
echo -e "${BLUE}[INFO]${NC} $1" | tee -a "$LOG_FILE"
34+
}
35+
36+
log_success() {
37+
echo -e "${GREEN}[SUCCESS]${NC} $1" | tee -a "$LOG_FILE"
38+
}
39+
40+
log_warning() {
41+
echo -e "${YELLOW}[WARNING]${NC} $1" | tee -a "$LOG_FILE"
42+
}
43+
44+
log_error() {
45+
echo -e "${RED}[ERROR]${NC} $1" | tee -a "$LOG_FILE"
46+
}
47+
48+
# Check if we're in the project root
49+
if [ ! -f "$PROJECT_ROOT/dexbot.js" ]; then
50+
log_error "Script must be run from DEXBot2 root directory"
51+
exit 1
52+
fi
53+
54+
log_info "=========================================="
55+
log_info "DEXBot2 Update Script Started (Dev Branch)"
56+
log_info "=========================================="
57+
log_info "Project Root: $PROJECT_ROOT"
58+
log_info "Branch: $REPO_BRANCH"
59+
log_info "Timestamp: $TIMESTAMP"
60+
61+
# Note: profiles/ directory is in .gitignore and is not backed up during updates
62+
# Your configuration files are safe and will not be affected by the update
63+
64+
# Step 1: Check git status
65+
log_info "Step 1: Checking git status..."
66+
cd "$PROJECT_ROOT"
67+
if ! git rev-parse --git-dir > /dev/null 2>&1; then
68+
log_error "Not a git repository"
69+
exit 1
70+
fi
71+
72+
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
73+
log_info "Current branch: $CURRENT_BRANCH"
74+
75+
# Step 2: Protect profiles directory (ensure it won't be touched)
76+
log_info "Step 2: Protecting profiles directory..."
77+
if [ -d "$PROJECT_ROOT/profiles" ]; then
78+
# Ensure profiles is properly ignored by git
79+
if ! grep -q "profiles/" "$PROJECT_ROOT/.gitignore" 2>/dev/null; then
80+
log_warning "Warning: profiles/ not in .gitignore, adding it..."
81+
echo "profiles/" >> "$PROJECT_ROOT/.gitignore"
82+
fi
83+
log_success "Profiles directory is protected and will not be modified"
84+
else
85+
log_info "No profiles directory found (will be created on first run)"
86+
fi
87+
88+
# Step 3: Stash any local changes (except profiles which is in .gitignore)
89+
log_info "Step 3: Checking for local changes..."
90+
if ! git diff --quiet; then
91+
log_warning "Uncommitted changes detected, stashing..."
92+
git stash
93+
log_info "Changes stashed"
94+
fi
95+
96+
# Step 4: Fetch latest from GitHub
97+
log_info "Step 4: Fetching latest from GitHub..."
98+
if git fetch origin "$REPO_BRANCH"; then
99+
log_success "Fetched latest from origin"
100+
else
101+
log_error "Failed to fetch from GitHub"
102+
exit 1
103+
fi
104+
105+
# Step 5: Check if there are updates
106+
log_info "Step 5: Checking for available updates..."
107+
LOCAL=$(git rev-parse HEAD)
108+
REMOTE=$(git rev-parse "origin/$REPO_BRANCH")
109+
110+
if [ "$LOCAL" = "$REMOTE" ]; then
111+
log_success "Already up to date!"
112+
log_info "=========================================="
113+
exit 0
114+
fi
115+
116+
log_info "Updates available, pulling changes..."
117+
118+
# Step 6: Pull latest code (use --rebase to avoid merge prompts)
119+
if git pull --rebase origin "$REPO_BRANCH"; then
120+
log_success "Successfully pulled latest code"
121+
else
122+
log_error "Failed to pull latest code"
123+
exit 1
124+
fi
125+
126+
# Step 7: Install/update dependencies
127+
log_info "Step 7: Installing/updating dependencies..."
128+
if npm install --prefer-offline; then
129+
log_success "Dependencies installed successfully"
130+
else
131+
log_warning "npm install completed with warnings"
132+
fi
133+
134+
# Step 8: Check for PM2 running
135+
log_info "Step 8: Checking PM2 status..."
136+
if command -v pm2 &> /dev/null; then
137+
if pm2 list | grep -q "bbot"; then
138+
log_info "PM2 bots detected, reloading..."
139+
if pm2 reload profiles/ecosystem.config.js 2>/dev/null; then
140+
log_success "PM2 bots reloaded successfully"
141+
else
142+
log_warning "PM2 reload failed or no ecosystem config found"
143+
fi
144+
else
145+
log_info "No running PM2 bots found"
146+
fi
147+
else
148+
log_info "PM2 not installed, skipping restart"
149+
fi
150+
151+
# Step 9: Summary
152+
log_info "=========================================="
153+
log_success "Update completed successfully!"
154+
log_info "=========================================="
155+
log_info ""
156+
log_info "Summary:"
157+
log_info "- Code updated to latest from dev branch"
158+
log_info "- Dependencies installed"
159+
if command -v pm2 &> /dev/null && pm2 list | grep -q "bbot"; then
160+
log_info "- PM2 processes reloaded"
161+
fi
162+
log_info "- Your profiles/ directory is safe and unchanged"
163+
log_info ""
164+
log_info "Log file: $LOG_FILE"
165+
log_info ""
166+
log_info "Next steps:"
167+
log_info "- Review the changes with: git log --oneline -n 5"
168+
log_info "- Check status with: pm2 status"
169+
log_info "- View logs with: pm2 logs"
170+
log_info ""
171+
172+
exit 0

scripts/update.sh

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ REPO_URL="https://github.com/froooze/DEXBot2.git"
2626
REPO_BRANCH="main"
2727
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
2828
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
29-
BACKUP_DIR="${PROJECT_ROOT}/backups"
3029
LOG_FILE="${PROJECT_ROOT}/update.log"
3130
TIMESTAMP=$(date '+%Y-%m-%d_%H-%M-%S')
3231

@@ -60,19 +59,11 @@ log_info "Project Root: $PROJECT_ROOT"
6059
log_info "Branch: $REPO_BRANCH"
6160
log_info "Timestamp: $TIMESTAMP"
6261

63-
# Step 1: Backup profiles directory
64-
log_info "Step 1: Backing up profiles directory..."
65-
mkdir -p "$BACKUP_DIR"
66-
BACKUP_PATH="${BACKUP_DIR}/profiles_${TIMESTAMP}"
67-
if [ -d "$PROJECT_ROOT/profiles" ]; then
68-
cp -r "$PROJECT_ROOT/profiles" "$BACKUP_PATH"
69-
log_success "Profiles backed up to: $BACKUP_PATH"
70-
else
71-
log_warning "No profiles directory found, skipping backup"
72-
fi
62+
# Note: profiles/ directory is in .gitignore and is not backed up during updates
63+
# Your configuration files are safe and will not be affected by the update
7364

74-
# Step 2: Check git status
75-
log_info "Step 2: Checking git status..."
65+
# Step 1: Check git status
66+
log_info "Step 1: Checking git status..."
7667
cd "$PROJECT_ROOT"
7768
if ! git rev-parse --git-dir > /dev/null 2>&1; then
7869
log_error "Not a git repository"
@@ -82,7 +73,20 @@ fi
8273
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
8374
log_info "Current branch: $CURRENT_BRANCH"
8475

85-
# Step 3: Stash any local changes (except profiles)
76+
# Step 2: Protect profiles directory (ensure it won't be touched)
77+
log_info "Step 2: Protecting profiles directory..."
78+
if [ -d "$PROJECT_ROOT/profiles" ]; then
79+
# Ensure profiles is properly ignored by git
80+
if ! grep -q "profiles/" "$PROJECT_ROOT/.gitignore" 2>/dev/null; then
81+
log_warning "Warning: profiles/ not in .gitignore, adding it..."
82+
echo "profiles/" >> "$PROJECT_ROOT/.gitignore"
83+
fi
84+
log_success "Profiles directory is protected and will not be modified"
85+
else
86+
log_info "No profiles directory found (will be created on first run)"
87+
fi
88+
89+
# Step 3: Stash any local changes (except profiles which is in .gitignore)
8690
log_info "Step 3: Checking for local changes..."
8791
if ! git diff --quiet; then
8892
log_warning "Uncommitted changes detected, stashing..."
@@ -117,25 +121,19 @@ if git pull --rebase origin "$REPO_BRANCH"; then
117121
log_success "Successfully pulled latest code"
118122
else
119123
log_error "Failed to pull latest code"
120-
log_error "Restoring backup..."
121-
if [ -d "$BACKUP_PATH" ]; then
122-
rm -rf "$PROJECT_ROOT/profiles"
123-
cp -r "$BACKUP_PATH" "$PROJECT_ROOT/profiles"
124-
log_info "Profiles restored from backup"
125-
fi
126124
exit 1
127125
fi
128126

129127
# Step 7: Install/update dependencies
130-
log_info "Step 6: Installing/updating dependencies..."
128+
log_info "Step 7: Installing/updating dependencies..."
131129
if npm install --prefer-offline; then
132130
log_success "Dependencies installed successfully"
133131
else
134132
log_warning "npm install completed with warnings"
135133
fi
136134

137135
# Step 8: Check for PM2 running
138-
log_info "Step 7: Checking PM2 status..."
136+
log_info "Step 8: Checking PM2 status..."
139137
if command -v pm2 &> /dev/null; then
140138
if pm2 list | grep -q "bbot"; then
141139
log_info "PM2 bots detected, reloading..."
@@ -162,7 +160,7 @@ log_info "- Dependencies installed"
162160
if command -v pm2 &> /dev/null && pm2 list | grep -q "bbot"; then
163161
log_info "- PM2 processes reloaded"
164162
fi
165-
log_info "- Backup saved: $BACKUP_PATH"
163+
log_info "- Your profiles/ directory is safe and unchanged"
166164
log_info ""
167165
log_info "Log file: $LOG_FILE"
168166
log_info ""

0 commit comments

Comments
 (0)