summaryrefslogtreecommitdiff
path: root/check_pinned.sh
blob: e266b46b3df722f96753f16c79b45effd1b235c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/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