bvdeenen

xbld void restricted package builder

Jul 21st, 2026
21,680
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.96 KB | Software | 0 0
  1. function xbld() {
  2.     local dir="${1:-$HOME/void-packages}"
  3.  
  4.     if [[ ! -d "$dir/srcpkgs" ]]; then
  5.         echo "Error: $dir does not look like a void-packages tree" >&2
  6.         return 1
  7.     fi
  8.     (
  9.         set -e
  10.         cd "$dir" || exit 1
  11.         git pull --rebase
  12.  
  13.         # Collect restricted package names cleanly
  14.         local pkgs
  15.         pkgs=$(
  16.             shopt -s extglob nullglob
  17.             cd srcpkgs 2>/dev/null || exit 1
  18.             grep -l '^restricted=yes' **/template 2>/dev/null |
  19.                 awk -F/ '{print $1}' |
  20.                 sort -u
  21.         )
  22.  
  23.         if [[ -z "$pkgs" ]]; then
  24.             echo "No restricted packages found." >&2
  25.             exit 0
  26.         fi
  27.  
  28.         # fzf single select with bat preview
  29.         local selection
  30.         selection=$(
  31.             echo "$pkgs" | fzf \
  32.                 --height 60% \
  33.                 --layout=reverse \
  34.                 --border \
  35.                 --prompt="Select restricted package to build+install → " \
  36.                 --header="Restricted packages in $(basename "$dir")" \
  37.                 --preview 'p={}; bat --color=always --style=numbers --line-range :500 "$PWD/srcpkgs/$p/template" ' \
  38.                 --preview-window=right:50%:wrap \
  39.                 --header='ctrl-u=check for updates' \
  40.                 --bind "ctrl-u:preview( ./xbps-src update-check {} )"
  41.         )
  42.  
  43.         if [[ -z "$selection" ]]; then
  44.             echo "Nothing selected."
  45.             exit 0
  46.         fi
  47.  
  48.         echo
  49.         echo "→ Selected: $selection"
  50.         echo "  Building and installing..."
  51.  
  52.         # Optional: clean first if you often want fresh builds
  53.         # ./xbps-src clean-restricted "$selection"  # uncomment if desired
  54.  
  55.         if ./xbps-src pkg "$selection" && command -v xi >/dev/null 2>&1; then
  56.             yes | xi "$selection"
  57.         else
  58.             echo "Build failed or 'xi' command not found." >&2
  59.             return 1
  60.         fi
  61.     )
  62.     return $?
  63. }
  64.  
Advertisement