From ef8050f8f7c5ba364b5d1bc6878ccfaba7cbfc77 Mon Sep 17 00:00:00 2001 From: zenobit Date: Sat, 26 Feb 2022 21:06:40 +0100 Subject: [PATCH] added slim version etc... --- LICENSE | 2 + Makefile | 6 +- README.md | 20 +- screenshots/{vpm.png => vbm.png} | Bin vbm | 655 --------------------------- vbm.sh | 735 +++++++++++++++++++++++++++++++ 6 files changed, 744 insertions(+), 674 deletions(-) rename screenshots/{vpm.png => vbm.png} (100%) delete mode 100755 vbm create mode 100755 vbm.sh diff --git a/LICENSE b/LICENSE index c7c3233..6fe5bfa 100644 --- a/LICENSE +++ b/LICENSE @@ -1,3 +1,5 @@ +vbm - An XBPS package management helper for VoidLinux +as vpm - An XBPS package management helper for VoidLinux Copyright (C) 2016 Armin Jenewein diff --git a/Makefile b/Makefile index 48d9322..9a8d98d 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -PREFIX_BIN ?= /usr/local/bin +PREFIX_BIN ?= /bin PREFIX_BASHC ?= /usr/share/bash-completion/completions .PHONY: all @@ -7,8 +7,8 @@ all: .PHONY: install install: - cp ./vbm $(PREFIX_BIN)/vbm - cp ./bash-completion/completions/vbm $(PREFIX_BASHC)/vbm + cp vbm.sh $(PREFIX_BIN)/vbm + cp bash-completion/completions/vbm $(PREFIX_BASHC)/vbm .PHONY: uninstall uninstall: diff --git a/README.md b/README.md index 056fb7d..7ad51ea 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ### Changed name from vpm to vbm -# vbm - An XBPS package management helper for vb-linux and VoidLinux +# vbm - An XBPS package management helper for vb aka Void GNU/Linux version 1.4.1 `vbm` is a simple to use, daily-driver enhancement to the awesome XBPS (X Binary @@ -11,23 +11,11 @@ nitpickers understanding of the word - especially vbm shouldn't be confused with XBPS - vbm is just an addon helper tool for XBPS to make your life easier. That's it. -# Screenshots +# better then screenshots vbm... -![vbm](https://codeberg.org/oSoWoSo/vbm/raw/branch/main/screenshots/vbm.png) - -vbm trying install package but... - -![try](https://codeberg.org/oSoWoSo/vbm/raw/branch/main/screenshots/vbm.png) - -vbm automatic updating xbps while updating system... - -![xbps](https://codeberg.org/oSoWoSo/vbm/raw/branch/main/screenshots/vbm3.png) - -vbm installing package... - -![xbps](https://codeberg.org/oSoWoSo/vbm/raw/branch/main/screenshots/vbm4.png) +[![asciicast](https://asciinema.org/a/476068.svg)](https://asciinema.org/a/476068) # Motivation to write vpm @@ -50,7 +38,7 @@ Or you can just grab vbm and paste it anywhere in your system. # Installation ### 1. Install xtools via `xbps-install` -### (optional - needed for for xcheckrestart functions) +### (optional - needed for xcheckrestart functions) $ xbps-install -S xtools diff --git a/screenshots/vpm.png b/screenshots/vbm.png similarity index 100% rename from screenshots/vpm.png rename to screenshots/vbm.png diff --git a/vbm b/vbm deleted file mode 100755 index 1e940cf..0000000 --- a/vbm +++ /dev/null @@ -1,655 +0,0 @@ -#!/bin/bash -# vim: ft=sh ts=2 sw=2 sts=2 et - -# vbm - vb-linux management utility for -# XBPS, the X Binary Package System -# original author of vpm: Armin Jenewein , GitHub: @netzverweigerer -# a lot used from: Dave Eddy , GitHub: @bahamas10 -# this fork vbm: zenobit from oSoWoSo , codeberg.org: @oSoWoSo -# For more information about XBPS, see: -# https://github.com/voidlinux/xbps -# Released under the terms of the GNU general public license, version 3+ -# see LICENSE file for license information. - -# set version number -version="1.4.1" -# disable verbosity by default -verbose=false -# override color settings -colors=auto - -# VPM color definitions -numc1=1 -numc2=2 -numc3=3 -numc4=4 -numc5=5 -numc6=6 -numc7=7 -numc8=8 -c=$(tput sgr0) -c1=${numc1} -c2=${numc2} -c3=${numc3} -c4=${numc4} -c5=${numc5} -c6=${numc6} -c7=${numc7} -c8=${numc8} - -## COLORS -#c=$(tput sgr0) # reset -#c1=$(tput setaf 1) # red -#c2=$(tput setaf 2) # green -#c3=$(tput setaf 3) # yellow -#c4=$(tput setaf 4) # blue -#c5=$(tput setaf 5) # magenta -#c6=$(tput setaf 6) # light blue -#c7=$(tput setaf 7) # white -#c8=$(tput setaf 8) # grey - -# program name -progname=${0##*/} - -# enable or disable colors based on the argument given, i.e.: -# setcolors on # colors on -# setcolors off # colors off -# setcolors auto # colors on or off depending on environment -declare -A COLORS - -setcolors () { - local opt=$1 - # determine if colors should be enabled or not - if [[ $opt == auto ]]; then - # if stdout is a TTY and the TERM looks like it supports color enable colors - if [[ -t 1 && $TERM == *color* ]]; then - opt='on' - else - opt='off' - fi - fi - case "$opt" in - on) - local i - for i in {1..11}; do - if [[ -n ${COLORS[$i]} ]]; then - continue - fi - COLORS[$i]=$(tput setaf "$i") - done - c1=${COLORS[$numc1]} - c2=${COLORS[$numc2]} - c3=${COLORS[$numc3]} - c4=${COLORS[$numc4]} - c5=${COLORS[$numc5]} - c6=${COLORS[$numc6]} - c7=${COLORS[$numc7]} - c8=${COLORS[$numc8]} - c=$(tput sgr0) - ;; - off) - c1= - c2= - c3= - c4= - c5= - c6= - c7= - c8= - c= - unset COLORS - declare -A COLORS - ;; - *) - rmsg 255 "unknown color option: '$opt'" - exit 255 - ;; - esac -} - -# print the logo with brackets colorized -getlogo () { - printf '%s[%s%s%s]%s' \ - "$c6" \ - "$c5" "$progname" \ - "$c6" \ - "$c" -} - -# prints a message (with vbm-prefix) -msg () { - local logo=$(getlogo) - local newline=true - - if [[ $1 == '-n' ]]; then - newline=false - shift - fi - - printf '%s %s%s%s' "$logo" "$c4" "$*" "$c" - $newline && echo -} - -# rmsg - same (but colorized based on return status passed via $1) -rmsg () { - local code=$1 - shift - - local logo=$(getlogo) - local statuscolor - - if ((code == 0)); then - statuscolor=$c7 - else - statuscolor=$c1 - fi - - printf '%s %s%s%s\n' "$logo" "$statuscolor" "$*" "$c" -} - -banner () { - echo -n "$c5" - echo ' __ ___ __ _ __ ' - - printf " \\ V / '_ \\ ' \ " - echo -n "$c2" - echo " $progname - void package management utility for XBPS" - echo -n "$c5" - echo -n ' \_/| .__/_|_|_\' - echo -n "$c2" - echo ' GitHub: https://github.com/netzverweigerer/vpm' - echo -n "$c5" - echo ' |/ ' - echo ' ยด ' - echo -n "$c" -} - -version () { - banner - msg "$progname - Version: $version (GPLv3+)" - msg "original author: Armin Jenewein , GitHub: @netzverweigerer" - msg "a lot used from: Dave Eddy , GitHub: @bahamas10" - msg "this fork: zenobit from oSoWoSo , codeberg.org: @oSoWoSo" - msg "XBPS version: $(xbps-query -v --version | sed 's/GIT: UNSET//')" -} - -# check if we have UID 0, exit otherwise -rootcheck () { - if [[ $EUID -gt 0 ]]; then - msg "$(tput setaf 1)This operation needs super-user privileges.$(tput sgr 0)" - SUDO=sudo - else - SUDO='' - fi -} - -t () { - if [[ -n $show_translations ]]; then - tput setaf 242 - echo ' ' "$@" - echo - tput setaf 109 - fi -} - -wrapcommand() { - local cmd ret - cmd=("$@") - - echo "$c4(${cmd[*]}):$c" - - "${cmd[@]}" - ret=$? - - rmsg "$ret" "[${cmd[*]}], return code was: $ret" - exit "$ret" -} - -usage () { - echo "${c2}USAGE: -${c1}${progname} ${c8}[OPTIONS] ${c7}[SUBCOMMANDS] ${c3}[] -${c8} OPTIONS : -${c8}--color= - ${c4}Enable/Disable colorized output (default: auto) -${c8}--help - ${c4}(same as: help) -${c8}--help-pager - ${c4}(same as: helppager) -${c8}--show-translations - ${c4}Show XBPS command translations for $progname sub-commands -${c8}--verbose - ${c4}Verbose mode (shows XBPS command translations during execution) -${c2} long : ${c7}SUBCOMMANDS${c1} : ${c1}(short) ${c3} -${c2}help - ${c4}Show usage information -${c2}helppager ${c1}(hp) - ${c4}Show usage information (will pipe output to less/more) -${c2}version ${c1}(v) - ${c4}Show version and exit -${c2}about ${c1}(a) ${c3} - ${c4}Show information about " - t "xbps-query -v -R" - echo "${c2}filelist ${c1}(fl) ${c3} - ${c4}Show file-list of " - t "xbps-query -v -R -f" - echo "${c2}deps ${c1}(d) ${c3} - ${c4}Show dependencies for " - t "xbps-query -v -R -x" - echo "${c2}reverse ${c1}(rd) ${c3} - ${c4}Show reverse dependendies of (see man xbps-query)" - t "xbps-query -v -R -X" - echo "${c2}search ${c1}(s) ${c3} - ${c4}Search for package" - t "xbps-query -v -Rs" - echo "${c2}searchlib ${c1}(sl) ${c3} - ${c4}Search for package (multilib exclude)" - t "xbps-query -v -Rs" - echo "${c2}searchfile ${c1}(sf) ${c3} - ${c4}Search for package containing (local)" - t "xbps-query -v -o \"*/$1\"" - echo "${c2}whatprovides ${c1}(wp) ${c3} - ${c4}Search for package containing " - t "xlocate ${c3}" - echo "${c2}list ${c1}(ls) - ${c4}List installed packages" - t "xbps-query -v -l" - echo "${c2}listw ${c1}(lw) - ${c4}List installed packages without their version" - t "xbps-query -l | awk '{ print $2 }' | xargs -n1 xbps-uhelper getpkgname" - echo "${c2}listalternatives ${c1}(la) - ${c4}List alternative candidates" - t "xbps-alternatives -l" - echo "${c2}listrepos ${c1}(lr) - ${c4}List configured repositories" - echo "${c2}repolist ${c1}(rl) - ${c4}Alias for listrepos" - t "xbps-query -v -L" - echo "${c2}sync ${c1}(sy) - ${c4}Synchronize remote repository data" - t "xbps-install -S" - echo "${c2}update ${c1}(up) - ${c4}Update the system" - t "xbps-install -Suv" - echo "${c2}addrepo ${c1}(ad) ${c3} - ${c4}Add an additional repository" - t "xbps-install " - echo "${c2}install ${c1}(i) ${c3} - ${c4}Install " - t "xbps-install" - echo "${c2}devinstall ${c1}(di) ${c3} - ${c4}Install and devel-(s)" - t "xbps-install -devel" - echo "${c2}reconfigure ${c1}(rc) ${c3} - ${c4}Re-configure installed " - t "xbps-reconfigure -v" - echo "${c2}forceinstall ${c1}(fi) ${c3} - ${c4}Force installation of " - t "xbps-install -f" - echo "${c2}setalternative ${c1}(sa) ${c3} - ${c4}Set alternative for " - t "xbps-alternatives -s" - echo "${c2}remove ${c1}(rm) ${c3} - ${c4}Remove from the system" - t "xbps-remove -v " - echo "${c2}removerecursive ${c1}(rr) ${c3} - ${c4}Recursively remove package(s) (and its dependencies)" - t "xbps-remove -v -R" - echo "${c2}cleanup ${c1}(cl) - ${c4}Remove obsolete packages in cachedir" - t "xbps-remove -v -O" - echo "${c2}autoremove ${c1}(ar) - ${c4}Remove orphaned packages" - t "xbps-remove -v -o" - echo "${c2} XBPS COMPATIBILITY ${c2}: " - f=(/usr/sbin/xbps-*) - echo "${c4}$progname also understands all unknown XBPS sub-commands, too:" - echo -n "${c2}Example: ${c7}" - selected=${f[$RANDOM % ${#f[@]}]} - echo "$progname ${selected##*-} - ${c2}see also: ${c4}/usr/sbin/xbps-* ${c}" -} - -setcolors auto -case "$1" in - --color=true|--color=yes|--color=on) - setcolors on - shift - ;; - --color=auto) - setcolors auto - shift - ;; - --color=false|--color=off|--color=no) - setcolors off - shift - ;; - --verbose=true) - shift - verbose=true - ;; - --show-translations) - shift - show_translations=1 - ;; - --help) - shift - usage - exit 255 - ;; - --help-pager) - shift - "$0" --color=off --help | less - ;; - --*) - msg "Unknown option: $1 (try: $progname --help)" - exit 1 - ;; -esac - - -if [[ -z $1 ]]; then - usage - exit 0 -fi - - -cmd=$1 -if [[ $arg =~ --.* ]]; then - cmd=${arg:2} -fi -shift - -case "$cmd" in - - about|a) - wrapcommand xbps-query -v -R "$@" - ;; - - filelist|fl|listfiles) - wrapcommand xbps-query -v -R -f "$@" - ;; - - deps|dep|dependencies|d) - wrapcommand xbps-query -v -R -x "$@" - ;; - - reverse|rd) - msg -n "Reverse dependencies for $* " - wrapcommand xbps-query -v -R -X "$@" - ;; - - searchfile|sf) - msg -n 'searchfile ' - wrapcommand xbps-query -v -o "*/$1" - ;; - - remotesearchfile|rsf) - msg -n 'remotesearchfile ' - wrapcommand xbps-query -R -v -o "*/$1" - ;; - - list|ls) - msg -n 'Installed packages: ' - - count=0 - while read -r _ pkg _; do - ((count++)) - pkgname=${pkg%-*} - version=${pkg##*-} - - printf '%s%d %s%s %s (%s%s%s) [%s%s%s]%s\n' \ - "$c8" "$count" \ - "$c4" "$pkgname" \ - "$c6" \ - "$c2" "$version" \ - "$c6" \ - "$c7" "$pkg" \ - "$c6" \ - "$c" - done < <(xbps-query -v -l) - ;; - - listw|lw) - xbps-query -l | awk '{ print $2 }' | xargs -n1 xbps-uhelper getpkgname - ;; - - listalternative|listalternatives|la) - wrapcommand xbps-alternatives -l "$@" - ;; - - setalternative|setalternatives|sa) - rootcheck - wrapcommand xbps-alternatives -s "$@" - echo - ;; - - repolist|listrepos|rl|lr) - code=0 - msg -n "Configured repositories (xbps-query -v -L): " - - xbps-query -v -L - ret=$? - ((ret == 0)) || code=1 - rmsg "$ret" "[xbps-query -v -L] return code: $ret" - - echo - - msg -n "Available sub-repositories (xbps-query -v -Rs void-repo): " - xbps-query -v -Rs void-repo - ret=$? - ((ret == 0)) || code=1 - rmsg "$ret" "[xbps-query -v -Rs void-repo] return code: $ret" - - echo - - msg -n "Use \"$progname addrepo \" to add a sub-repository." - echo - - exit "$code" - ;; - - addrepo|ad) - rootcheck - echo - if (($# < 1)); then - rmsg 255 "ERROR: install: argument missing, try --help." - exit 1 - fi - code=0 - for repo in "$@"; do - msg "Adding repository: $repo" - $SUDO xbps-install "$repo" - ret=$? - ((ret == 0)) || code=1 - rmsg "$ret" "[xbps-install $arg] return code: $ret" - - msg "Synchronizing remote repository data (xbps-install -S): " - $SUDO xbps-install -S - ret=$? - ((ret == 0)) || code=1 - rmsg "$ret" "[xbps-install -S] return code: $ret" - done - - exit "$code" - ;; - - sync|sy) - rootcheck - msg -n 'Synchronizing remote repository data ' - echo - wrapcommand "$SUDO" xbps-install -S - ;; - - install|i) - rootcheck - if (($# < 1)); then - rmsg 255 "ERROR: install: argument missing, try --help." - exit 1 - fi - - msg -n "Installing packages: $* " - echo - wrapcommand "$SUDO" xbps-install "$@" - ;; - - yesinstall) - rootcheck - if (($# < 1)); then - rmsg 255 "ERROR: install: argument missing, try --help." - exit 1 - fi - msg -n "Installing packages (assumed yes): $* " - echo - wrapcommand "$SUDO" xbps-install -y "$@" - ;; - - devinstall) - rootcheck - if (($# < 1)); then - rmsg 255 "ERROR: devinstall: argument missing, try --help." - exit 1 - fi - - args=("$@") - code=0 - - msg "devinstall: Packages will be installed one-by-one" - msg "Use \"forceinstall\" to override this if you know what you're doing." - msg "(Note: forceinstall won't install -devel packages)" - for arg in "${args[@]}"; do - msg "Installing package: $arg (xbps-install $arg) ..." - $SUDO xbps-install "$arg" - ret=$? - ((ret == 0)) || code=1 - rmsg "$ret" "[xbps-install $arg] return code: $ret" - - msg "installing devel package (${arg}-devel):" - $SUDO xbps-install "${arg}-devel" - ret=$? - ((ret == 0)) || code=1 - rmsg "$ret" "[xbps-install ${arg}-devel] return code: $ret" - done - - exit "$code" - ;; - - forceinstall|fi) - rootcheck - msg -n "Force-Installing Package(s): $* " - echo - wrapcommand "$SUDO" xbps-install -f "$@" - ;; - - remove|rm) - rootcheck - msg -n "Removing package(s): $* " - echo - wrapcommand "$SUDO" xbps-remove -v "$@" - ;; - - removerecursive|rr) - rootcheck - msg -n "Removing package(s) recursively: $* " - echo - wrapcommand "$SUDO" xbps-remove -v -R "$@" - ;; - - reconfigure|rc) - rootcheck - msg -n 'reconfigure: Re-configuring package(s) ' - echo - wrapcommand "$SUDO" xbps-reconfigure -v "$@" - ;; - - autoremove|ar) - rootcheck - msg -n 'autoremove: Removing orphaned packages ' - echo - wrapcommand "$SUDO" xbps-remove -v -o - ;; - - update|upgrade|up) - rootcheck - msg -n 'Running system update ' - echo - $SUDO xbps-install -Suv - if [[ $? == 16 ]]; then - msg -n "$(tput setaf 1)Updating xbps $(tput sgr 0)" - $SUDO xbps-install -u xbps - wrapcommand "$SUDO" xbps-install -Suv - else - if [[ $? == 1 ]]; then - msg 'Your system is up to date.' - else - msg $? 'Something goes wrong!' - fi - fi - msg 'Checking if something need restart...' - xcheckrestart - ;; - - search|s) - msg -n "Searching for: $* " - wrapcommand xbps-query -v -Rs "$*" - ;; -# TODO: instead of grep use proper command - searchlib|sl) - msg -n "Searching for: $* " - wrapcommand xbps-query -v -Rs "$*" | grep -v 32bit - ;; - - cleanup|clean|cl) - msg -n 'Remove obsolete packages in cachedir ' - rootcheck - echo - wrapcommand "$SUDO" xbps-remove -v -O "$@" - ;; - - h|help|-h|--help) - usage - ;; - - helppager|help-pager|hp) - pager=$PAGER - if [[ -z $pager ]]; then - if command -v less &>/dev/null; then - pager=less - else - pager=more - fi - fi - - "$0" --color=off help | $pager - exit 0 - ;; - - version|v) - version - exit 0 - ;; - - whatprovides|wp) - if ! command -v xlocate &>/dev/null; then - rmsg 255 "xlocate not found. Try installing the xtools package." - exit 1 - fi - - msg -n "relaying to xlocate - use xlocate -S to (re-)build cached DB. " - wrapcommand xlocate "$@" - ;; - - ''|*) - xbpscmd="xbps-$cmd" - if ! command -v "$xbpscmd" &>/dev/null; then - rmsg 255 "Unrecognized $progname subcommand: $cmd (and $xbpscmd does not exist) - Try: $progname help" - echo - exit 1 - fi - - # xbps- found - msg -n 'relaying to XBPS: ' - wrapcommand "$xbpscmd" "$@" - ;; -esac - -# enjoy and make better if you can... diff --git a/vbm.sh b/vbm.sh new file mode 100755 index 0000000..e4d82ac --- /dev/null +++ b/vbm.sh @@ -0,0 +1,735 @@ +#!/bin/bash +# vim: ft=sh ts=2 sw=2 sts=2 et + +# vbm - vb-linux management utility for +# XBPS, the X Binary Package System +# original author: Armin Jenewein , GitHub: @netzverweigerer +# a lot used from: Dave Eddy , GitHub: @bahamas10 +# this fork: zenobit , codeberg.org: @oSoWoSo +# For more information about XBPS, see: +# https://github.com/voidlinux/xbps + +# Released under the terms of the GNU general public license, version 3+ +# see LICENSE file for license information. + +# set version number +version="1.4.2" +# enable verbosity, by default +verbose=true +# program name +progname=${0##*/} + +# VBM color definitions +numcolorok=2 +numcolorfail=1 +numcolorlogo=2 +numcolorheader=3 +numcolortext=4 +numcolorgray=8 +numcolorpkgcount=7 +numcolordarkgray=11 +numcolorbrackets=1 + +# enable or disable colors based on the argument given, i.e.: +# setcolors on # colors on +# setcolors off # colors off +# setcolors auto # colors on or off depending on environment +declare -A COLORS +setcolors() { + local opt=$1 + + # determine if colors should be enabled or not + if [[ $opt == auto ]]; then + # if stdout is a TTY and the TERM looks like it supports color enable colors + if [[ -t 1 && $TERM == *color* ]]; then + opt='on' + else + opt='off' + fi + fi + + case "$opt" in + on) + local i + for i in {1..11}; do + if [[ -n ${COLORS[$i]} ]]; then + continue + fi + COLORS[$i]=$(tput setaf "$i") + done + colorbrackets=${COLORS[$numcolorbrackets]} + colordarkgray=${COLORS[$numcolordarkgray]} + colorfail=${COLORS[$numcolorfail]} + colorgray=${COLORS[$numcolorgray]} + colorheader=${COLORS[$numcolorheader]} + colorlogo=${COLORS[$numcolorlogo]} + colorok=${COLORS[$numcolorok]} + colorpkgcount=${COLORS[$numcolorpkgcount]} + colortext=${COLORS[$numcolortext]} + colorreset=$(tput sgr0) + ;; + off) + colorbrackets= + colordarkgray= + colorfail= + colorgray= + colorheader= + colorlogo= + colorok= + colorpkgcount= + colortext= + colorreset= + unset COLORS + declare -A COLORS + ;; + *) + rmsg 255 "unknown color option: '$opt'" + exit 255 + ;; + esac +} + +# print the logo with brackets colorized +getlogo() { + printf '%s[%s%s%s]%s' \ + "$colorbrackets" \ + "$colorlogo" "$progname" \ + "$colorbrackets" \ + "$colorreset" +} + +# prints a message (with vbm-prefix) +msg() { + local logo=$(getlogo) + local newline=true + + if [[ $1 == '-n' ]]; then + newline=false + shift + fi + + printf '%s %s%s%s' "$logo" "$colortext" "$*" "$colorreset" + $newline && echo +} + +# rmsg - same (but colorized based on return status passed via $1) +rmsg() { + local code=$1 + shift + + local logo=$(getlogo) + local statuscolor + + if ((code == 0)); then + statuscolor=$colorok + else + statuscolor=$colorfail + fi + + printf '%s %s%s%s\n' "$logo" "$statuscolor" "$*" "$colorreset" +} + +banner() { + echo -n "$colorlogo" + echo ' __ __/|__ _ __ ' + printf " \\ V / '_ \\ ' \ " + echo -n "$colorgray" + echo " $progname - XBPS package management helper" + echo -n "$colorlogo" + echo -n ' \_/|_,__/_|_|_\' + echo -n "$colorgray" + echo ' Source: https://codeberg.org/oSoWoSo/vbm' + echo -n "$colorlogo" + echo -n "$colorreset" +} + +version() { + banner + echo + msg "${colorpkgcount}$progname - Version: $version (GPLv3+)" + msg "${colorpkgcount}original author: Armin Jenewein " + msg "https://github.com/netzverweigerer/vpm" + msg "${colorpkgcount}a lot used from: Dave Eddy " + msg "https://github.com/bahamas10/vpm" + msg "${colorpkgcount}this fork: zenobit " + msg "https://codeberg.org/oSoWoSo/vbm" + msg "${colorpkgcount}XBPS version: $(xbps-query -v --version | sed 's/GIT: UNSET//')" +} + +# check if we have UID 0, exit otherwise +rootcheck() { + if [[ $EUID -gt 0 ]]; then + msg "$(tput setaf 1)This operation needs super-user privileges.$(tput sgr 0)" + SUDO=sudo + else + SUDO='' + fi +} + +t() { + if [[ -n $show_translations ]]; then + tput setaf 242 + echo ' ' "$@" + echo + tput setaf 109 + fi +} + +wrapcommand() { + local cmd ret + cmd=("$@") + + echo "$colortext(${cmd[*]}):$colorreset" + + "${cmd[@]}" + ret=$? + + rmsg "$ret" "[${cmd[*]}], return code was: $ret" + exit "$ret" +} + +usage() { + echo + version + echo + echo "${colorheader}USAGE: + ${colorpkgcount}${progname} ${colortext}[OPTIONS] ${colorok}[SUBCOMM${colorfail}ANDS] ${colorpkgcount}[] + + ${colorheader} OPTIONS : + ${colortext}--color= ${colorgray}Enable/Disable colorized output (default: auto) + ${colortext}--help ${colorgray}(same as: help) show usage + ${colortext}--slim ${colorgray}(same as: slim) show usage for small screens + ${colortext}--help-pager ${colorgray}(same as: helppager) + ${colortext}--show-translations ${colorgray}Show ${colorpkgcount}XBPS${colorgray} command translations for $colorpkgcount$progname$colorgray sub-commands + ${colortext}--verbose ${colorgray}Show ${colorpkgcount}XBPS${colorgray} command translations during execution + + ${colorheader} SUBCOMMANDS : + ${colorok}(long) ${colorfail}(short)${colorpkgcount} " + echo " ${colorok}sync ${colorfail}(S) ${colorgray}Synchronize remote repository data" + t "xbps-install -S" + echo " ${colorok}update ${colorfail}(u) ${colorgray}Update the system" + t "xbps-install -Suv" + echo " ${colorok}search ${colorfail}(s) ${colorpkgcount} ${colorgray}Search for package" + t "xbps-query -v -Rs" + echo " ${colorok}syncsearch ${colorfail}(Ss) ${colorgray}Fetch repodata and search for package" + t "xbps-query -v -MRs" + echo " ${colorok}about ${colorfail}(a) ${colorpkgcount} ${colorgray}Show information about " + t "xbps-query -v -R" + echo " ${colorok}install ${colorfail}(i) ${colorpkgcount} ${colorgray}Install " + t "xbps-install" + echo " ${colorok}remove ${colorfail}(rm) ${colorpkgcount} ${colorgray}Remove from the system" + t "xbps-remove -v " + echo " ${colorok}filelist ${colorfail}(fl) ${colorpkgcount} ${colorgray}Show file-list of " + t "xbps-query -v -R -f" + echo " ${colorok}deps ${colorfail}(d) ${colorpkgcount} ${colorgray}Show dependencies for " + t "xbps-query -v -R -x" + echo " ${colorok}reverse ${colorfail}(rd) ${colorpkgcount} ${colorgray}Show reverse dependendies of " + t "xbps-query -v -R -X" + echo " ${colorok}searchlib ${colorfail}(sl) ${colorpkgcount} ${colorgray}Search for package (64bit only)" + t "xbps-query -v -Rs" + echo " ${colorok}searchfile ${colorfail}(sf) ${colorpkgcount} ${colorgray}Search for package containing (local)" + t "xbps-query -v -o \"*/$1\"" + echo " ${colorok}whatprovides ${colorfail}(wp) ${colorpkgcount} ${colorgray}Search for package containing " + t "xlocate ${colorpkgcount}" + echo " ${colorok}list ${colorfail}(ls) ${colorgray}List installed packages" + t "xbps-query -v -l" + echo " ${colorok}listw ${colorfail}(lw) ${colorgray}List installed packages without their version" + t "xbps-query -l | awk '{ print $2 }' | xargs -n1 xbps-uhelper getpkgname" + echo " ${colorok}listalternatives ${colorfail}(la) ${colorgray}List alternative candidates" + t "xbps-alternatives -l" + echo " ${colorok}listrepos ${colorfail}(lr) ${colorgray}List configured repositories" + echo " ${colorok}repolist ${colorfail}(rl) ${colorgray}Alias for listrepos" + t "xbps-query -v -L" + echo " ${colorok}addrepo ${colorfail}(ad) ${colorpkgcount} ${colorgray}Add an additional repository" + t "xbps-install ${colorpkgcount}" + echo " ${colorok}devinstall ${colorfail}(di) ${colorpkgcount} ${colorgray}Install ${colorgray} and devel-" + t "xbps-install ${colorgray}-devel" + echo " ${colorok}reconfigure ${colorfail}(rc) ${colorpkgcount} ${colorgray}Re-configure installed " + t "xbps-reconfigure -v" + echo " ${colorok}forceinstall ${colorfail}(fi) ${colorpkgcount} ${colorgray}Force installation of " + t "xbps-install -f" + echo " ${colorok}setalternative ${colorfail}(sa) ${colorpkgcount} ${colorgray}Set alternative for " + t "xbps-alternatives -s" + echo " ${colorok}removerecursive ${colorfail}(rr) ${colorpkgcount} ${colorgray}Remove package(s) with dependencies" + t "xbps-remove -v -R" + echo " ${colorok}cleanup ${colorfail}(cl) ${colorgray}Remove obsolete packages in cachedir" + t "xbps-remove -v -O" + echo " ${colorok}autoremove ${colorfail}(ar) ${colorgray}Remove orphaned packages" + t "xbps-remove -v -o" + echo + echo "${colorpkgcount}XBPS${colorheader} COMPATIBILITY COOLNESS:" + echo -n "$colorgray" + f=(/usr/sbin/xbps-*) + echo "$colorpkgcount$progname$colorgray also understands all unknown ${colorpkgcount}XBPS${colorgray} sub-commands, too:" + echo -n "Example: " + selected=${f[$RANDOM % ${#f[@]}]} + echo "$colorpkgcount$progname$colorok ${selected##*-}$colorreset ${colorpkgcount} $colorgray- see also: /usr/sbin/xbps-*" + echo -n "$colorreset" +} + +usage_slim() { + echo + version + echo + echo "${colorheader}USAGE: + ${colorpkgcount}${progname} ${colortext}[OPTIONS] ${colorok}[SUBCOMM${colorfail}ANDS] ${colorpkgcount}[] + +${colorheader}OPTIONS : +${colortext}--color= + ${colorgray}Enable/Disable colorized output (default: auto) +${colortext}--help + ${colorgray}(same as: help) show usage +${colortext}--slim + ${colorgray}(same as: slim) show usage for small screens +${colortext}--help-pager + ${colorgray}(same as: helppager) +${colortext}--show-translations + ${colorgray}Show ${colorpkgcount}XBPS${colorgray} command translations for $colorpkgcount$progname$colorgray sub-commands +${colortext}--verbose + ${colorgray}Show ${colorpkgcount}XBPS${colorgray} command translations during execution + + ${colorheader} SUBCOMMANDS : +${colorok}(long) ${colorfail}(short)${colorpkgcount} +${colorok}about ${colorfail}(a) ${colorpkgcount} + ${colorgray}Show information about " + t "xbps-query -v -R" + echo "${colorok}filelist ${colorfail}(fl) ${colorpkgcount} + ${colorgray}Show file-list of " + t "xbps-query -v -R -f" + echo "${colorok}deps ${colorfail}(d) ${colorpkgcount} + ${colorgray}Show dependencies for " + t "xbps-query -v -R -x" + echo "${colorok}reverse ${colorfail}(rd) ${colorpkgcount} + ${colorgray}Show reverse dependendies of " + t "xbps-query -v -R -X" + echo "${colorok}search ${colorfail}(s) ${colorpkgcount} + ${colorgray}Search for package" + t "xbps-query -v -Rs" + echo "${colorok}searchlib ${colorfail}(sl) ${colorpkgcount} + ${colorgray}Search for package (64bit only)" + t "xbps-query -v -Rs" + echo "${colorok}searchfile ${colorfail}(sf) ${colorpkgcount} + ${colorgray}Search for package containing (local)" + t "xbps-query -v -o \"*/$1\"" + echo "${colorok}whatprovides ${colorfail}(wp) ${colorpkgcount} + ${colorgray}Search for package containing " + t "xlocate ${colorpkgcount}" + echo "${colorok}list ${colorfail}(ls) + ${colorgray}List installed packages" + t "xbps-query -v -l" + echo "${colorok}listw ${colorfail}(lw) + ${colorgray}List installed packages without version" + t "xbps-query -l | awk '{ print $2 }' | xargs -n1 xbps-uhelper getpkgname" + echo "${colorok}listalternatives ${colorfail}(la) + ${colorgray}List alternative candidates" + t "xbps-alternatives -l" + echo "${colorok}listrepos ${colorfail}(lr) + ${colorgray}List configured repositories" + echo "${colorok}repolist ${colorfail}(rl) + ${colorgray}Alias for listrepos" + t "xbps-query -v -L" + echo "${colorok}sync ${colorfail}(S) + ${colorgray}Synchronize remote repository data" + t "xbps-install -S" + echo "${colorok}update ${colorfail}(u) + ${colorgray}Update the system" + t "xbps-install -Suv" + echo "${colorok}addrepo ${colorfail}(ad) ${colorpkgcount} + ${colorgray}Add an additional repository" + t "xbps-install ${colorpkgcount}" + echo "${colorok}install ${colorfail}(i) ${colorpkgcount} + ${colorgray}Install " + t "xbps-install" + echo "${colorok}devinstall ${colorfail}(di) ${colorpkgcount} + ${colorgray}Install and devel-(s)" + t "xbps-install -devel" + echo "${colorok}reconfigure ${colorfail}(rc) ${colorpkgcount} + ${colorgray}Re-configure installed " + t "xbps-reconfigure -v" + echo "${colorok}forceinstall ${colorfail}(fi) ${colorpkgcount} + ${colorgray}Force installation of " + t "xbps-install -f" + echo "${colorok}setalternative ${colorfail}(sa) ${colorpkgcount} + ${colorgray}Set alternative for " + t "xbps-alternatives -s" + echo "${colorok}remove ${colorfail}(rm) ${colorpkgcount} + ${colorgray}Remove ${colorgray} from the system" + t "xbps-remove -v " + echo "${colorok}removerecursive ${colorfail}(rr) ${colorpkgcount} + ${colorgray}Remove package(s) with dependencies" + t "xbps-remove -v -R" + echo "${colorok}cleanup ${colorfail}(cl) + ${colorgray}Remove obsolete packages in cachedir" + t "xbps-remove -v -O" + echo "${colorok}autoremove ${colorfail}(ar) + ${colorgray}Remove orphaned packages" + t "xbps-remove -v -o" + echo "$colorheader" + echo "${colorpkgcount}XBPS${colorgray} COMPATIBILITY COOLNESS:" + echo -n "$colorgray" + f=(/usr/sbin/xbps-*) + echo "$colorpkgcount$progname$colorgray understands ${colorpkgcount}XBPS${colorgray} sub-commands" + echo -n "Example: " + selected=${f[$RANDOM % ${#f[@]}]} + echo "$colorpkgcount$progname$colorok ${selected##*-}$colorreset ${colorpkgcount} $colorgray + see also: /usr/sbin/xbps-*$colorreset" +} + +setcolors auto +case "$1" in + --color=true|--color=yes|--color=on) + setcolors on + shift + ;; + --color=auto) + setcolors auto + shift + ;; + --color=false|--color=off|--color=no) + setcolors off + shift + ;; + --verbose=true) + shift + verbose=true + ;; + --show-translations) + shift + show_translations=1 + ;; + --help) + shift + usage + exit 255 + ;; + --slim) + shift + usage_slim + ;; + --help-pager) + shift + "$0" --color=off --help | less + ;; + --*) + msg "Unknown option: $1 (try: $progname --help)" + exit 1 + ;; +esac + +if [[ -z $1 ]]; then + usage + exit 0 +fi + +cmd=$1 +if [[ $arg =~ --.* ]]; then + cmd=${arg:2} +fi +shift + +case "$cmd" in + + about|a) + wrapcommand xbps-query -v -R "$@" + ;; + + filelist|fl|listfiles) + wrapcommand xbps-query -v -R -f "$@" + ;; + + deps|dep|dependencies|d) + wrapcommand xbps-query -v -R -x "$@" + ;; + + reverse|rd) + msg "Reverse dependencies for $* " + wrapcommand xbps-query -v -R -X "$@" + ;; + + searchfile|sf) + msg 'searchfile ' + wrapcommand xbps-query -v -o "*/$1" + ;; + + remotesearchfile|rsf) + msg 'remotesearchfile ' + wrapcommand xbps-query -R -v -o "*/$1" + ;; + + list|ls) + msg 'Installed packages: ' + + count=0 + while read -r _ pkg _; do + ((count++)) + pkgname=${pkg%-*} + version=${pkg##*-} + + printf '%s%d %s%s %s (%s%s%s) [%s%s%s]%s\n' \ + "$colorpkgcount" "$count" \ + "$colortext" "$pkgname" \ + "$colorbrackets" \ + "$colorgray" "$version" \ + "$colorbrackets" \ + "$colordarkgray" "$pkg" \ + "$colorbrackets" \ + "$colorreset" + done < <(xbps-query -v -l) + ;; + + listw|lw) + xbps-query -l | awk '{ print $2 }' | xargs -n1 xbps-uhelper getpkgname + ;; + + listalternative|listalternatives|la) + wrapcommand xbps-alternatives -l "$@" + ;; + + setalternative|setalternatives|sa) + rootcheck + wrapcommand xbps-alternatives -s "$@" + echo + ;; + + repolist|listrepos|rl|lr) + code=0 + msg "Configured repositories (xbps-query -v -L): " + + xbps-query -v -L + ret=$? + ((ret == 0)) || code=1 + rmsg "$ret" "[xbps-query -v -L] return code: $ret" + + echo + + msg "Available sub-repositories (xbps-query -v -Rs void-repo): " + xbps-query -v -Rs void-repo + ret=$? + ((ret == 0)) || code=1 + rmsg "$ret" "[xbps-query -v -Rs void-repo] return code: $ret" + + echo + + msg "Use \"$progname addrepo \" to add a sub-repository." + echo + + exit "$code" + ;; + + addrepo|ad) + rootcheck + echo + if (($# < 1)); then + rmsg 255 "ERROR: install: argument missing, try --help." + exit 1 + fi + code=0 + for repo in "$@"; do + msg "Adding repository: $repo" + $SUDO xbps-install "$repo" + ret=$? + ((ret == 0)) || code=1 + rmsg "$ret" "[xbps-install $arg] return code: $ret" + + msg "Synchronizing remote repository data (xbps-install -S): " + $SUDO xbps-install -S + ret=$? + ((ret == 0)) || code=1 + rmsg "$ret" "[xbps-install -S] return code: $ret" + done + + exit "$code" + ;; + + sync|S) + rootcheck + msg 'Synchronizing remote repository data ' + echo + wrapcommand "$SUDO" xbps-install -S "$@" + ;; + + install|i) + rootcheck + if (($# < 1)); then + rmsg 255 "ERROR: install: argument missing, try --help." + exit 1 + fi + + msg "Installing packages: $* " + echo + wrapcommand "$SUDO" xbps-install "$@" + ;; + + yesinstall) + rootcheck + if (($# < 1)); then + rmsg 255 "ERROR: install: argument missing, try --help." + exit 1 + fi + msg "Installing packages (assumed yes): $* " + echo + wrapcommand "$SUDO" xbps-install -y "$@" + ;; + + devinstall) + rootcheck + if (($# < 1)); then + rmsg 255 "ERROR: devinstall: argument missing, try --help." + exit 1 + fi + + args=("$@") + code=0 + + msg "devinstall: Packages will be installed one-by-one" + msg "Use \"forceinstall\" to override this if you know what you're doing." + msg "(Note: forceinstall won't install -devel packages)" + for arg in "${args[@]}"; do + msg "Installing package: $arg (xbps-install $arg) ..." + $SUDO xbps-install "$arg" + ret=$? + ((ret == 0)) || code=1 + rmsg "$ret" "[xbps-install $arg] return code: $ret" + + msg "installing devel package (${arg}-devel):" + $SUDO xbps-install "${arg}-devel" + ret=$? + ((ret == 0)) || code=1 + rmsg "$ret" "[xbps-install ${arg}-devel] return code: $ret" + done + + exit "$code" + ;; + + forceinstall|fi) + rootcheck + msg "Force-Installing Package(s): $* " + echo + wrapcommand "$SUDO" xbps-install -f "$@" + ;; + + remove|rm) + rootcheck + msg "Removing package(s): $* " + echo + wrapcommand "$SUDO" xbps-remove -v "$@" + ;; + + removerecursive|rr) + rootcheck + msg "Removing package(s) recursively: $* " + echo + wrapcommand "$SUDO" xbps-remove -v -R "$@" + ;; + + reconfigure|rc) + rootcheck + msg 'reconfigure: Re-configuring package(s) ' + echo + wrapcommand "$SUDO" xbps-reconfigure -v "$@" + ;; + + autoremove|ar) + rootcheck + msg 'autoremove: Removing orphaned packages ' + echo + wrapcommand "$SUDO" xbps-remove -v -o + ;; + + update|upgrade|up|u) + rootcheck + msg 'Running system update ' + echo + $SUDO xbps-install -Suv + if [[ $? == 16 ]]; then + msg "$(tput setaf 1)Updating xbps $(tput sgr 0)" + $SUDO xbps-install -u xbps + wrapcommand "$SUDO" xbps-install -Suv + else + if [[ $? == 1 ]]; then + msg 'Your system is up to date.' + else + msg $? 'Something goes wrong!' + fi + fi + msg 'Checking if something need restart...' + echo + xcheckrestart + ;; + + syncsearch|Ss) + msg "Syncing and searching for: $* " + wrapcommand xbps-query -v -MRs "$*" + ;; + + search|s) + msg "Searching for: $* " + wrapcommand xbps-query -v -Rs "$*" + ;; + +# TODO: instead of grep use proper command + searchlib|sl) + msg "Searching for: $* " + wrapcommand xbps-query -v -Rs "$*" | grep -v 32bit + ;; + + cleanup|clean|cl) + msg 'Remove obsolete packages in cachedir ' + rootcheck + echo + wrapcommand "$SUDO" xbps-remove -v -O "$@" + ;; + + h|help|-h|--help) + usage + ;; + + slim|--slim) + usage_slim + ;; + + helppager|help-pager|hp) + pager=$PAGER + if [[ -z $pager ]]; then + if command -v less &>/dev/null; then + pager=less + else + pager=more + fi + fi + + "$0" --color=off help | $pager + exit 0 + ;; + + version|v) + version + exit 0 + ;; + + whatprovides|wp) + if ! command -v xlocate &>/dev/null; then + rmsg 255 "xlocate not found. Try installing the xtools package." + exit 1 + fi + + msg "relaying to xlocate - use xlocate -S to (re-)build cached DB. " + wrapcommand xlocate "$@" + ;; + + ''|*) + xbpscmd="xbps-$cmd" + if ! command -v "$xbpscmd" &>/dev/null; then + rmsg 255 "Unrecognized $progname subcommand: $cmd (and $xbpscmd does not exist) - Try: $progname help" + echo + exit 1 + fi + + # xbps- found + msg "relaying to ${colorpkgcount}XBPS${colorgray}: " + wrapcommand "$xbpscmd" "$@" + ;; +esac + +exit 0 +# enjoy and make better if you can...