2022-04-18 11:57:58 +02:00
|
|
|
#!/usr/bin/env bash
|
2022-04-18 11:54:06 +02:00
|
|
|
|
|
|
|
# The purpose of this script is to clear our custom pacman repository
|
2022-08-19 10:05:41 +02:00
|
|
|
# i.e. remove old versions of packages
|
2022-04-18 11:54:06 +02:00
|
|
|
# This script should NOT be run as root.
|
|
|
|
|
|
|
|
# Make sure that AWK rules file is present, readable and correctly set in this script's parameters
|
|
|
|
|
|
|
|
init() {
|
2022-04-18 12:02:06 +02:00
|
|
|
source variables.conf
|
2022-04-18 12:05:20 +02:00
|
|
|
repo_db_file=$repo_name.db.tar
|
|
|
|
repo_db_filesfile=$repo_name.files.tar
|
|
|
|
awk_rules_file='parser.awk'
|
2022-04-18 11:54:06 +02:00
|
|
|
if [ ! -e $repo_directory/$repo_db_file ] ; then
|
|
|
|
echo "Could not find db file. Exiting..."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo "ArchRepo clearing script"
|
|
|
|
}
|
|
|
|
|
|
|
|
clearRepo() {
|
2022-08-19 10:05:41 +02:00
|
|
|
if [ "$(uname)" = "OpenBSD" ]; then # TODO This could probably be done better (like with actually checking if tar is GNU...)
|
2022-04-18 13:44:29 +02:00
|
|
|
gnutar="gtar"
|
|
|
|
else
|
|
|
|
gnutar="tar"
|
|
|
|
fi
|
|
|
|
stream=$($gnutar xOf $repo_directory/$repo_db_file --wildcards */desc | awk -f $awk_rules_file)
|
2022-04-18 11:54:06 +02:00
|
|
|
|
|
|
|
OIFS=$IFS
|
|
|
|
IFS='|'
|
|
|
|
stream="${stream:1}"
|
|
|
|
current=""
|
|
|
|
for package in $stream
|
|
|
|
do
|
|
|
|
IFS='
|
|
|
|
'
|
|
|
|
count=0
|
|
|
|
for line in $package; do
|
|
|
|
if [ $count -eq 0 ]; then
|
|
|
|
current="$current $line"
|
|
|
|
else
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
((count++))
|
|
|
|
done
|
|
|
|
|
|
|
|
IFS='|'
|
|
|
|
done
|
|
|
|
IFS=$OIFS
|
|
|
|
|
|
|
|
cd $repo_directory
|
|
|
|
reg="^($repo_name.).+"
|
|
|
|
for filename in *; do
|
|
|
|
if [[ $filename =~ $reg || $filename = 'sync' || $filename = 'local' || $filename = 'resources' ]]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
for package in $current; do
|
|
|
|
if [ $filename = $package ]; then
|
|
|
|
continue 2
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo "Removing $filename..."
|
|
|
|
rm $filename
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
run_directory_path=$(pwd)
|
|
|
|
|
|
|
|
# Main process
|
|
|
|
|
|
|
|
if [ "$1" = "" ]; then
|
|
|
|
init
|
|
|
|
clearRepo
|
|
|
|
else
|
|
|
|
echo "Please call this script without any arguments."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit 0
|