121 lines
		
	
	
	
		
			2.9 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
			
		
		
	
	
			121 lines
		
	
	
	
		
			2.9 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
| #!/bin/zsh
 | |
| #dep:xi xbps-checkvers ag
 | |
| 
 | |
| source ${$(realpath "$0"):h:h}/lib/common.zsh
 | |
| 
 | |
| alternative-noparam column cat
 | |
| 
 | |
| PACKAGES_DIR=${VOID_PACKAGES_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/void-packages}
 | |
| if [[ ! -d $PACKAGES_DIR ]]; then
 | |
| 	#fallback to location also used by xbps-checkvers
 | |
| 	PACKAGES_DIR=$HOME/void-packages
 | |
| fi
 | |
| if [[ ! -d $PACKAGES_DIR ]]; then
 | |
|  	<<-ERR
 | |
| 	void-packages repo not found. Either set VOID_PACKAGES_DIR or place it at one of the 
 | |
| 	following locations:
 | |
| 	  - ${XDG_DATA_HOME:-$HOME/.local/share}/void-packages
 | |
| 	  - $HOME/void-packages
 | |
| 	ERR
 | |
| 	exit 1
 | |
| fi
 | |
| 
 | |
| zparseopts -D -E h=help -help=help j:=jobs -jobs:=jobs b:=branch -branch:=branch y=yes -yes=yes
 | |
| 
 | |
| if [[ $yes ]]; then echo "auto mode: $yes"; fi
 | |
| 
 | |
| if [[ $help ]]; then
 | |
| 	<<-HELP
 | |
| 	Usage: xrestricted list
 | |
| 	       xrestricted update
 | |
| 	       xrestricted install <PACKAGE...>
 | |
| 	
 | |
| 	Install restricted packages from a void source repo.  Detected repo at:
 | |
| 	  $VOID_PACKAGES_DIR
 | |
| 	
 | |
| 	Common options:
 | |
| 		-j, --jobs N     Number of jobs to use
 | |
| 		-b, --branch B   Use given branch instead of master
 | |
| 	HELP
 | |
| 	exit
 | |
| fi
 | |
| 
 | |
| if [[ ! $jobs ]]; then
 | |
| 	jobs=$(nproc)
 | |
| fi
 | |
| 
 | |
| cd $PACKAGES_DIR
 | |
| 
 | |
| branch=${branch[2]:-master}
 | |
| check "Checking git branch..."
 | |
| if [[ $(git rev-parse --abbrev-ref HEAD) != $branch ]]; then
 | |
| 	if ! git diff --quiet; then
 | |
| 		fail "not on $branch and working directory dirty, please fix manually"
 | |
| 		exit 1
 | |
| 	else
 | |
| 		warn "not on $branch"
 | |
| 		check "checking out $branch ..."
 | |
| 		output=$(git checkout $branch 2>&1)
 | |
| 		[[ $? == 0 ]] && succeed || { fail $output && exit 1 }
 | |
| 	fi
 | |
| else
 | |
| 	succeed "on $branch"
 | |
| fi
 | |
| 
 | |
| packages=( $(ag -G 'template' restricted=yes srcpkgs/ | cut -d/ -f 2 | sort -u) )
 | |
| 
 | |
| version() { grep -Poe '(?<=^version=).*$' srcpkgs/$1/template }
 | |
| install_restricted() {
 | |
| 	local existing=( hostdir/binpkgs/nonfree/$1-$2*(N) )
 | |
| 	if [[ -z $2 || -z $existing ]]; then
 | |
| 		./xbps-src pkg -j $jobs $1
 | |
| 	else
 | |
| 		echo "Package already built for version $2 ($existing), installing..."
 | |
| 	fi
 | |
| 	xi $yes $1
 | |
| }
 | |
| 
 | |
| case $1 in
 | |
| 	""|"list")
 | |
| 		zparseopts -D -E v=verbose -verbose=verbose -versions=verbose
 | |
| 		if [[ $verbose ]]; then
 | |
| 			for pkg in $packages; do
 | |
| 				printf "%s\t%s\n" $pkg $(version $pkg)
 | |
| 			done | column -t
 | |
| 		else
 | |
| 			printf "%s\n" $packages
 | |
| 		fi
 | |
| 		;;
 | |
| 	"update")
 | |
| 		check "Updating package dir..."
 | |
| 		git --git-dir=$PACKAGES_DIR/.git --work-tree=$PACKAGES_DIR/ pull &>/dev/null\
 | |
| 			&& succeed || { fail && exit 1 }
 | |
| 		possible_updates=$(
 | |
| 			xbps-checkvers -I -D $PACKAGES_DIR -m $packages |
 | |
| 				awk '$2 != "?" { print }'
 | |
| 			)
 | |
| 
 | |
| 		if [[ -z $possible_updates ]]; then
 | |
| 			echo "All up to date"
 | |
| 			exit 0
 | |
| 		fi
 | |
| 
 | |
| 		awk '{ printf "\x1b[34m%s\x1b[0m: %s →  \x1b[92m%s\x1b[0m\n", $1, $2, $3 }' <<<"$possible_updates"
 | |
| 		[[ -z $yes ]] && printf "Run updates? [y/N] "
 | |
| 		if [[ $yes ]] || read -q; then
 | |
| 			echo
 | |
| 			for pkg ver in $(cut -d' ' -f 1,3 <<<"$possible_updates"); do
 | |
| 				install_restricted $pkg $ver
 | |
| 			done
 | |
| 		else
 | |
| 			echo
 | |
| 		fi
 | |
| 		;;
 | |
| 	"install")
 | |
| 		shift
 | |
| 		for i in $@; install_restricted $i
 | |
| 		;;
 | |
| 	*)
 | |
| 		for i in $@; install_restricted $i
 | |
| 		;;
 | |
| esac
 | 
