dev: automated commit - 2025-06-09 10:20:01

This commit is contained in:
Mariano Z. 2025-06-09 10:20:01 -03:00
parent c71e2bd9a9
commit 38747ba84e

View file

@ -1,5 +1,4 @@
#!/usr/bin/env zsh #!/usr/bin/env zsh
# Configuration # Configuration
MAINTENANCE_SCRIPT="$HOME/.local/bin/maintenance.sh" MAINTENANCE_SCRIPT="$HOME/.local/bin/maintenance.sh"
TIMESTAMP_FILE="$HOME/.local/share/arch_maintenance_timestamp" TIMESTAMP_FILE="$HOME/.local/share/arch_maintenance_timestamp"
@ -14,7 +13,6 @@ if [ -f "$TIMESTAMP_FILE" ]; then
LAST_RUN=$(cat $TIMESTAMP_FILE) LAST_RUN=$(cat $TIMESTAMP_FILE)
CURRENT_TIME=$(date +%s) CURRENT_TIME=$(date +%s)
DAYS_DIFF=$(( (CURRENT_TIME - LAST_RUN) / 86400 )) DAYS_DIFF=$(( (CURRENT_TIME - LAST_RUN) / 86400 ))
# Return immediately if maintenance not due # Return immediately if maintenance not due
[ $DAYS_DIFF -lt $INTERVAL ] && return 0 [ $DAYS_DIFF -lt $INTERVAL ] && return 0
else else
@ -46,7 +44,6 @@ ask_confirm() {
# Function to run maintenance script # Function to run maintenance script
run_maintenance() { run_maintenance() {
print_styled "Running system maintenance script..." print_styled "Running system maintenance script..."
if sudo $MAINTENANCE_SCRIPT; then if sudo $MAINTENANCE_SCRIPT; then
date +%s > $TIMESTAMP_FILE date +%s > $TIMESTAMP_FILE
print_styled "✓ Maintenance completed successfully." print_styled "✓ Maintenance completed successfully."
@ -55,15 +52,58 @@ run_maintenance() {
fi fi
} }
# Function to snooze for 7 more days
snooze_maintenance() {
SNOOZE_TIME=$(($(date +%s) - (${INTERVAL} - 7) * 86400))
echo $SNOOZE_TIME > $TIMESTAMP_FILE
print_styled "⏰ Maintenance reminder snoozed for 7 more days."
}
# Display maintenance notification # Display maintenance notification
echo "" echo ""
print_styled "⚠️ It's been $DAYS_DIFF days since your last system maintenance" print_styled "⚠️ It's been $DAYS_DIFF days since your last system maintenance"
if ask_confirm "Would you like to run maintenance now?"; then # Enhanced confirmation with three options
if command -v gum &> /dev/null; then
CHOICE=$(gum choose "Run maintenance now" "Skip this time" "Don't ask for 7 more days")
case "$CHOICE" in
"Run maintenance now")
run_maintenance run_maintenance
else ;;
"Skip this time")
print_styled "Maintenance skipped. You'll be reminded next time you start your shell." print_styled "Maintenance skipped. You'll be reminded next time you start your shell."
print_styled "To run manually: sudo $MAINTENANCE_SCRIPT" print_styled "To run manually: sudo $MAINTENANCE_SCRIPT"
;;
"Don't ask for 7 more days")
snooze_maintenance
;;
esac
else
# Fallback for systems without gum
echo "Choose an option:"
echo "1) Run maintenance now"
echo "2) Skip this time"
echo "3) Don't ask for 7 more days"
echo -n "Enter your choice (1-3): "
read -k 1 CHOICE
echo ""
case "$CHOICE" in
1)
run_maintenance
;;
2)
print_styled "Maintenance skipped. You'll be reminded next time you start your shell."
print_styled "To run manually: sudo $MAINTENANCE_SCRIPT"
;;
3)
snooze_maintenance
;;
*)
print_styled "Invalid choice. Maintenance skipped."
print_styled "To run manually: sudo $MAINTENANCE_SCRIPT"
;;
esac
fi fi
return 0 return 0