1. Jack Frost
  2. misc

Commits

Jack Frost  committed 85b567d

Enter zpm (zero package manager), a replacement for aur

  • Participants
  • Parent commits 59d14a0
  • Branches master

Comments (0)

Files changed (2)

File aur

  • Ignore whitespace
-#!/usr/bin/env bash
-
-## config
-[[ -e "$HOME/.config/aur.rc" ]] && {
-	source "$HOME/.config/aur.rc"
-}
-
-cfg_work_dir="${cfg_work_dir:-$HOME/.aur}"
-cfg_aur_url="${cfg_aur_url:-https://aur.archlinux.org}"
-cfg_abs_tree="${cfg_abs_tree:-/var/abs}"
-cfg_makepkg_flags='-rs'
-cfg_libfbt_path="${cfg_libfbt_path:-/usr/lib/libfbt}"
-# /config
-
-[[ -e "$cfg_libfbt_path" ]] || {
-	echo "This script depends on libfbt: https://github.com/fbt/libfbt"
-	exit 1
-}
-
-source "${cfg_libfbt_path}/libfbt.sh"
-
-aur.usage() {
-	echo "$0 [options] [packages]"
-
-	echo "SYNC (-S):"
-	echo "-s|--search			# search"
-	echo "-d|--download-only	# download only"
-	echo "-u|--upgrade			# upgrade"
-	echo "-y|--update			# update ABS"
-	echo
-	echo "OTHER:"
-	echo "-a|--aur-only			# AUR only"
-	echo "-h|--help				# show this message"
-}
-
-aur.args() {
-	while [[ "$1" ]]; do
-		case "$1" in
-			-a|--aur-only) flag_aur_only='1';;
-			-S|--sync) action_group='sync';;
-			-s|--search) action='search';;
-			-u|--upgrade) flag_upgrade='1';;
-			-y|--update) flag_update='1';;
-
-			-w|--download-only) flag_download_only='1';;
-			-b|--build) flag_build='1';;
-			-N|--noconfirm) flag_noconfirm='1';;
-			-D|--asdeps) flag_asdeps='1';;
-			-h|--help) aur.usage; exit;;
-			--) :;;
-			*) args+=( "$1" );;
-		esac
-		shift
-	done
-}
-
-aur.get_package() {
-#	local package_repo
-	[[ "$flag_aur_only" ]] && {
-		package_repo="`package-query --aur-url "$cfg_aur_url" -A "$1" | head -1 | cut -d '/' -f1`"
-	} || {
-		package_repo="`package-query --aur-url "$cfg_aur_url" -AS "$1" | head -1 | cut -d '/' -f1`"
-	}
-
-	[[ "$package_repo" ]] || {
-		lf.err "Package $1 not found!\n"
-		return 1
-	}
-
-	cd "$cfg_work_dir"
-
-	case "${package_repo}" in
-		aur)	
-			lf.msg "Downloading $cfg_aur_url/packages/${1:0:2}/${1}/${1}.tar.gz\n"
-			curl "$cfg_aur_url/packages/${1:0:2}/${1}/${1}.tar.gz" | gzip -d | tar xf - || {
-				lf.err "Fail!\n"
-				return 3
-			}
-		;;
-
-		*)
-			[[ "$flag_build" ]] && {
-				cp -r "${cfg_abs_tree}/${package_repo}/${1}" . || {
-					lf.err "Fail!\n"
-					return 9
-				}
-			} || {
-				[[ "$flag_download_only" ]] && {
-					sudo pacman --cachedir "`pwd`" -Sw "$1"
-				}
-			}
-		;;
-	esac
-
-	return 0
-}
-
-aur.update_local_db() {
-	lf.msg "Updating ABS...\n"
-	sudo abs >/dev/null || { lf.msg 'Fail!\n'; return 1; }
-
-	sudo pacman -Sy || { return 1; }
-}
-
-aur.upgrade() {
-	local old_pkgs
-	old_pkgs=( `package-query -Au | cut -d ' ' -f1` )
-
-	[[ "$flag_aur_only" ]] || { sudo pacman -Su; }
-
-	lf.msg "Updating packages from AUR...\n"
-
-	[[ "$old_pkgs" ]] || {
-		lf.msg "Everything seems to be up to date.\n"
-		return 0
-	}
-
-	lf.msg "Packages that need updates: ${old_pkgs[*]}\n"
-	read -n1 -p "Proceed? [Y/n] " answer
-	[[ "$answer" == 'y' ]] || [[ "$answer" ]] && {
-		echo
-		lf.msg 'Ok.\n'
-		return 1
-	}
-
-	for i in "${old_pkgs[@]}"; do
-		"$BASH" "$0" -NS "$i" || {
-			failed_pkgs+=( "$i" )
-		}
-	done
-
-	[[ "$failed_pkgs" ]] && {
-		lf.msg "Failed to upgrade the following pacages: ${failed_pkgs[*]}\n"
-		return 1
-	}
-
-	return 0
-}
-
-aur.build_package() {
-	local aur_deps
-
-	cd "$cfg_work_dir/$package"
-	[[ "$flag_build" ]] || { cfg_makepkg_flags+=' -i'; }
-	[[ "$flag_noconfirm" ]] && { cfg_makepkg_flags+=' --noconfirm'; }
-
-	source PKGBUILD
-
-	for i in "${depends[@]}"; do
-		package-query --aur-url "$cfg_aur_url" -A "$i" && {
-			lf.msg "$package depends on $i, installing it\n"
-			"$BASH" "$0" -aNS --asdeps "$i"
-		}
-	done
-
-	makepkg ${cfg_makepkg_flags}
-}
-
-aur.search() {
-	[[ "$flag_aur_only" ]] && {
-		package-query --aur-url "$cfg_aur_url" -As "$1"
-	} || {
-		package-query --aur-url "$cfg_aur_url" -ASs "$1"
-	}
-}
-
-aur.init() {
-	for i in "$cfg_work_dir"; do
-		[[ -e "$i" ]] || {
-			mkdir -p "$i" || {
-				lf.msg "Cannot create $i!\n"
-				return 1
-			}
-		}
-	done
-}
-
-aur.main() {
-	aur.init || { return 1; }
-	aur.args `lf.getopt "$@"` || { return 1; }
-
-	package="${args[0]##*/}"
-
-	case "$action_group" in
-		sync)
-			action="${action:-build}"
-
-			[[ "$flag_update" ]] && { aur.update_local_db; }
-			[[ "$flag_upgrade" ]] && { aur.upgrade; }
-
-			[[ "$package" ]] && {
-				case "$action" in
-					search) aur.search "$package" || { return "$?"; };;
-					build)
-						aur.get_package "$package" || { return "$?"; }
-
-						[[ "$flag_download_only" ]] || {
-							case "$package_repo" in	
-								aur)
-									aur.build_package || { return "$?"; }
-								;;
-
-								*)
-									[[ "$flag_build" ]] && {
-										aur.build_package || { return "$?"; }
-									} || {
-										sudo pacman -S "$package"
-									}
-								;;
-							esac
-						}
-					;;
-				esac
-			}
-		;;
-
-		*) sudo pacman "$@";;
-	esac
-}
-
-aur.main "$@"

File zpm

View file
  • Ignore whitespace
+#!/usr/bin/env bash
+
+## config
+[[ -e "$HOME/.config/zpm.rc" ]] && {
+	source "$HOME/.config/zpm.rc"
+}
+
+cfg_work_dir="${cfg_work_dir:-$HOME/.zpm}"
+cfg_aur_url="${cfg_aur_url:-https://aur.archlinux.org}"
+cfg_abs_tree="${cfg_abs_tree:-/var/abs}"
+cfg_makepkg_flags='-rs'
+cfg_libfbt_path="${cfg_libfbt_path:-/usr/lib/libfbt}"
+# /config
+
+[[ -e "$cfg_libfbt_path" ]] || {
+	echo "This script depends on libfbt: https://github.com/fbt/libfbt"
+	exit 1
+}
+
+source "${cfg_libfbt_path}/libfbt.sh"
+
+zpm.usage() {
+cat << EOF
+$0 is an AUR, ABS and pacman wrapper
+Usage: $0 <flags> [packages]
+Flags:
+	-S|--sync			# Synchronize packages.
+		-s|--search		# Search for packages.
+		-y|--update		# Update the local database.
+		-u|--upgrade	# Upgrade packages.
+
+		These only work with AUR/ABS packages:
+		-w				# Download the package, don't do anything with it.
+		-b				# Build the package, don't install.
+
+	-A|--aur-only		# Only upgrade AUR packages.
+	-a|--abs			# Build packages from ABS instead of installing them with pacman.
+	
+	-h|--help			# Show this message.
+EOF
+}
+
+zpm.args() {
+	while [[ "$1" ]]; do
+		case "$1" in
+			-A|--aur-only) flag_aur_only='1';;
+			-a|--abs) flag_abs='1';;
+
+			-S|--sync) action_group='sync';;
+			-s|--search) action='search';;
+			-y|--update) flag_update='1';;
+			-u|--upgrade) flag_upgrade='1';;
+			-w|--dowload-only) flag_download_only='1';;
+			-b|--build-only) flag_build_only='1';;
+
+			-h|--help) zpm.usage; exit;;
+			--) :;;
+			*) args+=( "$1" );;
+		esac
+		shift
+	done
+}
+
+# ABS-related functions
+zpm.abs::update() { sudo abs; }
+zpm.abs::upgrade() {
+	local updated_packages
+
+	lf.msg "Upgrading packages from ABS...\n"
+
+	updated_packages=( `pacman -Qeu | cut -d ' ' -f1` )
+
+	[[ "$updated_packages" ]] || {
+		lf.msg "Everything seems to be up to date.\n"
+		return 0
+	}
+
+	lf.msg "Packages that need updates: ${updated_packages[*]}\n"
+	read -n1 -p "Proceed? [Y/n] " answer
+	[[ "$answer" == 'y' ]] || [[ "$answer" ]] && {
+		echo
+		lf.msg 'Ok.\n'
+		return 0
+	}
+
+	for i in "${updated_packages[@]}"; do
+		zpm.abs::get "$i" || return "$?"
+		zpm.build "$i"
+	done
+}
+
+zpm.abs::get() {
+	local package_abs_path=`find /var/abs -name "$1"`
+
+	[[ "$package_abs_path" ]] || {
+		lf.err "Can't find package $1 in ABS.\n"
+		return 1
+	}
+
+	cp -r "$package_abs_path" "$cfg_work_dir"
+}
+
+# AUR-related functions
+zpm.aur::get() {
+	cd "$cfg_work_dir"
+
+	lf.msg "Downloading $cfg_aur_url/packages/${1:0:2}/${1}/${1}.tar.gz\n"
+	curl "$cfg_aur_url/packages/${1:0:2}/${1}/${1}.tar.gz" | gzip -d | tar xf - || {
+		lf.err "Fail!\n"
+		return 1
+	}
+}
+
+zpm.aur::upgrade() {
+	local updated_packages package_name
+
+	lf.msg "Upgrading packages from AUR...\n"
+
+	updated_packages=( `package-query -Au | cut -d ' ' -f1` )
+
+	[[ "$updated_packages" ]] || {
+		lf.msg "Everything seems to be up to date.\n"
+		return 0
+	}
+
+	lf.msg "Packages that need updates: ${updated_packages[*]}\n"
+	read -n1 -p "Proceed? [Y/n] " answer
+	[[ "$answer" == 'y' ]] || [[ "$answer" ]] && {
+		echo
+		lf.msg 'Ok.\n'
+		return 0
+	}
+
+	for i in "${updated_packages[@]}"; do
+		package_name="${i##*/}"
+
+		zpm.aur::get "$package_name" || return "$?"
+		zpm.build "$package_name"
+	done
+}
+
+# pacman-related functions
+zpm.pacman::update() { sudo pacman -Sy; }
+zpm.pacman::upgrade() { sudo pacman -Su; }
+
+# Common functions
+zpm.build() {
+	cd "$cfg_work_dir/$1"
+	
+	[[ "$flag_build_only" ]] || { cfg_makepkg_flags+=' -i'; }
+
+	makepkg ${cfg_makepkg_flags}
+}
+
+zpm.update() {
+	zpm.abs::update
+	zpm.pacman::update
+}
+
+zpm.upgrade() {
+	[[ "$flag_aur_only" ]] || {
+		[[ "$flag_abs" ]] && { zpm.abs::upgrade; }
+		[[ "$flag_abs" ]] || { zpm.pacman::upgrade; }
+	}
+
+	[[ "$flag_no_aur" ]] || { zpm.aur::upgrade; }
+}
+
+zpm.search() {
+	[[ "$flag_aur_only" ]] && {
+		package-query --aur-url "$cfg_aur_url" -As "$1" || return 1
+	} || {
+		package-query --aur-url "$cfg_aur_url" -ASs "$1" || return 1
+	}
+}
+
+zpm.main() {
+	local packages
+
+	zpm.args `lf.getopt "$@"` || { return 1; }
+	packages="${args[@]}"
+
+	case "$action_group" in
+		sync)
+			[[ "$flag_update" ]] && { zpm.update; }
+			[[ "$flag_upgrade" ]] && { zpm.upgrade; }
+
+			action="${action:-build}"
+
+			[[ "$packages" ]] || { return 0; }
+
+			case "$action" in
+				search)
+					for i in "${packages[@]}"; do
+						zpm.search "$i"
+					done
+				;;
+
+				build)
+					for i in "${packages[@]}"; do
+						package_repo="`package-query --aur-url "$cfg_aur_url" -AS "$i" | head -1 | cut -d '/' -f1`"
+
+						[[ "$package_repo" ]] || {
+							lf.err "Package $i not found.\n"
+							return 1
+						}
+
+						case "$package_repo" in
+							aur)
+								zpm.aur::get "$i" || return "$?"
+								[[ "$flag_download_only" ]] || { zpm.build "$i"; }
+							;;
+
+							*)
+								[[ "$flag_abs" ]] && {
+									zpm.abs::get "$i" || return "$?"
+									zpm.build "$i"
+									return "$?"
+								} || {
+									sudo pacman -S "$i"
+								}
+							;;
+						esac
+					done
+				;;
+			esac
+		;;
+
+		*) sudo pacman "$@";;
+	esac
+}
+
+zpm.main "$@"