#!/bin/bash set -e # List of packages to monitor PACKAGES=( "linux-image-liquorix-amd64" "linux-headers-liquorix-amd64" ) # Temp file to store last known versions STATE_FILE="/var/tmp/pinned_versions.state" # Telegram Bot Info (replace with your own) TELEGRAM_BOT_TOKEN="YOUR_TELEGRAM_BOT_TOKEN" TELEGRAM_CHAT_ID="YOUR_CHAT_ID" # Function to send Telegram message send_telegram() { local msg="$1" curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \ -d chat_id="${TELEGRAM_CHAT_ID}" \ -d text="$msg" > /dev/null } # Check and alert alert_needed=0 alert_msg="🚨 *Pinned Package Alert* 🚨\n" for pkg in "${PACKAGES[@]}"; do current_ver=$(apt-cache policy "$pkg" | grep Installed | awk '{print $2}') last_ver="" if [ -f "$STATE_FILE" ]; then last_ver=$(grep "^$pkg=" "$STATE_FILE" | cut -d= -f2) fi if [ "$current_ver" != "$last_ver" ]; then alert_needed=1 alert_msg+="Package *$pkg* changed from '$last_ver' to '$current_ver'\n" fi # Update state file grep -v "^$pkg=" "$STATE_FILE" 2>/dev/null > "${STATE_FILE}.tmp" || true echo "$pkg=$current_ver" >> "${STATE_FILE}.tmp" mv "${STATE_FILE}.tmp" "$STATE_FILE" done if [ "$alert_needed" -eq 1 ]; then # Uncomment below to enable Telegram alerts # send_telegram "$alert_msg" # Command-line notification echo -e "\n🚨 Pinned Package Alert! 🚨" echo -e "$alert_msg" else echo "No changes detected in pinned packages." fi