-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_sync_tool.sh
More file actions
executable file
·269 lines (224 loc) · 6.82 KB
/
setup_sync_tool.sh
File metadata and controls
executable file
·269 lines (224 loc) · 6.82 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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#!/bin/bash
# Cruise Logs Sync Tool - Setup Script
# This script sets up the sync tool in a new environment
set -e
# Configuration
TOOL_NAME="Cruise Logs Sync Tool"
REQUIRED_FILES=(
"cruise_logs_sync.py"
"sync_cruise_logs.sh"
"sync_diagnostic.py"
"find_sync_differences.py"
"requirements_sync.txt"
"SYNC_TOOL_FILES.md"
)
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Functions
print_banner() {
echo -e "${BLUE}=====================================================${NC}"
echo -e "${BLUE}🚢 CRUISE LOGS SYNC TOOL - SETUP SCRIPT 🚢${NC}"
echo -e "${BLUE}=====================================================${NC}"
echo ""
}
print_step() {
echo -e "${BLUE}[STEP]${NC} $1"
}
print_success() {
echo -e "${GREEN}✅ $1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
print_error() {
echo -e "${RED}❌ $1${NC}"
}
check_requirements() {
print_step "Checking system requirements..."
# Check for Python 3
if ! command -v python3 &> /dev/null; then
print_error "Python 3 is required but not installed"
echo "Please install Python 3.6 or later and try again"
exit 1
fi
PYTHON_VERSION=$(python3 --version | cut -d' ' -f2)
print_success "Python 3 found: $PYTHON_VERSION"
# Check for pip
if ! command -v pip3 &> /dev/null && ! command -v pip &> /dev/null; then
print_error "pip is required but not installed"
echo "Please install pip and try again"
exit 1
fi
print_success "pip found"
# Check for bash
if ! command -v bash &> /dev/null; then
print_error "bash is required but not installed"
exit 1
fi
print_success "bash found"
}
check_files() {
print_step "Checking for required files..."
local missing_files=()
for file in "${REQUIRED_FILES[@]}"; do
if [[ -f "$file" ]]; then
print_success "Found: $file"
else
print_warning "Missing: $file"
missing_files+=("$file")
fi
done
if [[ ${#missing_files[@]} -gt 0 ]]; then
print_error "Missing ${#missing_files[@]} required files"
echo "Please ensure all files are in the current directory:"
for file in "${missing_files[@]}"; do
echo " - $file"
done
exit 1
fi
print_success "All required files found"
}
install_dependencies() {
print_step "Installing Python dependencies..."
if [[ -f "requirements_sync.txt" ]]; then
if command -v pip3 &> /dev/null; then
pip3 install -r requirements_sync.txt
else
pip install -r requirements_sync.txt
fi
print_success "Python dependencies installed"
else
print_warning "requirements_sync.txt not found, installing manually"
if command -v pip3 &> /dev/null; then
pip3 install pymysql
else
pip install pymysql
fi
print_success "pymysql installed"
fi
}
setup_permissions() {
print_step "Setting up file permissions..."
# Make Python scripts executable
chmod +x cruise_logs_sync.py 2>/dev/null || true
chmod +x sync_cruise_logs.sh 2>/dev/null || true
if [[ -f "sync_diagnostic.py" ]]; then
chmod +x sync_diagnostic.py 2>/dev/null || true
fi
if [[ -f "find_sync_differences.py" ]]; then
chmod +x find_sync_differences.py 2>/dev/null || true
fi
print_success "File permissions set"
}
check_databases() {
print_step "Checking database access..."
# Check SQLite database
SQLITE_DB="$HOME/Github/Cruise_Logs/Cruise_Logs.db"
if [[ -f "$SQLITE_DB" ]]; then
print_success "SQLite database found: $SQLITE_DB"
else
print_warning "SQLite database not found: $SQLITE_DB"
echo "Make sure the Cruise_Logs repository is cloned and the database exists"
fi
# Test MariaDB connectivity (optional)
print_success "Database checks completed"
}
test_installation() {
print_step "Testing installation..."
# Test the shell launcher
if [[ -f "sync_cruise_logs.sh" ]]; then
if ./sync_cruise_logs.sh help &> /dev/null; then
print_success "Shell launcher working"
else
print_warning "Shell launcher test failed"
fi
fi
# Test Python imports
if python3 -c "import pymysql, sqlite3, hashlib, json" 2>/dev/null; then
print_success "Python dependencies working"
else
print_warning "Python dependency test failed"
fi
print_success "Installation test completed"
}
create_shortcut() {
print_step "Creating convenience shortcuts..."
# Create a simple wrapper script
cat > cruise_sync << 'EOF'
#!/bin/bash
# Convenience wrapper for Cruise Logs Sync Tool
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
"$SCRIPT_DIR/sync_cruise_logs.sh" "$@"
EOF
chmod +x cruise_sync
print_success "Created 'cruise_sync' shortcut"
}
print_usage() {
echo ""
echo -e "${BLUE}🎉 SETUP COMPLETE!${NC}"
echo ""
echo "The Cruise Logs Sync Tool is now ready to use."
echo ""
echo -e "${YELLOW}Quick Start:${NC}"
echo " ./sync_cruise_logs.sh help # Show help"
echo " ./sync_cruise_logs.sh status # Check sync status"
echo " ./sync_cruise_logs.sh dry-run # Preview changes"
echo " ./sync_cruise_logs.sh sync # Perform sync"
echo ""
echo "Or use the convenience shortcut:"
echo " ./cruise_sync status"
echo " ./cruise_sync dry-run"
echo " ./cruise_sync sync"
echo ""
echo -e "${YELLOW}Diagnostics:${NC}"
echo " python3 sync_diagnostic.py [table]"
echo " python3 find_sync_differences.py [table]"
echo ""
echo -e "${YELLOW}Documentation:${NC}"
echo " cat SYNC_TOOL_FILES.md"
echo ""
echo -e "${GREEN}Happy syncing! 🌊${NC}"
}
# Main execution
main() {
print_banner
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--skip-deps)
SKIP_DEPS=1
shift
;;
--help)
echo "Usage: $0 [--skip-deps] [--help]"
echo " --skip-deps Skip Python dependency installation"
echo " --help Show this help message"
exit 0
;;
*)
print_error "Unknown option: $1"
echo "Use --help for usage information"
exit 1
;;
esac
done
# Run setup steps
check_requirements
check_files
if [[ -z "$SKIP_DEPS" ]]; then
install_dependencies
else
print_warning "Skipping dependency installation (--skip-deps)"
fi
setup_permissions
check_databases
test_installation
create_shortcut
print_usage
}
# Run main function
main "$@"