Hi, I'm running RebornOS (Arch Linux based) and want to know when the maintainers add brand new packages in the repo. However I haven't found an easy way to do that, there's no RSS for such news. Is it possible to write a bash script that will check if new software was added?
Assistant
Yes, it's definitely possible to write a bash script that checks for new software added to the RebornOS repositories. Since RebornOS is based on Arch Linux, it uses pacman as its package manager, and you can leverage pacman commands to list packages from repositories.
Below, I'll guide you through creating a script that:
Retrieves the current list of packages from the RebornOS repository.
Compares it with a previously saved list.
Reports any new packages added since the last check.
Prerequisites
Ensure you have bash, pacman, and the necessary permissions to read /var/lib/pacman/sync/.
Familiarity with basic command-line operations.
Step-by-Step Guide
1. Identify the RebornOS Repository Name
First, determine the exact name of the RebornOS repository as defined in your pacman.conf. You can find this by checking /etc/pacman.conf or files under /etc/pacman.d/. Look for lines like:
ini
[rebornos]
Include = /etc/pacman.d/rebornos-mirrorlist
In this example, the repository name is rebornos.
2. Create the Script
Create a new bash script file:
bash
nano check_new_packages.sh
Paste the following content into it:
bash
#!/bin/bash
# Configuration
REPO_NAME="rebornos" # Replace with your actual RebornOS repository name
PACKAGE_LIST_DIR="$HOME/.rebornos-package-list"
CURRENT_DATE=$(date +"%Y%m%d")
CURRENT_PACKAGE_LIST="$PACKAGE_LIST_DIR/packages-$CURRENT_DATE.txt"
LATEST_PACKAGE_LIST="$PACKAGE_LIST_DIR/packages-latest.txt"
# Ensure the package list directory exists
mkdir -p "$PACKAGE_LIST_DIR"
# Fetch the current package list from the RebornOS repository
pacman -Sl "$REPO_NAME" | awk '{print $2}' | sort > "$CURRENT_PACKAGE_LIST"
# Check if a previous package list exists
if [ -f "$LATEST_PACKAGE_LIST" ]; then
# Compare previous and current package lists to find new packages
NEW_PACKAGES=$(comm -13 "$LATEST_PACKAGE_LIST" "$CURRENT_PACKAGE_LIST")
if [ -n "$NEW_PACKAGES" ]; then
echo "New packages added to the $REPO_NAME repository since the last check:"
echo "$NEW_PACKAGES"
# Optionally, save the new packages to a file
echo "$NEW_PACKAGES" > "$PACKAGE_LIST_DIR/new-packages-$CURRENT_DATE.txt"
else
echo "No new packages have been added since the last check."
fi
else
echo "No previous package list found. Saving the current package list for future comparisons."
fi
# Update the symlink to the latest package list
ln -sf "$CURRENT_PACKAGE_LIST" "$LATEST_PACKAGE_LIST"
3. Make the Script Executable
Save the script and make it executable:
bash
chmod +x check_new_packages.sh
4. Run the Script Manually
You can run the script manually to test it:
bash
./check_new_packages.sh
On the first run, it will save the current package list and inform you that no previous list was found.
On subsequent runs, it will compare the current list with the previous one and notify you of any new packages.
5. Schedule the Script to Run Periodically
To automate the process, schedule the script using cron:
bash
crontab -e
Add the following line to run the script daily at 9 AM:
cron
0 9 * * * /path/to/your/check_new_packages.sh
Save and exit the crontab editor.
Explanation of the Script
Variables:
REPO_NAME: The name of the RebornOS repository.
PACKAGE_LIST_DIR: Directory to store package lists.
CURRENT_PACKAGE_LIST: File to store the current package list.
LATEST_PACKAGE_LIST: Symlink to the latest package list.
Commands:
pacman -Sl "$REPO_NAME": Lists all packages in the specified repository.
awk '{print $2}': Extracts the package names from the pacman output.
sort: Sorts the package names for consistent ordering.
comm -13: Compares two sorted files and outputs lines unique to the second file (new packages).
Logic:
First, the script checks if a previous package list exists.
If it does, it compares the previous and current lists to find new packages.
If there are new packages, it outputs them.
If there's no previous list, it creates one for future comparisons.
Customization and Enhancements
Email Notifications:
If you want to receive email notifications when new packages are added, you can modify the script to send emails.
Add this inside the if [ -n "$NEW_PACKAGES" ]; block:
bash
echo "$NEW_PACKAGES" | mail -s "New RebornOS Packages Added" your-email@example.com
Ensure that you have a mail utility like mailx installed and configured.
Logging:
Append the script output to a log file for record-keeping:
Add checks to ensure that pacman commands succeed and handle any errors appropriately.
Points to Consider
Repository Access:
Ensure that your system's package database is up-to-date before running the script by performing sudo pacman -Sy. However, frequent syncs may not be ideal.
Alternatively, you can modify the script to include pacman -Sl --refresh "$REPO_NAME" to force a refresh, but use this judiciously to avoid unnecessary load on repository servers.
Permissions:
Reading the package database typically doesn't require root privileges, but ensure that your user has the necessary permissions.
Repository Mirrors:
If you use multiple mirrors, the availability of new packages might vary slightly. Generally, syncing mirrors are kept consistent, but there can be delays.
Conclusion
By automating this script, you'll be able to keep track of new packages added to the RebornOS repository. This method leverages existing package management tools and simple file comparison to achieve your goal.
If you encounter any issues or need further customization, feel free to ask!