-n "gtk" ou --not="gtk" : je ne désire pas
-w "gtk" ou --want="gtk" : je le recherche
-a (--all) : permet de tout aficher (utile avec --want)
par exemple :
yaourts.sh patience -not="gtk|gnome"
ou autre exemple :
yaourts.sh manjaro --want="kde" --not="gtk|gnome|python" -a
A noter que l'exécution est relativement lente
Voici le tout premier jet; le script (yaourts.sh):
#!/usr/bin/env bash
pkgname='yaourts'
version=0.1.0
# tests asset function
unset DEVELOPER PARAMS ADMIN CONFIG
PARAMS=1
ADMIN=1
DEVELOPER=1
c_red='\033[0m\033[31m'
c_green='\033[0m\033[32m'
c_yellow='\033[0m\033[33m'
c_end='\033[0m'
c_bold='\033[1m'
#########################
function usage()
{
echo -e "Usage: yaourts [options] 'packageName' \n\
-w 'dependence' --want : want dependence \n\
-n 'dependence' --not : no dependence\n
-a --all : return all\n\n
ex: --not='gtk|kde'"
}
function error()
{
local msg="$1"
echo "${msg}" >&2
}
function asset()
{
local E_PARAM_ERR=98
local E_ASSERT_FAILED=99
local msg="Error"
((PARAMS)) && {
(( $# < 1 )) && {
error "expected argument"
usage
exit $E_PARAM_ERR
}
}
((ADMIN)) && {
(($EUID != 0)) || {
error "you cannot perform this operation unless you are no root."
exit $E_ASSERT_FAILED
}
}
}
echod()
{
local txt="${1}"
local c_color="$2"
[[ $txt == '' ]] && echo "" ||echo -e "($c_color${txt}$c_end)"
}
run()
{
for package in $(yaourt -Ssq "$1"); do
all=$(LANG=en yaourt -Si "$package" 2>dev\null| grep "^De")
deps=$(echo "$all" | awk -F':' '/^Depends/ {print $2}')
deps=${deps//None/}
#deps=${deps// /}
desc=$(echo "$all" | awk -F':' '/^Description/ {print $2}')
if [[ $deps =~ (${NOWANT}) ]]; then
echo -ne " --${package}\t"
echod "${deps}" "$c_red"
continue
fi
#dependence is good
if [[ $deps =~ (${WANT}) ]]; then
echo -e "$c_bold${package}\n\t$c_end${desc}"
echo -e "\t Deps: $c_green$deps$c_end"
continue
fi
# not good
((ALL)) && {
echo -ne " --${package}\t"
echod "${deps}"
}
done
}
main()
{
unset ALL
SHORT=hw:n:da
LONG=help,want:,not:,dev,all
PARSED=$(getopt --options $SHORT --longoptions $LONG --name "$0" -- "$@")
(( $? != 0 )) && exit 1
eval set -- "$PARSED"
while true; do
case "$1" in
-w|--want)
WANT="$2"
shift 2
;;
-n|--not)
NOWANT="$2"
shift 2
;;
-a|--all)
ALL=1
shift
;;
-d|--dev)
DEVELOPER=1
shift
;;
-h|--help)
usage
exit 0
;;
--)
shift
break
;;
*)
echo "Programming error"
exit 3
;;
esac
done
#ARGS=("$@")
unset LONG SHORT PARSED
echo -e " -- want: $c_green${WANT}$c_end"
echo -e " -- not: $c_red${NOWANT}$c_end\n"
[[ $NOWANT == "" ]] && NOWANT='---'
# tests
asset "$@"
#run
run "$@"
}
if [ "${BASH_SOURCE[0]}" == "$0" ]; then
main "$@"
exit 0
fi