1+ #! /usr/bin/env bash
2+ #
3+ # Script to track package updates for release notes
4+ # This script compares current package versions with previous versions and generates a report
5+
6+ set -e
7+
8+ # Colors for better output
9+ GREEN=' \033[0;32m'
10+ YELLOW=' \033[0;33m'
11+ BLUE=' \033[0;34m'
12+ NC=' \033[0m' # No Color
13+
14+ log () {
15+ echo -e " ${GREEN} [INFO]${NC} $1 "
16+ }
17+
18+ warn () {
19+ echo -e " ${YELLOW} [WARN]${NC} $1 "
20+ }
21+
22+ info () {
23+ echo -e " ${BLUE} [INFO]${NC} $1 "
24+ }
25+
26+ # Directory for storing package version data
27+ DATA_DIR=" /tmp/package-versions"
28+ CURRENT_VERSIONS_FILE=" ${DATA_DIR} /current_versions.txt"
29+ PREVIOUS_VERSIONS_FILE=" ${DATA_DIR} /previous_versions.txt"
30+ UPDATES_FILE=" ${DATA_DIR} /package_updates.md"
31+
32+ # Create data directory if it doesn't exist
33+ mkdir -p " ${DATA_DIR} "
34+
35+ # Function to get current package versions
36+ get_current_versions () {
37+ log " Getting current package versions..."
38+
39+ # Make sure we're using an updated database
40+ pacman -Sy --noconfirm > /dev/null 2>&1
41+
42+ # Get package list from packages.x86_64
43+ if [ -f " packages.x86_64" ]; then
44+ while read -r pkg; do
45+ # Skip empty lines and comments
46+ [[ -z " $pkg " || " $pkg " =~ ^# ]] && continue
47+
48+ # Get version information for each package
49+ version= $( pacman -Si " $pkg " 2> /dev/null | grep " Version" | head -n 1 | awk ' {print $3}' )
50+
51+ if [ -n " $version " ]; then
52+ echo " $pkg =$version " >> " ${CURRENT_VERSIONS_FILE} .tmp"
53+ else
54+ warn " Could not get version for package: $pkg "
55+ fi
56+ done < " packages.x86_64"
57+
58+ # Sort the file for easier comparison
59+ sort " ${CURRENT_VERSIONS_FILE} .tmp" > " ${CURRENT_VERSIONS_FILE} "
60+ rm " ${CURRENT_VERSIONS_FILE} .tmp"
61+ else
62+ warn " packages.x86_64 file not found!"
63+ return 1
64+ fi
65+
66+ log " Current package versions saved to ${CURRENT_VERSIONS_FILE} "
67+ }
68+
69+ # Function to save current versions as the new previous versions
70+ save_versions_as_previous () {
71+ if [ -f " ${CURRENT_VERSIONS_FILE} " ]; then
72+ cp " ${CURRENT_VERSIONS_FILE} " " ${PREVIOUS_VERSIONS_FILE} "
73+ log " Saved current versions as previous for next comparison."
74+ else
75+ warn " No current versions file found to save as previous."
76+ fi
77+ }
78+
79+ # Function to compare current with previous versions
80+ compare_versions () {
81+ log " Comparing current package versions with previous versions..."
82+
83+ # If previous versions file doesn't exist, create an empty one
84+ if [ ! -f " ${PREVIOUS_VERSIONS_FILE} " ]; then
85+ warn " No previous versions file found. This might be the first run."
86+ touch " ${PREVIOUS_VERSIONS_FILE} "
87+ fi
88+
89+ # Create updates file with header
90+ echo " ## 📦 Package Updates" > " ${UPDATES_FILE} "
91+ echo " " >> " ${UPDATES_FILE} "
92+
93+ # Track if we found any updates
94+ found_updates=false
95+
96+ while IFS=' =' read -r pkg current_version; do
97+ # Get previous version of this package
98+ previous_version=$( grep " ^${pkg} =" " ${PREVIOUS_VERSIONS_FILE} " | cut -d' =' -f2)
99+
100+ # If package is new or has a different version
101+ if [ -z " $previous_version " ]; then
102+ echo " - ➕ New package: **${pkg} ** (${current_version} )" >> " ${UPDATES_FILE} "
103+ found_updates=true
104+ elif [ " $previous_version " != " $current_version " ]; then
105+ echo " - 🔄 Updated: **${pkg} ** (${previous_version} → ${current_version} )" >> " ${UPDATES_FILE} "
106+ found_updates=true
107+ fi
108+ done < " ${CURRENT_VERSIONS_FILE} "
109+
110+ # Check for packages that were removed
111+ while IFS=' =' read -r pkg previous_version; do
112+ if ! grep -q " ^${pkg} =" " ${CURRENT_VERSIONS_FILE} " ; then
113+ echo " - ❌ Removed: **${pkg} ** (was ${previous_version} )" >> " ${UPDATES_FILE} "
114+ found_updates=true
115+ fi
116+ done < " ${PREVIOUS_VERSIONS_FILE} "
117+
118+ # If no updates were found, add a note
119+ if [ " $found_updates " = false ]; then
120+ echo " No package updates since the previous release." >> " ${UPDATES_FILE} "
121+ fi
122+
123+ log " Package comparison complete. Results written to ${UPDATES_FILE} "
124+ }
125+
126+ # Main function
127+ main () {
128+ log " Starting package tracking process..."
129+
130+ # Get current versions
131+ get_current_versions
132+
133+ # Compare with previous versions
134+ compare_versions
135+
136+ # After successful comparison, save current as previous for next run
137+ save_versions_as_previous
138+
139+ log " Package tracking completed."
140+ }
141+
142+ # Run the main function
143+ main
0 commit comments