dev: automated commit - 2025-06-09 10:20:01
This commit is contained in:
parent
c71e2bd9a9
commit
38747ba84e
1 changed files with 47 additions and 7 deletions
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env zsh
|
||||
|
||||
# Configuration
|
||||
MAINTENANCE_SCRIPT="$HOME/.local/bin/maintenance.sh"
|
||||
TIMESTAMP_FILE="$HOME/.local/share/arch_maintenance_timestamp"
|
||||
|
@ -14,7 +13,6 @@ if [ -f "$TIMESTAMP_FILE" ]; then
|
|||
LAST_RUN=$(cat $TIMESTAMP_FILE)
|
||||
CURRENT_TIME=$(date +%s)
|
||||
DAYS_DIFF=$(( (CURRENT_TIME - LAST_RUN) / 86400 ))
|
||||
|
||||
# Return immediately if maintenance not due
|
||||
[ $DAYS_DIFF -lt $INTERVAL ] && return 0
|
||||
else
|
||||
|
@ -46,7 +44,6 @@ ask_confirm() {
|
|||
# Function to run maintenance script
|
||||
run_maintenance() {
|
||||
print_styled "Running system maintenance script..."
|
||||
|
||||
if sudo $MAINTENANCE_SCRIPT; then
|
||||
date +%s > $TIMESTAMP_FILE
|
||||
print_styled "✓ Maintenance completed successfully."
|
||||
|
@ -55,15 +52,58 @@ run_maintenance() {
|
|||
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
|
||||
echo ""
|
||||
print_styled "⚠️ It's been $DAYS_DIFF days since your last system maintenance"
|
||||
|
||||
if ask_confirm "Would you like to run maintenance now?"; then
|
||||
run_maintenance
|
||||
# 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
|
||||
;;
|
||||
"Skip this time")
|
||||
print_styled "Maintenance skipped. You'll be reminded next time you start your shell."
|
||||
print_styled "To run manually: sudo $MAINTENANCE_SCRIPT"
|
||||
;;
|
||||
"Don't ask for 7 more days")
|
||||
snooze_maintenance
|
||||
;;
|
||||
esac
|
||||
else
|
||||
print_styled "Maintenance skipped. You'll be reminded next time you start your shell."
|
||||
print_styled "To run manually: sudo $MAINTENANCE_SCRIPT"
|
||||
# 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
|
||||
|
||||
return 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue