feat(install-scripts): add system monitor scripts (battery, disk, temp, notifier)

This commit is contained in:
Deekshith N
2025-10-03 12:15:12 +05:30
parent 1e17f173a7
commit f50d9e751c
4 changed files with 511 additions and 0 deletions

View File

@@ -0,0 +1,116 @@
#!/bin/bash
# 💫 https://github.com/JaKooLit 💫 #
# Battery Monitor and Low Battery Notification #
battery=(
acpi
libnotify
)
## WARNING: DO NOT EDIT BEYOND THIS LINE IF YOU DON'T KNOW WHAT YOU ARE DOING! ##
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Change the working directory to the parent directory of the script
PARENT_DIR="$SCRIPT_DIR/.."
cd "$PARENT_DIR" || { echo "${ERROR} Failed to change directory to $PARENT_DIR"; exit 1; }
# Source the global functions script
if ! source "$(dirname "$(readlink -f "$0")")/Global_functions.sh"; then
echo "Failed to source Global_functions.sh"
exit 1
fi
# Set the name of the log file to include the current date and time
LOG="Install-Logs/install-$(date +%d-%H%M%S)_battery-monitor.log"
# Battery Monitor
printf "${NOTE} Installing ${SKY_BLUE}Battery Monitor${RESET} Packages...\n"
for BAT in "${battery[@]}"; do
install_package "$BAT" "$LOG"
done
# Create battery monitoring script
printf "${NOTE} Creating ${YELLOW}battery monitoring${RESET} script...\n"
BATTERY_SCRIPT="$HOME/.config/hypr/scripts/battery-monitor.sh"
mkdir -p "$HOME/.config/hypr/scripts"
cat > "$BATTERY_SCRIPT" << 'EOF'
#!/bin/bash
# Low Battery Notification Script
# Monitors battery level and sends notifications
# Configuration
LOW_BATTERY_THRESHOLD=20
CRITICAL_BATTERY_THRESHOLD=10
CHECK_INTERVAL=60 # Check every 60 seconds
# Track notification state to avoid spam
NOTIFIED_LOW=false
NOTIFIED_CRITICAL=false
while true; do
# Get battery percentage
BATTERY_LEVEL=$(acpi -b | grep -P -o '[0-9]+(?=%)')
BATTERY_STATUS=$(acpi -b | grep -o 'Discharging\|Charging\|Full')
# Only send notifications when discharging
if [ "$BATTERY_STATUS" = "Discharging" ]; then
if [ "$BATTERY_LEVEL" -le "$CRITICAL_BATTERY_THRESHOLD" ] && [ "$NOTIFIED_CRITICAL" = false ]; then
notify-send -u critical -i battery-caution "Critical Battery" "Battery level is at ${BATTERY_LEVEL}%! Please plug in your charger immediately."
NOTIFIED_CRITICAL=true
NOTIFIED_LOW=true
elif [ "$BATTERY_LEVEL" -le "$LOW_BATTERY_THRESHOLD" ] && [ "$NOTIFIED_LOW" = false ]; then
notify-send -u normal -i battery-low "Low Battery" "Battery level is at ${BATTERY_LEVEL}%. Consider plugging in your charger."
NOTIFIED_LOW=true
fi
else
# Reset notification flags when charging or full
NOTIFIED_LOW=false
NOTIFIED_CRITICAL=false
fi
sleep "$CHECK_INTERVAL"
done
EOF
chmod +x "$BATTERY_SCRIPT"
printf "${OK} Battery monitoring script created at ${YELLOW}$BATTERY_SCRIPT${RESET}\n"
# Create systemd user service
printf "${NOTE} Creating ${YELLOW}systemd user service${RESET} for battery monitoring...\n"
SYSTEMD_DIR="$HOME/.config/systemd/user"
mkdir -p "$SYSTEMD_DIR"
cat > "$SYSTEMD_DIR/battery-monitor.service" << EOF
[Unit]
Description=Battery Level Monitor
After=graphical-session.target
[Service]
Type=simple
ExecStart=$BATTERY_SCRIPT
Restart=on-failure
RestartSec=10
[Install]
WantedBy=default.target
EOF
printf "${OK} Systemd service created\n"
# Enable and start the service
printf "${NOTE} Enabling and starting ${YELLOW}battery-monitor${RESET} service...\n"
systemctl --user daemon-reload
systemctl --user enable battery-monitor.service 2>&1 | tee -a "$LOG"
systemctl --user start battery-monitor.service 2>&1 | tee -a "$LOG"
printf "${OK} Battery monitor service is now running!\n"
printf "${INFO} You can check status with: ${YELLOW}systemctl --user status battery-monitor${RESET}\n"
printf "${INFO} To stop: ${YELLOW}systemctl --user stop battery-monitor${RESET}\n"
printf "${INFO} To disable: ${YELLOW}systemctl --user disable battery-monitor${RESET}\n"
printf "\n%.0s" {1..2}

View File

@@ -0,0 +1,126 @@
#!/bin/bash
# 💫 https://github.com/JaKooLit 💫 #
# Disk Space Monitor #
disk=(
libnotify
)
## WARNING: DO NOT EDIT BEYOND THIS LINE IF YOU DON'T KNOW WHAT YOU ARE DOING! ##
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Change the working directory to the parent directory of the script
PARENT_DIR="$SCRIPT_DIR/.."
cd "$PARENT_DIR" || { echo "${ERROR} Failed to change directory to $PARENT_DIR"; exit 1; }
# Source the global functions script
if ! source "$(dirname "$(readlink -f "$0")")/Global_functions.sh"; then
echo "Failed to source Global_functions.sh"
exit 1
fi
# Set the name of the log file to include the current date and time
LOG="Install-Logs/install-$(date +%d-%H%M%S)_disk-monitor.log"
# Disk Monitor
printf "${NOTE} Installing ${SKY_BLUE}Disk Monitor${RESET} Packages...\n"
for DISK in "${disk[@]}"; do
install_package "$DISK" "$LOG"
done
# Create disk monitoring script
printf "${NOTE} Creating ${YELLOW}disk space monitoring${RESET} script...\n"
DISK_SCRIPT="$HOME/.config/hypr/scripts/disk-monitor.sh"
mkdir -p "$HOME/.config/hypr/scripts"
cat > "$DISK_SCRIPT" << 'EOF'
#!/bin/bash
# Disk Space Monitoring Script
# Monitors disk usage and sends notifications
# Configuration
DISK_WARNING_THRESHOLD=80
DISK_CRITICAL_THRESHOLD=90
CHECK_INTERVAL=300 # Check every 5 minutes
# Track notification state
declare -A NOTIFIED_WARNING
declare -A NOTIFIED_CRITICAL
while true; do
# Get disk usage for all mounted filesystems
df -h | grep '^/dev/' | while read -r line; do
DEVICE=$(echo "$line" | awk '{print $1}')
MOUNT=$(echo "$line" | awk '{print $6}')
USAGE=$(echo "$line" | awk '{print $5}' | sed 's/%//')
# Skip if usage is not a number
if ! [[ "$USAGE" =~ ^[0-9]+$ ]]; then
continue
fi
# Check disk usage
if [ "$USAGE" -ge "$DISK_CRITICAL_THRESHOLD" ]; then
if [ "${NOTIFIED_CRITICAL[$MOUNT]}" != "true" ]; then
notify-send -u critical -i drive-harddisk "Critical Disk Space" "Mount point $MOUNT is ${USAGE}% full!\nDevice: $DEVICE"
NOTIFIED_CRITICAL[$MOUNT]="true"
NOTIFIED_WARNING[$MOUNT]="true"
fi
elif [ "$USAGE" -ge "$DISK_WARNING_THRESHOLD" ]; then
if [ "${NOTIFIED_WARNING[$MOUNT]}" != "true" ]; then
notify-send -u normal -i drive-harddisk "Low Disk Space" "Mount point $MOUNT is ${USAGE}% full\nDevice: $DEVICE"
NOTIFIED_WARNING[$MOUNT]="true"
fi
else
# Reset notifications when usage drops
if [ "$USAGE" -lt $((DISK_WARNING_THRESHOLD - 5)) ]; then
NOTIFIED_WARNING[$MOUNT]="false"
NOTIFIED_CRITICAL[$MOUNT]="false"
fi
fi
done
sleep "$CHECK_INTERVAL"
done
EOF
chmod +x "$DISK_SCRIPT"
printf "${OK} Disk monitoring script created at ${YELLOW}$DISK_SCRIPT${RESET}\n"
# Create systemd user service
printf "${NOTE} Creating ${YELLOW}systemd user service${RESET} for disk monitoring...\n"
SYSTEMD_DIR="$HOME/.config/systemd/user"
mkdir -p "$SYSTEMD_DIR"
cat > "$SYSTEMD_DIR/disk-monitor.service" << EOF
[Unit]
Description=Disk Space Monitor
After=graphical-session.target
[Service]
Type=simple
ExecStart=$DISK_SCRIPT
Restart=on-failure
RestartSec=10
[Install]
WantedBy=default.target
EOF
printf "${OK} Systemd service created\n"
# Enable and start the service
printf "${NOTE} Enabling and starting ${YELLOW}disk-monitor${RESET} service...\n"
systemctl --user daemon-reload
systemctl --user enable disk-monitor.service 2>&1 | tee -a "$LOG"
systemctl --user start disk-monitor.service 2>&1 | tee -a "$LOG"
printf "${OK} Disk monitor service is now running!\n"
printf "${INFO} You can check status with: ${YELLOW}systemctl --user status disk-monitor${RESET}\n"
printf "${INFO} View disk usage: ${YELLOW}df -h${RESET}\n"
printf "\n%.0s" {1..2}

View File

@@ -0,0 +1,156 @@
#!/bin/bash
# 💫 https://github.com/JaKooLit 💫 #
# Temperature Monitor - CPU/GPU Temperature Alerts #
temp=(
lm_sensors
libnotify
)
## WARNING: DO NOT EDIT BEYOND THIS LINE IF YOU DON'T KNOW WHAT YOU ARE DOING! ##
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Change the working directory to the parent directory of the script
PARENT_DIR="$SCRIPT_DIR/.."
cd "$PARENT_DIR" || { echo "${ERROR} Failed to change directory to $PARENT_DIR"; exit 1; }
# Source the global functions script
if ! source "$(dirname "$(readlink -f "$0")")/Global_functions.sh"; then
echo "Failed to source Global_functions.sh"
exit 1
fi
# Set the name of the log file to include the current date and time
LOG="Install-Logs/install-$(date +%d-%H%M%S)_temp-monitor.log"
# Temperature Monitor
printf "${NOTE} Installing ${SKY_BLUE}Temperature Monitor${RESET} Packages...\n"
for TEMP in "${temp[@]}"; do
install_package "$TEMP" "$LOG"
done
# Detect sensors
printf "${NOTE} Detecting ${YELLOW}hardware sensors${RESET}...\n"
sudo sensors-detect --auto 2>&1 | tee -a "$LOG"
# Create temperature monitoring script
printf "${NOTE} Creating ${YELLOW}temperature monitoring${RESET} script...\n"
TEMP_SCRIPT="$HOME/.config/hypr/scripts/temp-monitor.sh"
mkdir -p "$HOME/.config/hypr/scripts"
cat > "$TEMP_SCRIPT" << 'EOF'
#!/bin/bash
# Temperature Monitoring Script
# Monitors CPU and GPU temperatures and sends alerts
# Configuration
CPU_TEMP_WARNING=75
CPU_TEMP_CRITICAL=85
GPU_TEMP_WARNING=75
GPU_TEMP_CRITICAL=85
CHECK_INTERVAL=30 # Check every 30 seconds
# Track notification state
NOTIFIED_CPU_WARN=false
NOTIFIED_CPU_CRIT=false
NOTIFIED_GPU_WARN=false
NOTIFIED_GPU_CRIT=false
while true; do
# Get CPU temperature (average of all cores)
CPU_TEMP=$(sensors | grep -i 'Package id 0:\|Tdie:' | awk '{print $4}' | sed 's/+//;s/°C//' | head -1)
# If Package id not found, try other methods
if [ -z "$CPU_TEMP" ]; then
CPU_TEMP=$(sensors | grep -i 'Core 0:' | awk '{print $3}' | sed 's/+//;s/°C//' | head -1)
fi
# Get GPU temperature (if available)
GPU_TEMP=$(sensors | grep -i 'edge:\|temp1:' | awk '{print $2}' | sed 's/+//;s/°C//' | head -1)
# Check CPU temperature
if [ -n "$CPU_TEMP" ]; then
CPU_TEMP_INT=${CPU_TEMP%.*}
if [ "$CPU_TEMP_INT" -ge "$CPU_TEMP_CRITICAL" ]; then
if [ "$NOTIFIED_CPU_CRIT" = false ]; then
notify-send -u critical -i temperature-high "Critical CPU Temperature" "CPU temperature is ${CPU_TEMP}°C! System may throttle or shutdown."
NOTIFIED_CPU_CRIT=true
NOTIFIED_CPU_WARN=true
fi
elif [ "$CPU_TEMP_INT" -ge "$CPU_TEMP_WARNING" ]; then
if [ "$NOTIFIED_CPU_WARN" = false ]; then
notify-send -u normal -i temperature-normal "High CPU Temperature" "CPU temperature is ${CPU_TEMP}°C"
NOTIFIED_CPU_WARN=true
fi
else
NOTIFIED_CPU_WARN=false
NOTIFIED_CPU_CRIT=false
fi
fi
# Check GPU temperature
if [ -n "$GPU_TEMP" ]; then
GPU_TEMP_INT=${GPU_TEMP%.*}
if [ "$GPU_TEMP_INT" -ge "$GPU_TEMP_CRITICAL" ]; then
if [ "$NOTIFIED_GPU_CRIT" = false ]; then
notify-send -u critical -i temperature-high "Critical GPU Temperature" "GPU temperature is ${GPU_TEMP}°C!"
NOTIFIED_GPU_CRIT=true
NOTIFIED_GPU_WARN=true
fi
elif [ "$GPU_TEMP_INT" -ge "$GPU_TEMP_WARNING" ]; then
if [ "$NOTIFIED_GPU_WARN" = false ]; then
notify-send -u normal -i temperature-normal "High GPU Temperature" "GPU temperature is ${GPU_TEMP}°C"
NOTIFIED_GPU_WARN=true
fi
else
NOTIFIED_GPU_WARN=false
NOTIFIED_GPU_CRIT=false
fi
fi
sleep "$CHECK_INTERVAL"
done
EOF
chmod +x "$TEMP_SCRIPT"
printf "${OK} Temperature monitoring script created at ${YELLOW}$TEMP_SCRIPT${RESET}\n"
# Create systemd user service
printf "${NOTE} Creating ${YELLOW}systemd user service${RESET} for temperature monitoring...\n"
SYSTEMD_DIR="$HOME/.config/systemd/user"
mkdir -p "$SYSTEMD_DIR"
cat > "$SYSTEMD_DIR/temp-monitor.service" << EOF
[Unit]
Description=Temperature Monitor
After=graphical-session.target
[Service]
Type=simple
ExecStart=$TEMP_SCRIPT
Restart=on-failure
RestartSec=10
[Install]
WantedBy=default.target
EOF
printf "${OK} Systemd service created\n"
# Enable and start the service
printf "${NOTE} Enabling and starting ${YELLOW}temp-monitor${RESET} service...\n"
systemctl --user daemon-reload
systemctl --user enable temp-monitor.service 2>&1 | tee -a "$LOG"
systemctl --user start temp-monitor.service 2>&1 | tee -a "$LOG"
printf "${OK} Temperature monitor service is now running!\n"
printf "${INFO} You can check status with: ${YELLOW}systemctl --user status temp-monitor${RESET}\n"
printf "${INFO} View temperatures: ${YELLOW}sensors${RESET}\n"
printf "\n%.0s" {1..2}

View File

@@ -0,0 +1,113 @@
#!/bin/bash
# 💫 https://github.com/JaKooLit 💫 #
# Package Update Notifier #
update=(
dnf-automatic
libnotify
)
## WARNING: DO NOT EDIT BEYOND THIS LINE IF YOU DON'T KNOW WHAT YOU ARE DOING! ##
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Change the working directory to the parent directory of the script
PARENT_DIR="$SCRIPT_DIR/.."
cd "$PARENT_DIR" || { echo "${ERROR} Failed to change directory to $PARENT_DIR"; exit 1; }
# Source the global functions script
if ! source "$(dirname "$(readlink -f "$0")")/Global_functions.sh"; then
echo "Failed to source Global_functions.sh"
exit 1
fi
# Set the name of the log file to include the current date and time
LOG="Install-Logs/install-$(date +%d-%H%M%S)_update-notifier.log"
# Update Notifier
printf "${NOTE} Installing ${SKY_BLUE}Update Notifier${RESET} Packages...\n"
for UPD in "${update[@]}"; do
install_package "$UPD" "$LOG"
done
# Create update check script
printf "${NOTE} Creating ${YELLOW}update check${RESET} script...\n"
UPDATE_SCRIPT="$HOME/.config/hypr/scripts/update-notifier.sh"
mkdir -p "$HOME/.config/hypr/scripts"
cat > "$UPDATE_SCRIPT" << 'EOF'
#!/bin/bash
# Package Update Notifier Script
# Checks for available system updates and notifies user
# Check for updates
UPDATE_COUNT=$(dnf check-update --quiet 2>/dev/null | grep -v "^$" | grep -v "^Last metadata" | wc -l)
if [ "$UPDATE_COUNT" -gt 0 ]; then
# Get list of packages to update (first 5)
UPDATE_LIST=$(dnf check-update --quiet 2>/dev/null | grep -v "^$" | grep -v "^Last metadata" | head -5 | awk '{print $1}' | tr '\n' ', ' | sed 's/,$//')
if [ "$UPDATE_COUNT" -le 5 ]; then
notify-send -u normal -i system-software-update "System Updates Available" "$UPDATE_COUNT package(s) can be updated:\n$UPDATE_LIST"
else
notify-send -u normal -i system-software-update "System Updates Available" "$UPDATE_COUNT package(s) can be updated:\n$UPDATE_LIST and more..."
fi
echo "$(date): $UPDATE_COUNT updates available"
else
echo "$(date): System is up to date"
fi
EOF
chmod +x "$UPDATE_SCRIPT"
printf "${OK} Update notifier script created at ${YELLOW}$UPDATE_SCRIPT${RESET}\n"
# Create systemd timer for update checks
printf "${NOTE} Creating ${YELLOW}systemd timer${RESET} for update checks...\n"
SYSTEMD_DIR="$HOME/.config/systemd/user"
mkdir -p "$SYSTEMD_DIR"
cat > "$SYSTEMD_DIR/update-notifier.service" << EOF
[Unit]
Description=Package Update Notifier
After=network-online.target
[Service]
Type=oneshot
ExecStart=$UPDATE_SCRIPT
[Install]
WantedBy=default.target
EOF
cat > "$SYSTEMD_DIR/update-notifier.timer" << EOF
[Unit]
Description=Check for Package Updates
Requires=update-notifier.service
[Timer]
OnBootSec=5min
OnUnitActiveSec=6h
Persistent=true
[Install]
WantedBy=timers.target
EOF
printf "${OK} Systemd timer created\n"
# Enable the timer
printf "${NOTE} Enabling ${YELLOW}update-notifier${RESET} timer...\n"
systemctl --user daemon-reload
systemctl --user enable update-notifier.timer 2>&1 | tee -a "$LOG"
systemctl --user start update-notifier.timer 2>&1 | tee -a "$LOG"
printf "${OK} Update notifier timer is now active!\n"
printf "${INFO} Updates will be checked every 6 hours\n"
printf "${INFO} Manual check: ${YELLOW}$UPDATE_SCRIPT${RESET}\n"
printf "${INFO} Check timer status: ${YELLOW}systemctl --user status update-notifier.timer${RESET}\n"
printf "\n%.0s" {1..2}