~hnaguski/xmetagen

bf49861d18a094b89fbd998026424ddddb1cfd40 — Henry Naguski 9 months ago ff6a798
rename xim to xir, and add xim which installs metapackages from repo, add xrmm to remove metapackges easily
9 files changed, 112 insertions(+), 86 deletions(-)

M Makefile
M README
M _xmetagen
M xim
A xir
M xmeta
M xqm
A xrmm
M xrsm
M Makefile => Makefile +5 -1
@@ 1,4 1,4 @@
# xim
# xmetagen
PREFIX=/usr/local

install:


@@ 6,6 6,8 @@ install:
	install -D xmeta "$(PREFIX)/bin/xmeta"
	install -D xrsm "$(PREFIX)/bin/xrsm"
	install -D xqm "$(PREFIX)/bin/xqm"
	install -D xrmm "$(PREFIX)/bin/xrmm"
	install -D xir "$(PREFIX)/bin/xir"
	install -Dm 644 _xmetagen "$(PREFIX)/share/zsh/site-functions/_xmetagen"

uninstall:


@@ 13,4 15,6 @@ uninstall:
	rm "$(PREFIX)/bin/xmeta"
	rm "$(PREFIX)/bin/xrsm"
	rm "$(PREFIX)/bin/xqm"
	rm "$(PREFIX)/bin/xrmm"
	rm "$(PREFIX)/bin/xir"
	rm "$(PREFIX)/share/zsh/site-functions/_xmetagen"

M README => README +17 -11
@@ 14,21 14,27 @@ xmeta [-r] [-d DESC] [-v VERSION] METAPACKAGE DEPENDENCIES...
	-d DESC to set a description for the metapackage.
	-v VERSION to set a version to the metapackage (version is 1 by default).

xqm METAPACKAGE
xrsm METAPACKAGE
	xqm and xrsm are used to get information about specific packages in the
	XMETA_REPODIR repository. They behave similarly to xtools' xq and xrs, (and
	by extension xbps-query) but only operate on the single repository.

xim [-m MESSAGE] PACKAGES...
	xim is a wrapper for xtools' xi, which adds the -m option to add a message
	for installation to the XIM_HISTORY file (by default this is in your
	documents directory, but can be set manually).

To store xmeta's local repository somewhere else, set XMETA_REPODIR. By default
it will be stored in "$XDG_DATA_HOME/xmeta". If XDG_DATA_HOME is unset,
"$HOME/.local/share/xmeta" is used.

xim METAPACKAGE
xqm METAPACKAGE
xrsm METAPACKAGE
	xim, xqm, and xrsm are used to get information about specific packages in
	the XMETA_REPODIR repository. They behave similarly to xtools' xim, xq, and
	xrs, (and by extension xbps-install and xbps-query) but only operate on the
	single repository.

xrmm PACKAGE
	This just runs sudo xbps-remove -r. I did write some completions for it to
	make it easy to use with metapackages from xmeta.

xir [-m MESSAGE] PACKAGES...
	xir is a wrapper for xtools' xi, which adds the -m option to add a message
	for installation to the XIR_HISTORY file (by default this is in your
	documents directory, but can be set manually).

what?
-----


M _xmetagen => _xmetagen +17 -6
@@ 1,35 1,46 @@
#compdef xim xmeta xqm
#compdef xir xmeta xqm xrmm xim

_xbps

_xtoolsm_avaliable_packages() {
_xmetagen_avaliable_packages() {
	compadd "$@" -- ${${${(f)"$(xbps-query --ignore-conf-repos --repository="${XMETA_REPODIR:-${XDG_DATA_HOME:-$HOME/.local/share}/xmeta}" -Rs '')"}#??? }%%-[^- ]# *}
}

_xim() {
_xir() {
	_arguments : \
		-m'[add message for installation]:message' \
		'*:package:_xbps_all_packages'
}

_xim() {
	_arguments : \
		'*:package:_xmetagen_avaliable_packages'
}

_xmeta() {
	_arguments : \
		-d'[set description of metapackage]' \
		-v'[specify version for meta package]' \
		-r'[use manual assignment of dependency version]' \
		'*:package:_xbps_all_packages'
}

_xqm() {
	_arguments : \
		'*:package:_xtoolsm_avaliable_packages'
		'*:package:_xmetagen_avaliable_packages'
}

_xrmm() {
	_arguments : \
		'*:package:_xmetagen_avaliable_packages'
}

_xmetagen() {
	case "$service" in
		xim) _xim "$@";;
		xir) _xir "$@";;
		xmeta) _xmeta "$@";;
		xqm) _xqm "$@";;
		xrmm) _xrmm "$@";;
		xim) _xim "$@";;
	esac
}


M xim => xim +2 -44
@@ 1,46 1,4 @@
#!/bin/sh
# xim is a wrapper for xtools' xi. If you give it the -m option it will add a
# message as to why you installed the package to the XIM_HISTORY file (by
# default, the file is located in your documents folder)
# xim is similar to xtools' xi but only uses the XMETA_REPODIR repository

XIM_HISTORY=${XIM_HISTORY:-"$(xdg-user-dir DOCUMENTS)/xim.txt"}

usage() {
	progname=${0%${0##*[!/]}}
	progname=${progname##*/}
	printf 'usage: %s [-m MESSAGE] packages\n' "$progname"
	exit "$1"
}

while getopts m: option; do
	case $option in
	m)
		message="$OPTARG"
		;;
	?)
		usage 2
		;;
	esac
done
shift $((OPTIND - 1))

# don't do anything if nothing is to be installed
[ -z "$*" ] && usage 1

# create XIM_HISTORY if it doesn't exist
[ -e "$XIM_HISTORY" ] || touch "$XIM_HISTORY"

# for some reason if you try to let xi handle privledge escalation the exit
# code is always 0, so xim is hardcoded to use sudo
if sudo xi "$@"; then
	[ -z "$message" ] && exit 0 # if there's no message just end here
	for package in "$@"; do
		if grep "$package:" "$XIM_HISTORY" 1>/dev/null; then
			sed -i "/^$package:/ s/$/, $message/" "$XIM_HISTORY"
		else
			printf '%s: %s\n' "$package" "$message" >>"$XIM_HISTORY"
		fi
	done
	sort -o "$XIM_HISTORY" "$XIM_HISTORY" # sort history file
	printf 'reason to install "%s": %s\n' "$*" "$message"
fi
sudo xbps-install --ignore-conf-repos --repository="${XMETA:-${XDG_DATA_HOME:-$HOME/.local/share}/xmeta}" "$@"

A xir => xir +46 -0
@@ 0,0 1,46 @@
#!/bin/sh
# xir is a wrapper for xtools' xi. If you give it the -m option it will add a
# message as to why you installed the package to the XIR_HISTORY file (by
# default, the file is located in your documents folder)

XIR_HISTORY=${XIR_HISTORY:-"$(xdg-user-dir DOCUMENTS)/xir.txt"}

usage() {
	progname=${0%${0##*[!/]}}
	progname=${progname##*/}
	printf 'usage: %s [-m MESSAGE] packages\n' "$progname"
	exit "$1"
}

while getopts m: option; do
	case $option in
	m)
		message="$OPTARG"
		;;
	?)
		usage 2
		;;
	esac
done
shift $((OPTIND - 1))

# don't do anything if nothing is to be installed
[ -z "$*" ] && usage 1

# create XIR_HISTORY if it doesn't exist
[ -e "$XIR_HISTORY" ] || touch "$XIR_HISTORY"

# for some reason if you try to let xi handle privledge escalation the exit
# code is always 0, so xir is hardcoded to use sudo
if sudo xi "$@"; then
	[ -z "$message" ] && exit 0 # if there's no message just end here
	for package in "$@"; do
		if grep "$package:" "$XIR_HISTORY" 1>/dev/null; then
			sed -i "/^$package:/ s/$/, $message/" "$XIR_HISTORY"
		else
			printf '%s: %s\n' "$package" "$message" >>"$XIR_HISTORY"
		fi
	done
	sort -o "$XIR_HISTORY" "$XIR_HISTORY" # sort history file
	printf 'reason to install "%s": %s\n' "$*" "$message"
fi

M xmeta => xmeta +19 -22
@@ 7,32 7,34 @@ XMETA_REPODIR="${XMETA_REPODIR:-${XDG_DATA_HOME:-$HOME/.local/share}/xmeta}"
usage() {
	progname=${0%${0##*[!/]}}
	progname=${progname##*/}
	printf 'usage: %s [-r] [-d DESC] [-v VERSION] METAPACKAGE DEPENDENCIES...\n\n' "$progname"
	printf 'usage: %s [-d DESC] [-v VERSION] METAPACKAGE DEPENDENCIES...\n\n' "$progname"
	printf 'OPTIONS\n'
	printf ' -d [DESC]  	set description of metapackage\n'
	printf ' -v	[VERSION]	set version of metapackage\n'
	printf ' -r				use manual assignment of dependency version\n'
	exit "$1"
}

# parse dependencies to add >=0 for the version if -r was given, maybe figure
# out a way to detect if a version is supplied without and only add >=0 if a
# package doesn't get one?
parse() {
	pkgname="$1"
	shift 1
	if [ -z "$manual_version" ]; then
		# Add >=0 to each dependency, otherwise xbps-install doesn't know what
		# to do. Do want to glob this, to allow quoting all the dependencies
		# for ease of use, and dependency names probably don't have more than 1
		# word anyway
		# shellcheck disable=SC2068
		for arg in $@; do
	# globbing is desired, to allow quoting the list of dependencies
	# shellcheck disable=SC2068
	for arg in $@; do
		case "$arg" in
		*\>*)
			deps="${deps}${arg} "
			continue
			;;
		*\<*)
			deps="${deps}${arg} "
			continue
			;;
		*)
			# add >=0 to each arg that doesn't have manually assigned version.
			deps="${deps}${arg}>=0 "
		done
	else
		deps="$*"
	fi
			;;
		esac
	done
}

# create a package and add it to the local repository


@@ 60,9 62,6 @@ while getopts rd:v: option; do
	v)
		version="$OPTARG"
		;;
	r)
		manual_version=1
		;;
	?)
		usage 2
		;;


@@ 77,6 76,4 @@ shift $((OPTIND - 1))
desc="${desc:-"package generated by xmeta"}"
version=${version:-"1"}

parse "$@"
create
install
parse "$@" && create && install

M xqm => xqm +1 -1
@@ 1,4 1,4 @@
#!/bin/sh
# xqm is similar to xtools' xq but uses your xmeta repo as the only repo
# xqm is similar to xtools' xq but only uses the XMETA_REPODIR repository

xbps-query --ignore-conf-repos --repository="${XMETA:-${XDG_DATA_HOME:-$HOME/.local/share}/xmeta}" "$@"

A xrmm => xrmm +4 -0
@@ 0,0 1,4 @@
#!/bin/sh
# xrmm removes packages with xbps-remove (see readme for why this exists)

sudo xbps-remove -R "$@"

M xrsm => xrsm +1 -1
@@ 1,4 1,4 @@
#!/bin/sh
# xrsm is similar to xtools' xrs but uses your xmeta repo as the only repo
# xrsm is similar to xtools' xrs but only uses the XMETA_REPODIR repository

xbps-query --ignore-conf-repos --repository="${XMETA_REPODIR:-${XDG_DATA_HOME:-$HOME/.local/share}/xmeta}" -Rs "$@"