mirror of
https://github.com/acedanger/shell.git
synced 2025-12-06 04:30:13 -08:00
feat: Add enhanced crontab entries and backup management with improved logging and fallback mechanisms
This commit is contained in:
@@ -50,17 +50,29 @@ backup_current_crontab() {
|
||||
install_enhanced_crontab() {
|
||||
log_info "Installing enhanced crontab entries for system: $HOSTNAME"
|
||||
|
||||
# Check for system-specific crontab file first
|
||||
if [ ! -f "$ENHANCED_CRONTAB_FILE" ]; then
|
||||
log_error "Enhanced crontab file not found: $ENHANCED_CRONTAB_FILE"
|
||||
log_warning "System-specific crontab file not found: $ENHANCED_CRONTAB_FILE"
|
||||
log_info "Available crontab files:"
|
||||
ls -la "$SCRIPT_DIR"/enhanced-crontab-*.txt 2>/dev/null || log_warning "No system-specific crontab files found"
|
||||
return 1
|
||||
|
||||
# Check for generic fallback
|
||||
FALLBACK_CRONTAB="$SCRIPT_DIR/enhanced-crontab.txt"
|
||||
if [ -f "$FALLBACK_CRONTAB" ]; then
|
||||
log_info "Using generic fallback crontab: $FALLBACK_CRONTAB"
|
||||
ENHANCED_CRONTAB_FILE="$FALLBACK_CRONTAB"
|
||||
else
|
||||
log_error "No suitable crontab file found. Please create $ENHANCED_CRONTAB_FILE or $FALLBACK_CRONTAB"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Create a backup before making changes
|
||||
if [ -f "$SCRIPT_DIR/crontab-backup-system.sh" ]; then
|
||||
log_info "Creating pre-install backup"
|
||||
"$SCRIPT_DIR/crontab-backup-system.sh" backup pre-install
|
||||
if ! "$SCRIPT_DIR/crontab-backup-system.sh" backup pre-install; then
|
||||
log_warning "Pre-install backup failed (normal for systems with no existing crontab)"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Extract just the cron entries (skip comments and empty lines)
|
||||
@@ -74,6 +86,8 @@ install_enhanced_crontab() {
|
||||
rm -f /tmp/cron_entries_only.txt
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
log_warning "Backup script not found, skipping validation"
|
||||
fi
|
||||
|
||||
if sudo crontab /tmp/cron_entries_only.txt; then
|
||||
@@ -82,7 +96,9 @@ install_enhanced_crontab() {
|
||||
|
||||
# Create a post-install backup
|
||||
if [ -f "$SCRIPT_DIR/crontab-backup-system.sh" ]; then
|
||||
"$SCRIPT_DIR/crontab-backup-system.sh" backup post-install
|
||||
if ! "$SCRIPT_DIR/crontab-backup-system.sh" backup post-install; then
|
||||
log_warning "Post-install backup failed, but crontab installation was successful"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
log_error "Failed to install enhanced crontab entries"
|
||||
|
||||
Reference in New Issue
Block a user