2022-04-18 11:57:58 +02:00
|
|
|
#!/usr/bin/env bash
|
2022-02-13 12:18:26 +01:00
|
|
|
|
|
|
|
# The purpose of this script is to automate the maintenance of a custom pacman (Arch Linux) repository, whose goal is to
|
|
|
|
# provide package-ready AUR softs.
|
|
|
|
# This script should NOT be run as root.
|
|
|
|
|
|
|
|
# Dependencies
|
|
|
|
# Make sure that AWK rules file is present, readable and correctly set in this script's parameters
|
|
|
|
# Make sure the following packages are installed before running this script:
|
|
|
|
# package-query aurutils git
|
|
|
|
|
2022-02-14 22:26:48 +01:00
|
|
|
|
2022-02-13 12:18:26 +01:00
|
|
|
# Functions
|
|
|
|
|
|
|
|
##################################################################
|
|
|
|
ascii_frag() {
|
|
|
|
expr match "$1" "\([^[:digit:]]*\)"
|
|
|
|
}
|
|
|
|
|
|
|
|
ascii_remainder() {
|
|
|
|
expr match "$1" "[^[:digit:]]*\(.*\)"
|
|
|
|
}
|
|
|
|
|
|
|
|
numeric_frag() {
|
|
|
|
expr match "$1" "\([[:digit:]]*\)"
|
|
|
|
}
|
|
|
|
|
|
|
|
numeric_remainder() {
|
|
|
|
expr match "$1" "[[:digit:]]*\(.*\)"
|
|
|
|
}
|
|
|
|
|
|
|
|
# return 1 for $1 > $2
|
|
|
|
# return 2 for $1 < $2
|
|
|
|
# return 0 for equal
|
|
|
|
vercomp() {
|
|
|
|
local WORK1="$1"
|
|
|
|
local WORK2="$2"
|
|
|
|
local NUM1="", NUM2="", ASCII1="", ASCII2=""
|
|
|
|
while true; do
|
|
|
|
ASCII1=`ascii_frag "${WORK1}"`
|
|
|
|
ASCII2=`ascii_frag "${WORK2}"`
|
|
|
|
WORK1=`ascii_remainder "${WORK1}"`
|
|
|
|
WORK2=`ascii_remainder "${WORK2}"`
|
|
|
|
|
|
|
|
if [ "${ASCII1}" \> "${ASCII2}" ]; then
|
|
|
|
return 1
|
|
|
|
elif [ "${ASCII1}" \< "${ASCII2}" ]; then
|
|
|
|
return 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
NUM1=`numeric_frag "${WORK1}"`
|
|
|
|
NUM2=`numeric_frag "${WORK2}"`
|
|
|
|
WORK1=`numeric_remainder "${WORK1}"`
|
|
|
|
WORK2=`numeric_remainder "${WORK2}"`
|
|
|
|
|
|
|
|
if [ -z "${NUM1}" -a -z "${NUM2}" ]; then
|
|
|
|
return 0
|
|
|
|
elif [ -z "${NUM1}" -a -n "${NUM2}" ]; then
|
|
|
|
return 2
|
|
|
|
elif [ -n "${NUM1}" -a -z "${NUM2}" ]; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "${NUM1}" -gt "${NUM2}" ]; then
|
|
|
|
return 1
|
|
|
|
elif [ "${NUM1}" -lt "${NUM2}" ]; then
|
|
|
|
return 2
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
##################################################################
|
|
|
|
|
|
|
|
init() {
|
|
|
|
# Only run if the user is not root
|
|
|
|
if [[ $USER = 'root' ]] ; then
|
|
|
|
echo "You cannot run this script as root!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$(ls $run_directory_path)" ] ; then
|
|
|
|
echo "The running directory is not empty!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-02-14 22:26:48 +01:00
|
|
|
source ../variables.conf
|
2022-04-18 12:09:22 +02:00
|
|
|
repo_db_file=$repo_name.db.tar
|
|
|
|
repo_db_filesfile=$repo_name.files.tar
|
|
|
|
awk_rules_file='../parser.awk'
|
2022-02-14 22:26:48 +01:00
|
|
|
eval "$(ssh-agent)"
|
|
|
|
ssh-add $ssh_key
|
|
|
|
|
2022-02-13 12:18:26 +01:00
|
|
|
# TODO Check if required packages are installed
|
|
|
|
|
|
|
|
echo "ArchRepo update script"
|
|
|
|
}
|
|
|
|
|
|
|
|
checkUpdates() {
|
|
|
|
echo "Checking for updates:"
|
|
|
|
upgraded_packages=""
|
2022-02-14 22:26:48 +01:00
|
|
|
scp $ssh_options $remote_repository/$repo_db_file $remote_repository/$repo_db_filesfile $run_directory_path/
|
2022-02-13 15:17:55 +01:00
|
|
|
stream=$(tar xOf $run_directory_path/$repo_db_file --wildcards */desc | awk -f $awk_rules_file)
|
2022-02-13 12:18:26 +01:00
|
|
|
|
|
|
|
OIFS=$IFS
|
|
|
|
IFS='|'
|
|
|
|
stream="${stream:1}"
|
|
|
|
for package in $stream
|
|
|
|
do
|
|
|
|
IFS='
|
|
|
|
'
|
|
|
|
count=0
|
|
|
|
for line in $package; do
|
|
|
|
if [ $count -eq 0 ]; then
|
|
|
|
filename=$line
|
|
|
|
elif [ $count -eq 1 ]; then
|
|
|
|
name=$line
|
|
|
|
elif [ $count -eq 2 ]; then
|
|
|
|
version=$line
|
|
|
|
fi
|
|
|
|
|
|
|
|
((count++))
|
|
|
|
done
|
|
|
|
|
|
|
|
reg="(linux-lts).+-((docs)|(headers))"
|
|
|
|
if [[ $name =~ $reg ]]; then
|
|
|
|
echo -e "\nSkipping $name ($version, default exception)."
|
|
|
|
continue 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if echo $exlist | grep -w $name > /dev/null; then
|
|
|
|
echo -e "\nSkipping $name ($version, temporary exception)."
|
|
|
|
continue 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo -e "\nChecking $name ($version)..."
|
|
|
|
aur_version=$(package-query -A -f %v $name)
|
|
|
|
|
|
|
|
vercomp $aur_version $version
|
|
|
|
result=$?
|
|
|
|
if [[ $result -eq 1 ]]; then
|
|
|
|
echo "New version for $name: $version -> $aur_version"
|
2022-02-14 22:26:48 +01:00
|
|
|
IFS=$OIFS
|
2022-02-13 12:18:26 +01:00
|
|
|
createPackage $name
|
|
|
|
addPackageToRepo $name $aur_version
|
|
|
|
upgraded_packages="$upgraded_packages $name"
|
|
|
|
fi
|
|
|
|
|
|
|
|
IFS='|'
|
|
|
|
done
|
|
|
|
IFS=$OIFS
|
|
|
|
echo "All packages processed."
|
|
|
|
|
|
|
|
if [[ $upgraded_packages != "" ]]; then
|
|
|
|
echo "The following packages were upgraded:"
|
|
|
|
echo $upgraded_packages
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
addPackage() {
|
2022-04-18 12:19:50 +02:00
|
|
|
scp $ssh_options $remote_repository/$repo_db_file $remote_repository/$repo_db_filesfile $run_directory_path/
|
2022-02-13 12:18:26 +01:00
|
|
|
createPackage $1
|
|
|
|
addPackageToRepo $1
|
|
|
|
}
|
|
|
|
|
|
|
|
createPackage() { # Create package $1
|
|
|
|
echo "Fetching $1 from AUR..."
|
|
|
|
aur fetch $1 # TODO This could be replaced by a git clone or even a wget+tar thanks to package-query
|
|
|
|
echo "Making $1 package..."
|
|
|
|
cd $1
|
|
|
|
makepkg -s --noconfirm --noprogressbar
|
|
|
|
cd $run_directory_path
|
|
|
|
}
|
|
|
|
|
2022-02-13 15:17:55 +01:00
|
|
|
# TODO: try manually: can we update db file before sending to remote repo?
|
2022-02-13 12:18:26 +01:00
|
|
|
addPackageToRepo() { # Add package $1
|
|
|
|
echo "Adding $1 to repository..."
|
2022-02-14 22:26:48 +01:00
|
|
|
scp $ssh_options $run_directory_path/$1/$1-$2*.pkg.tar.xz $remote_repository/
|
|
|
|
repo-add $repo_db_file $run_directory_path/$1/$1-$2*.pkg.tar.xz
|
|
|
|
scp $ssh_options $run_directory_path/$repo_db_file $run_directory_path/$repo_db_file.old $run_directory_path/$repo_db_filesfile $run_directory_path/$repo_db_filesfile.old $remote_repository/
|
2022-02-13 12:18:26 +01:00
|
|
|
reg="(linux-lts).+"
|
|
|
|
if [[ $name =~ $reg ]]; then
|
|
|
|
echo "Adding $1-headers and $1-docs to repository..."
|
2022-02-14 22:26:48 +01:00
|
|
|
repo-add $repo_db_file $run_directory_path/$1/$1-headers-$2*.pkg.tar.xz $run_directory_path/$1/$1-docs-$2*.pkg.tar.xz
|
|
|
|
scp $ssh_options $run_directory_path/$1/$1-headers-$2*.pkg.tar.xz $run_directory_path/$1/$1-docs-$2*.pkg.tar.xz $remote_repository/
|
2022-02-13 12:18:26 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
clean() {
|
|
|
|
echo "Cleaning directory..."
|
|
|
|
rm -rf $run_directory_path/*
|
|
|
|
echo "Done."
|
|
|
|
}
|
|
|
|
|
|
|
|
run_directory_path=$(pwd)
|
|
|
|
|
|
|
|
# Main process
|
|
|
|
|
|
|
|
if [ "$1" = "" ]; then
|
|
|
|
init
|
|
|
|
checkUpdates
|
|
|
|
elif [ "$1" = "add" ]; then
|
|
|
|
init
|
|
|
|
addPackage $2
|
|
|
|
elif [ "$1" = "clean" ]; then
|
|
|
|
clean
|
|
|
|
else
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit 0
|