Generic-Mass-Compilation-PK.../clone.sh

137 lines
4.7 KiB
Bash

#!/bin/bash
#set -x
### Color Codes
RED="\e[31m"
GREEN="\e[32m"
ENDCOLOR="\e[0m"
#find . -not -name "packages.txt" -not -name "clone.sh" -not -name "." -exec rm -rfv {} \;
working_directory=$(pwd)
mkdir $working_directory/built_packages/
mkdir $working_directory/clone/
function statisfy_dependencies() {
for line in "$@"; do
cd $working_directory/clone
# clone all the packages first
echo "Attempting to clone $line..."
if ! [ -d $line ]; then
timeout 10s git clone https://gitlab.archlinux.org/archlinux/packaging/packages/$line.git
cd $working_directory/clone/$line
git switch main
#git branch -a
else
cd $working_directory/clone/$line
# git pull
# git switch main
fi
done
cd $working_directory
}
function containsElement () {
local e match="$1"
shift
for e in "$@"; do
[[ "$e" == "$match" ]] && return 0; done
return 1
}
readarray first_pass < packages.txt
echo $first_pass
statisfy_dependencies ${first_pass[@]}
depends_array=()
makedepends_array=()
conflicts_array=()
while read line; do
# Check each PKGBUILD's dependencies.
cd $working_directory/clone/$line
# grab depends array
# eval $(source PKGBUILD; echo depends=$depends; echo makedepends=$makedepends; echo conflicts=$conflicts)
# cache the output of makepkg to a file, since makepkg is slow at parsing the srcinfo data
if [[ ! -f $working_directory/clone/$line/.SRCINFO ]]; then
makepkg_output=$(makepkg --printsrcinfo )
echo $makepkg_output | tee $working_directory/clone/$line/.SRCINFO
else
makepkg_output=$(cat $working_directory/clone/$line/.SRCINFO)
fi
#echo "$makepkg_output"
depends=$(echo "$makepkg_output" | grep -w "depends" | sed "s/depends = //g" | xargs)
makedepends=$(echo "$makepkg_output" | grep -w "makedepends" | sed "s/makedepends = //g" | xargs)
conflicts=$(echo "$makepkg_output" | grep -w "conflicts" | sed "s/conflicts = //g" | xargs)
# if we don't have the dependency, we need build it too
echo "depends for $line: ${depends[@]}"
for depends_element in ${depends[@]}; do
containsElement "$depends_element" "${depends_array[@]}"
if [[ $? == 1 ]]; then
echo "Adding ${depends_element}..."
depends_array+=("$depends_element")
fi
done
for depends_element in ${makedepends[@]}; do
containsElement "$depends_element" "${depends_array[@]}"
if [[ $? == 1 ]]; then
echo "Adding ${depends_element}..."
depends_array+=("$depends_element")
makedepends_array+=("$depends_element")
fi
done
for conflicts_element in ${conflicts[@]}; do
containsElement "$conflicts_element" "${conflicts_array[@]}"
if [[ $? == 1 ]]; then
echo -e "Conflicting elements for $line: ${RED} ${conflicts_element}${ENDCOLOR} ..."
conflicts_array+=("${conflicts_element}")
fi
done
done < packages.txt
cd $working_directory
# Remove these dependencies, they are already taken care of, anyway :P
#delete=(gcc-libs glibc appstream-qt futuresql-qt6 cron clang=16.0.6 boost-libs kcachegrind-common kquickimageeditor libkmahjongg marble-common libcolord corrosion flatpak colord cronie kwrite plasma-workspace kgamma5 kdesdk-kioslaves zeroconf-ioslave kalendar)
delete=(clang=17.0.6 llvm-libs appstream-qt gcc-libs futuresql-qt6 boost-libs util-linux-libs systemd-libs packagekit-qt6 polkit-qt6 sh mesa-utils mesa-utils libpipewire)
for target in "${delete[@]}"; do
for i in "${!depends_array[@]}"; do
if [[ ${depends_array[i]} = $target ]]; then
unset 'depends_array[i]'
fi
done
done
echo ${depends_array[@]}
statisfy_dependencies ${depends_array[@]}
cd $working_directory/clone
echo -e "Conflicts detected: ${RED} ${conflicts_array[@]} ${ENDCOLOR}"
#read -p "Press Enter to continue..." </dev/tty
function are_all_pkgs_built() {
for package in "$working_directory"/clone/*; do
if [ -f "$package"/*.pkg.* ]; then
return 0
fi
done
return 1
}
COUNTER = 0
while are_all_pkgs_built; do
COUNTER = 0
for i in "$working_directory"/clone/*; do
if [ ! -f "${working_directory}/built_packages/${i##*/}"*.pkg.* ]; then #Skip-built packages
echo "Attempting to build ${i##*/} ($COUNTER out of $(echo $working_directory/clone/* | wc | awk '{print $2}'))"
cd "$i"
eval "$(source PKGBUILD; echo makedepends="$makedepends")"
makepkg -ACcsi --noconfirm --nocheck --skipinteg
cp -v *.pkg.* "$working_directory"/built_packages/
else
echo "It appears that ${i##*/} is already built, skipping..."
fi
COUNTER=$((COUNTER+1))
done
done
#paru --sudoloop --useask -B *
#paru --sudoloop --mode repo --clonedir $working_directory/clone -B *
#for i in *; do
#done