#!/bin/bash
+verstr="XbpsUI 2.0"
+
+# Evaluate command line:
+for arg in "$@" ; do
+ case "$arg" in
+ "-V")
+ echo "$verstr"
+ exit 0
+ ;;
+ "-d")
+ use_dialog=1
+ ;;
+ "-h"|*)
+ echo "Usage: $(basename $0) [-d] [-h] [-V]"
+ echo " -d use dialog(1) to display the main menu, not fzf(1)"
+ echo " -h display this help page"
+ echo " -V display version info and exit"
+ exit 0
+ ;;
+ esac
+done
+
+
# Make sure we can actually do anything meaningful:
SUDO=''
if (( $EUID != 0 )); then
fi
# Check/install essential prerequisites:
-preq="dialog fzf gawk grep"
pinst=""
+preq="fzf gawk grep"
+[[ "$use_dialog" == "1" ]] && preq="dialog $preq"
for cmd in $preq ; do
if ! command -pv "$cmd" > /dev/null ; then
pinst="$pinst $cmd"
# Create resource file for dialog:
+if [[ "$use_dialog" == "1" ]] ; then
echo "# dialogrc
use_colors = ON
use_shadow = OFF
border2_color = dialog_color
menubox_border2_color = dialog_color
" > $tmp/dialogrc
-
+fi
# Update repository package database:
function syncRepo() {
# Clean cache by removing obsolete binary packages:
function cleanCache() {
- echo "Cleaning package cache ..."
+ echo "Cleaning package cache ..."
$SUDO xbps-remove -Ov
}
# Remove orphaned packages:
function reapOrphans() {
- echo "Searching for orphans ..."
+ echo "Searching for orphans ..."
$SUDO xbps-remove -ov
}
# Main menu:
function menu() {
-
- # NOTE: Using explicit output fd redirection, as dialog's --stdout
- # option might fail in unexpected ways.
- exec 3>&1
- choice=$( \
- DIALOGRC=$tmp/dialogrc \
- dialog \
- --backtitle 'XbpsUI v2' \
- --begin 1 0 \
- --cancel-label 'Quit' \
- --colors \
- --no-lines \
- --no-shadow \
- --menu '\Zb\ZuSelect Operation:' 20 60 15 \
- 'sync' 'Synchronize repository package database' \
- 'upgrade' 'Update all packages to their latest version' \
- 'install' 'Install a new package' \
- 'reinstall' 'Re-install an already installed package' \
- 'purge' 'Remove a currently installed package' \
- 'reconfig' 'Forcibly reconfigure an installed package' \
- 'clean' 'Remove obsolete packages from cache' \
- 'orphan' 'Remove orphaned packages' \
- 'manual' 'Mark packages as manually installed' \
- 'auto' 'Mark packages as automatically installed' \
- 'hold' 'Set packages on hold' \
- 'unhold' 'Unhold held packages' \
- 2>&1 1>&3 \
- )
- res=$?
- exec 3>&-
- clear
- if (( $res != 0 )) ; then
- # quit / cancel dialog
- exit 0
+ if [[ -n $use_dialog ]] ; then
+ # Use dialog(1) for main menu.
+ # NOTE: Using explicit output redirection, as dialog's --stdout
+ # option allegedly might fail in unexpected ways. Go figure.
+ exec 3>&1
+ choice=$( \
+ DIALOGRC=$tmp/dialogrc \
+ dialog \
+ --title "$verstr" \
+ --begin 1 0 \
+ --cancel-label 'Quit' \
+ --colors \
+ --no-lines \
+ --no-shadow \
+ --menu '' 19 60 15 \
+ 'sync' 'Synchronize repository package database' \
+ 'upgrade' 'Update all packages to their latest version' \
+ 'install' 'Install a new package' \
+ 'reinstall' 'Re-install an already installed package' \
+ 'purge' 'Remove a currently installed package' \
+ 'reconfig' 'Forcibly reconfigure an installed package' \
+ 'clean' 'Remove obsolete packages from cache' \
+ 'orphan' 'Remove orphaned packages' \
+ 'manual' 'Mark packages as manually installed' \
+ 'auto' 'Mark packages as automatically installed' \
+ 'hold' 'Set packages on hold' \
+ 'unhold' 'Unhold held packages' \
+ 2>&1 1>&3 \
+ )
+ res=$?
+ exec 3>&-
+ clear
+ if (( $res != 0 )) ; then
+ # quit / cancel dialog
+ exit 0
+ fi
+ else
+ # Use fzf(1) for main menu.
+ nl=$'\n'
+ hstr="$nl$verstr$nl$nl"
+ choice="$( echo \
+$'sync Synchronize repository package database
+upgrade Update all packages to their latest version
+install Install a new package
+reinstall Re-install an already installed package
+purge Remove a currently installed package
+reconfig Forcibly reconfigure an installed package
+clean Remove obsolete packages from cache
+orphan Remove orphaned packages
+manual Mark packages as manually installed
+auto Mark packages as automatically installed
+hold Set packages on hold
+unhold Unhold held packages
+quit Quit' |
+ fzf -i \
+ --no-multi \
+ --exact \
+ --no-sort \
+ --cycle \
+ --reverse \
+ --margin="4%,1%,1%,2%" \
+ --inline-info \
+ --header="$hstr" |
+ awk '{ print $1 }'
+ )"
+ res=$?
+ if [[ -z "$choice" ]] ; then
+ # quit / cancel dialog
+ exit 0
+ fi
fi
-
+
# Perform requested operation:
case "$choice" in
"sync" ) syncRepo ;;
"auto" ) markPkgAuto ;;
"hold" ) holdPkg ;;
"unhold" ) unholdPkg ;;
- * ) echo "Oops, unknown operation!?!" ; false ;;
+ "quit" ) exit 0 ;;
+ * ) echo "Unknown operation, WTF!?!" ; false ;;
esac
- res=$?
- return $res
+ return $?
}
# Report exit status of an operation:
read
}
-# Main loop
-
+# Main loop:
while : ; do
menu
statrep $?