Skip to content

Instantly share code, notes, and snippets.

@stralytic
Last active December 14, 2022 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stralytic/15e554cd61c7418a28a1e639214fcb77 to your computer and use it in GitHub Desktop.
Save stralytic/15e554cd61c7418a28a1e639214fcb77 to your computer and use it in GitHub Desktop.
archlinux makeworld / pacbuilder - rebuild entire distro
#!/usr/bin/zsh
# make the /home/repo directory and /home/repo/asp directories
# clone any git repositories for PKGBUILD into this directory
# and the script will pull changes in them and rebuild.
# for example:
# git clone git@github.com:CachyOS/CachyOS-PKGBUILDS.git
cd /home/repo/asp || exit
# update core arch PKGBUILDs
asp update
asp checkout $({ paru -Sl core; paru -Sl community; paru -Sl extra; paru -Sl multilib; } | grep "installed" | awk '{ print $2 }')
cd /home/repo || exit
# pull any git repos
find /home/repo -type d -name ".git" -execdir git reset --hard ';'
find /home/repo -type d -name ".git" -execdir git pull --rebase --autostash ';'
# change architecture
find /home/repo -name "PKGBUILD" | xargs -I {} sed -i 's/arch=(x86_64)/arch=(x86_64_v3)/' {}
find /home/repo -name "PKGBUILD" | xargs -I {} sed -i "s/arch=('x86_64')/arch=('x86_64_v3')/" {}
# grep for arch x86_64 so time isn't wasted rebuilding "any" arch packages
# twice so it only uses trunk asp builds
# as asp puts two or more PKGBUILD files under the directory for the package
# second find is for things not in the asp directory if you have things checked out from git
# shuf is used here to randomize the order things build
# so if the script dies for some reason it won't start at the beginning and die at the same place
for x in $(
{
grep -El "arch=\('?x86_64" /home/repo/**/PKGBUILD | grep "asp.*trunk";
grep -El "arch=\('?x86_64" /home/repo/**/PKGBUILD | grep -v "asp";
} | shuf)
do
d=$(dirname $x)
cd $d
pwd
# yes 1 will choose the first option when pacman asks which package will fulfill dependency
yes 1 | makepkg -Ascr --noconfirm
done
# makepkg line below required for packages to be deposited here
cd /home/packages/
rm custom.*
# clean up old packages
repo-add ./custom.db.tar.gz ./*.tar.zst 2>&1 | grep -B 1 "A newer version" | grep "Adding package" | awk -F "'" '{ print $2 }' | xargs rm
rm custom.*
# build new package db
repo-add custom.db.tar.gz *.tar.zst
# add below to put packages in the directory which above uses
PKGDEST=/home/packages
# I also recommend the below to keep stuff nicely separated
BUILDDIR=/home/tmp
SRCDEST=/home/sources
# I keep /home/tmp on SSD, and packages and sources on a big hard disk
# add below to have pacman use built packages
[custom]
SigLevel = Optional
Server = file:///home/packages
# below snippet will clone all the garuda PKGBUILDs if you want to rebuild them...
for repo in $(curl -s --header "PRIVATE-TOKEN: [INSERT YOUR TOKEN HERE]" "https://gitlab.com/api/v4/groups/11326526?include_subgroups=true" | jq -r ".projects[].ssh_url_to_repo"); do git clone $repo; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment