View previous topic :: View next topic |
Author |
Message |
ulenrich Veteran
Joined: 10 Oct 2010 Posts: 1483
|
Posted: Fri Jul 30, 2021 12:17 am Post subject: mygendb - index and search all ebuilds |
|
|
I wanted a more simple and flexible way for search
[Edit] A fast and simple frontend in a post below: mygshow
Code: | #!/bin/bash
## name: mygendb
## version: 0.94
## author: ulenrich
## licence like: Mozilla
##
## Changes 0.94:
## search: sed expression falsely had eaten a slot's leading '0/'
## search: also display repo in -g search output like with -a search
## search: don't ever eat -r0 for better comparism of slot changes
mygendbDir="/var/cache/mygendb"
# mygendbDir must have USER=portage as owner!
# As USER=portage run --update:
# sudo --user portage -- mygendb --update gentoo
# Although starting as root any --update session will invoke:
# exec sudo --user portage -- mygendb --update <REPO>
function errExit() {
[ "${1:1:3}" = "nfo" ] \
&& echo "$1 $2" \
|| echo " mygendb - Exit: $1 $2"
exit 2
}
declare -x woFile="yet_we_dont_have_a_semaphore"
function removeworkFile() {
[ "${woFile}" != "${woFile%${arch}}" ] && [ -f "${woFile}" ] && rm "${woFile}"
exit 3
}
trap removeworkFile HUP INT KILL
function giveArch() {
if [ "$1" = "--arch" ] ;then
shift
else
shift;shift;shift
fi
[ -z "$1" ] \
&& farch=$(sed -n \
-e'/^ACCEPT_KEYW/{s/ACCEPT_KEYWORDS[''" =~]*\([[:alnum:]]*\).*/\1/p;q}'\
/etc/portage/make.conf) \
|| farch=${1}
[[ ${farch:0:1} = "~" ]] && farch="${farch:1}" # we need without '~'
[[ -z ${farch} ]] && farch='amd64' # at least the likely default
farch="${farch@L}" # we need lower case
echo ${farch}
return 0
}
function mygenRepoLocation() {
# $1 = repo name
# we look for name.conf and disabled repos .name.conf
[[ -z $1 ]] &&errExit "need repo name for location"
repo="$1"
locD=""
[ ${repo@L} = "merged" ] \
&& echo "/var/db/pkg" \
&& return 0
conF="/etc/portage/repos.conf/$repo.conf"
[ ! -f "${conF}" ] && return 1
locD=$(sed -n -e's/#.*//' -e'y/"/ /' -e"y/'/ /" \
-e'/^location[ =]*/{s_.*=__;s_[[:blank:]]*\(.*\)[[:blank:]]*_\1_p;q}' \
"${conF}")
[[ -d "${locD}" ]] \
&& echo $locD \
&& return 0 \
|| return 1
}
function asInteg() {
declare -i I=0 c=0 k=0
v=" $@" # we absolutely need a blank in front for the regex!
A='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
B='__________________________'
v=$(sed \
-e'{ s=.*= \U&=;y='$A'='$B'=;y=.,-_/= = }' \
-e'{ :eatzero;s= 0\([[:digit:]]\)= \1=;/ 0[[:digit:]]/b eatzero }' <<<"$v")
for k in $v 0 0 0 0 0 ; do
# zeros are needed if the higher version is shorter as the other
c=$(( $c + 1 ))
I=$(( $I <<10 ))
I=$(( $I + $k ))
(( c > 4 )) && break
done
echo $I
}
function mygenlistUpgrades() {
cd ${mygendbDir}/MERGED.${arch} || errExit "cannot cd MERGED.$arch"
declare -i c=0
for categ in * ; do
while read sta nam ver rev slo ; do
gFile="${mygendbDir}/gentoo.${arch}/${categ}"
[ ! -s ${gFile} ] && continue
while read stg nmg vrg rvg slg ; do
[ "${nam}" != "${nmg}" ] && continue
if [ $(asInteg ${vrg} 0 ${rvg}) -gt $(asInteg ${ver} 0 ${rev}) ] ;then
# insert a zero before revision otherwise '_pNNN' releases missed
#TODO include slot change, but complicate to compare
echo -e -n \
"\n ${sta} =${categ}/${nam}-${ver}-${rev}:${slo}\n ${stg}" 1>&2
echo -n " =${categ}/${nmg}-${vrg}-${rvg}:${slg}"
(( ++c ))
break
fi
done< <(sed -n -e'/^['${flags}']* '${nam}' /p' ${gFile} |sort -r -V -k 2 )
done< <( cat ${categ} )
done
echo -e "\n $c ebuilds with high versions. Masked ebuilds are included" 1>&2
}
function mygenDump() {
[ -d ${mygendbDir} ] || errExit "not found $mygendbDir"
cd ${mygendbDir} || errExit "not found $mygendbDir"
for d in *.${arch} ;do
[ -d "$d" ] || continue
pushd $d >/dev/null
repo=$(printf '%12s' ${d%.${arch}} )
for categ in * ; do
[ -s ${categ} ] || continue
while read sta nam ver rev slo ; do
[ ${slo} = '0' ] && slo="" || slo=':'${slo}
[ ${rev} = '0' ] && rev="" || rev='-'${rev}
echo "${repo} ${sta} ${categ}/${nam}-${ver}${rev}${slo}"
done < <(cat ${categ})
done
popd >/dev/null
done
}
function isNotCategory() {
# if $1 is not a category return true=0
[ ! -d "$1" ] && return 0
[ "${1:0:1}" = "." ] && return 0
[ "${1}" = "metadata" ] && return 0
[ "${1}" = "eclass" ] && return 0
[ "${1}" = "profiles" ] && return 0
[ "${1}" = "scripts" ] && return 0
[ "${1}" = "licenses" ] && return 0
return 1
}
function mygendbClean() {
declare -i G=0 D=0 E=0 U=0
# Unfound files not found in repo anymore
# all entries of ebuild files of the repo
cd ${mygendbDir} || errExit "not found mygendb: $mygendbDir"
for dbDir in *.${arch} ;do
[ -d $dbDir ] || continue
repo="${dbDir%.${arch}}"
[ "${repo}" = "MERGED" ] \
&& L=/var/db/pkg \
|| L="$(mygenRepoLocation $repo )"
[ -z $L ] && errExit "could not find location of $repo"
[ ! -d $L ] && errExit "location of $repo not exists: $L"
woFile=${mygendbDir}/.work.${repo}.${arch}
[ -f ${woFile} ] \
&& errExit " multi access problem with existing $woFile"
touch $woFile || errExit " as USER ${USER} we cannot write ${woFile}"
pushd $dbDir >/dev/null
for indexF in * ;do
## indexF = 'stat name vers revi slo'
## Status = (s)table (u)nstableTesting (w)ithoutKeyword (z)eroed
while read k n v r s ;do
[ "$r" = 'r0' ] && r='' || r='-'$r
# Attention: Probmem with '=-'
(( ++G ))
[ "${k}" = 'z' ] \
&& D=$(( $D + 1 )) \
&& continue
if [ "${repo}" = "MERGED" ] ;then
[ -d "$L/$indexF/$n-$v$r" ] \
&& (( E += 1 )) \
&& continue \
|| (( U += 1 ))
else
[ -f "$L/$indexF/$n/$n-$v$r.ebuild" ] \
&& (( E += 1 )) \
&& continue \
|| (( U += 1 ))
fi
done< <( cat ${indexF} )
sed -i -e'/^z /d' "${indexF}"
[ -f "${indexF}" ] \
&& [ ! -s "${indexF}" ] \
&& echo " Info empty category removd: $indexF" \
&& rm ${indexF}
done
popd >/dev/null
rm $woFile
done
echo -e "\t $G \t total entries"
echo -e "\t $D \t zeroed (these z entries were removed)"
echo -e "\t $E \t entries with an existing ebuild file"
echo -e "\t $U \t ebuilds not found, need --update"
}
function getSlot() {
# $1 = file
s=""
if [ -s "${1}" ] ;then
# if filename=SLOT then examine the MERGED repo OR sed the md5-cache
[ SLOT = $(basename $1 ) ] \
&& s=$(head -n 1 ${1} ) \
|| s=$(sed -n -e'/^SLOT/ { s/SLOT=//p ;q}' ${1} )
fi
[ -z ${s} ] && s="0"
echo ${s}
}
function mygendbUpdate() {
# $1=repo $2=location
R="$1"; [[ $R = "" ]] &&errExit "missing --repo argument"
L="$2"; [[ $L = "" ]] &&errExit "missing location for repo $R"
woFile="${mygendbDir}/.work.$R.${arch}"
[ -f ${woFile} ] && errExit " multi access problem with existing $woFile"
touch $woFile || errExit " as USER ${USER} we cannot write ${woFile}"
echo " mygendb --arch ${arch} --update $R"
dbDir=${mygendbDir}/${R}.${arch}
mkdir -p ${dbDir}
cd ${dbDir} || errExit "cannot create ${dbDir}"
for indexF in * ;do
## First check if all categorie exist we had previously as index
categ="${indexF}" # every category has an index
if [ ! -d "$L/$categ" ] ;then
# seemingly this category does not exist any more
[ -f "${indexF}" ] && rm "${indexF}"
echo " info category been removed: ${categ}"
fi
done
declare -i namEbUpdatedC=0 namEbRefoundC=0 namesRemovedC=0
cd "$L" || errExit "cannot cd into $L"
for categ in * ;do
[ "$R" != "MERGED" ] && isNotCategory $categ && continue
indexF="${dbDir}/$categ"
[ -f $indexF ] && Y=$(stat -c %Y $indexF)
[ ! -f $indexF ] && touch ${indexF} && Y=0
## indexF = 'stat name vers revi slot'
pushd $categ >/dev/null
for ins in * ;do
[[ -d $ins ]] || continue
Z=$(stat -c %Y $ins)
(( Z <= Y )) && continue
nam=${ins}
if [ $R = MERGED ] ;then
nam="${ins%-r[0-9]*}"
nam="${nam%-[0-9.]*}"
fi
sed -i -e"/^. ${nam} / s/^./z/" ${indexF}
if [ $R = MERGED ] ;then
ver=${ins#${nam}-}
rev=${ver##*-r}
[[ "$ver" != "$rev" ]] &&ver=${ver%-r${rev}} ||rev="0"
[[ "$ver" = "" ]] && ver="0"
[[ "$rev" = "" ]] && rev="r0" ||rev="r${rev}"
[ "gentoo" = $(head -n 1 "$L/${categ}/${ins}/repository" ) ] \
&& sta="G" \
|| sta="O"
slo=$(getSlot $L/${categ}/${ins}/SLOT )
liny="${nam} ${ver} ${rev} ${slo}"
if fgrep -q "z ${liny}" $indexF ;then
sed -i -e"s=^z ${liny}=${sta} ${liny}=" $indexF
(( ++namEbRefoundC ))
else
echo "${sta} ${liny}" >>$indexF
fi
(( ++namEbUpdatedC ))
else # not MERGED but normal repo
pushd $nam >/dev/null
for ebFile in *.ebuild ;do # multiple is the difference to MERGED
[ -f "${ebFile}" ] ||continue
ver=${ebFile%.ebuild}
ver=${ver#${nam}-}
rev=${ver##*-r}
[[ "$ver" != "$rev" ]] && ver=${ver%-r${rev}} || rev="0"
[[ "$ver" = "" ]] && ver="0"
[[ "$rev" = "" ]] && rev="r0" || rev="r${rev}"
liny=$( sed -n -e \
'/^[[:blank:]]*KEYWORD/{s/^.*\"\(.*\)\".*$/ \1 /p; ;q}'\
${ebFile})
if [[ "${liny}" = "${liny%${arch} *}" ]] ;then
sta="w"
elif [[ "${liny}" != "${liny%~${arch} *}" ]] ;then
sta="u"
else sta="s"
fi
slo=$(getSlot $L/metadata/md5-cache/${categ}/${ebFile%.ebuild})
liny="${nam} ${ver} ${rev} ${slo}"
if fgrep -q "z ${liny}" $indexF ;then
sed -i -e"s=^z ${liny}=${sta} ${liny}=" $indexF
(( ++namEbRefoundC ))
else echo "${sta} ${liny}" >>$indexF
fi
(( ++namEbUpdatedC ))
done
popd >/dev/null
fi # fi MERGED
sed -i -e"/^z $nam /d" $indexF
done
popd >/dev/null
### We have to look for packages the repo removed or renamed
if [ "$R" = "MERGED" ] ;then
while read stat nam ver rev slot ;do
[ "${rev}" = "r0" ] && riv='' || riv='-'${rev}
[ -d "$L/${categ}/${nam}-${ver}${riv}" ] && continue
echo -e " info package was unmerged: \t $categ/$nam-${ver}${riv}"
sed -i -e"/^[GO]* ${nam} ${ver} ${rev} /d" ${indexF}
(( ++namesRemovedC ))
done < <(grep -v -e'^z ' ${indexF} | sort -V -k 2)
# sort makes sure we can write to the indexF with sed d command
else # elif normal repo
while read nam ;do
[ -d "$L/${categ}/${nam}" ] && continue
echo -e " info package removed: \t \t $categ/$nam"
sed -i -e"/^. ${nam} .*/d" "${indexF}"
(( ++namesRemovedC ))
done < <(sed -e'/^z.*/d' -e's=..==' -e's= .*==' ${indexF}|sort --unique)
fi # fi MERGED
if (( namEbUpdatedC > 0 )) ;then
echo -n -e " examined ebuilds: ${namEbUpdatedC}\t"
namEbUpdatedC=$(( namEbUpdatedC - namEbRefoundC ))
echo -e " new version: ${namEbUpdatedC}\t${categ}"
fi
namEbUpdatedC=0; namEbRefoundC=0; namesRemovedC=0
done
[ -f "${woFile}" ] && rm "${woFile}"
}
arch=$(giveArch $1 $2)
[ "$1" = "--arch" ] && shift && shift
[ -z "${arch}" ] && errExit "cannot find any ARCH (like amd64,arm)"
while [ "$1" != "" ] ;do
case "$1" in
-h|-H|--help|--Help)
##@ Index all available ebuilds of all repositories for search
##@ Index lines save 5 fields: status name version revision slot
##@ mygendb --update <REPO> | -a <SEARCH>
exec sed -n -e'/^[[:blank:]]*exec.*/d' -e's/^.*##@//p' $0
;;
-u|-U|--update|--Update|--repo|--create|--createdb)
##@ -u|--update <REPO>
##@ create and update the index in /var/cache/mygendb
##@ REPO must have an /etc/portage/repos.conf/REPO.conf
##@ Also plays nicely with disabled ".REPO" names
if [ ! -d ${mygendbDir} ] ;then
[ "${UID}" != "0" ] && errExit "Only root can create $mygendbDir"
mkdir -p ${mygendbDir}
chown portage:portage ${mygendbDir}
[ ! -d ${mygendbDir} ] && errExit "cannot create dir $mygendbDir"
fi
if [ "${USER}" != "portage" ] ;then
[ "${UID}" != "0" ] && errExit 'need USER portage for --update'
exec sudo --user "portage" -- $0 --arch "${arch}" $@
exit # this line just has documentary purpose
fi
[ "--repo" = "$2" ] && shift
[ -z "$R" ] && R="$2"
[ -z "$R" ] && errExit "missing repo name"
shift
#removing leading point for disabled repos to work:
if [ ${R@L} = "merged" ] ;then
R="MERGED"
[ ${arch} != $(giveArch) ] && errExit "not accept ${arch} for MERGED"
fi
L="$(mygenRepoLocation $R )"
[ -d "$L" ] || errExit "missing repo location for $R : $L"
[[ ${R:0:1} = '.' ]] &&R="${R:1}"
mygendbUpdate $R $L
exit
;;
-m|-M|--updateMerged|--updatemerged)
##@ -m|--updateMerged
##@ update the index of all your merged (installed) ebuilds
##@ All these installed will show as a repo named "MERGED"
##@ Entries have 2 status flags: 'G' for gentoo and 'O'ther
exec $0 --update "MERGED"
exit # this line just has documentary purpose
;;
-d|-D|--dump|--dumpdb|--dumpDb|--dumpDB)
##@ -d|--dump
##@ dumps very fast the very raw data
[ -d ${mygendbDir} ] || errExit "not found $mygendbDir"
cd ${mygendbDir} || errExit "cannot cd $mygendbDir"
fgrep --color=never -s -R -H -F ' '
exit
;;
-g|-G|--grep|--grepGentoo|--grepgentoo)
##@ -g|--grepGentoo <SEARCH>
##@ grep the gentoo repo with your own search expression
shift
R='gentoo'
[ -z "${*}" ] && errExit "missing arg for grep - give a point!"
[ -d ${mygendbDir}/$R.${arch} ] || errExit "miss $mygendbDir/$R"
cd ${mygendbDir}/$R.${arch} || errExit "cd $mygendbDir/$R"
for F in * ; do
sed -e\
'{y= =-=;s=^\(.\).='$R' \1 '$F'/=;s=-r\([[:digit:]]*\)-=-r\1:=;s=:0$==}' $F
done |sort -V -k 3 | grep --color=auto "$@"
exit
;;
-a|-A|--all|--All|--grepAll)
##@ -a|--grepall <SEARCH>
##@ grep all repos with your own search expression
##@ This is the default action when called: mygendb <SEARCH>
shift
[ -z "${*}" ] && errExit "missing arg for grep - give a point!"
[ -d ${mygendbDir} ] || errExit "miss $mygendbDir"
cd ${mygendbDir} || errExit "cd $mygendbDir"
for repo in * ;do
R="${repo%.${arch}}"
[ -d ${repo} ] || continue
pushd ${repo} >/dev/null
for F in * ; do
#TODO awk seems to be much simpler, but ?howto? eat slot ':0'
#TODO gawk '{ print "'$R' "$1" '$F/'"$2"-"$3"-"$4":"$5 }' $F
sed -e\
'{y= =-=;s=^\(.\).='$R' \1 '$F'/=;s=-r\([[:digit:]]*\)-=-r\1:=;s=:0$==}' $F
# '{y= =-=;s=^\(.\).='$R' \1 '$F'/=;s=-r\(.*\)-=-r\1:=;s=-r0:=:=;s=:0$==}' $F
done
popd >/dev/null
done | grep --color=never "$@" | sort -V -k 3
exit
;;
--listUpgrade|--listupgrade|--listUpgrades|--listupgrades)
##@ --listupgrade
##@ find unstable Gentoo upgrades for all of repo "MERGED"
[ -d ${mygendbDir}/MERGED.${arch} ] || errExit "Info: miss index MERGED"
flags='su'
mygenlistUpgrades
exit
;;
--listupgradeStable|--listupgradestable|--listupgradesStable)
##@ --listupgradestable
##@ find stable Gentoo upgrades for all of "MERGED"
[ -d ${mygendbDir}/MERGED.${arch} ] || errExit "Info: miss index MERGED"
flags='s'
mygenlistUpgrades
exit
;;
--cleandb|--cleanDB|--cleanDb)
##@ --cleandb
##@ Remove dead "^z" entries (although they should not exist)
[ -d ${mygendbDir} ] || errExit "not found $mygendbDir"
if [ "${USER}" != "portage" ] ;then
exec sudo --user "portage" -- $0 --cleandb
else
mygendbClean
fi
exit
;;
--arch)
##@ --arch <ARCH>
##@ Not needed. Give this option before --update for another ARCH
shift
arch="$(giveArch --arch $1 )"
shift
[[ -z "${arch}" ]] && errExit "not understood argument for --arch"
# the only time the while case loop will
# NOT exit
;;
*)
[ "${1:0:1}" = "-" ] \
&& errExit "not found an action like this for you: $1" \
|| exec $0 --arch ${arch} --grepAll "$@"
;;
esac
shift
done
echo "If you see this line try: mygendb --help"
|
Last edited by ulenrich on Mon Aug 09, 2021 4:52 pm; edited 3 times in total |
|
Back to top |
|
|
ulenrich Veteran
Joined: 10 Oct 2010 Posts: 1483
|
Posted: Fri Jul 30, 2021 9:42 am Post subject: |
|
|
Code: | # mygendb -h
Index all available ebuilds of all repositories for search
Index lines save 5 fields: status name version revision slot
mygendb --update <REPO> | --grepGentoo <NAME>
-u|--update <REPO>
create and update the index in /var/cache/mygendb
REPO must have an /etc/portage/repos.conf/REPO.conf
Also plays nicely with disabled ".REPO" names
-m|--updateMerged
update the index of all your merged (installed) ebuilds
All these installed will show as a repo named "MERGED"
Entries have 2 status flags: 'G' for gentoo and 'O'ther
-d|--dump
dumps very fast the very raw data
-g|--grepGentoo <SEARCH>
grep the gentoo repo with your own search expression
-a|--grepAll <SEARCH>
grep all repos with your own search expression
This is the default action when called: mygendb <SEARCH>
--listupgrades
find unstable Gentoo upgrades for all of repo "MERGED"
--listupgradeStable
find stable Gentoo upgrades for all of "MERGED"
--cleandb
Remove dead "^z" entries (although they should not exist)
--arch <ARCH>
Not needed. Give this option before --update for another ARCH | mygendb is so simple,
I thought I'll code it in 3 hours. The first working version was done in that time. But thinking it through, how I would include the installed versions in the index, that took me much longer. Until I found to handle all the installed packages just as another repo with special name: MERGED
... In the end --updateMerged is --update MERGED
I took some more time to think about security, how to do without root. And I included some examples for usable output: --grepGentoo --grepAll --listupgrades
But the main purpose of mygendb is the index, ready for scripting your search results. Code: | repo.arch/category: status name version revision slot |
|
|
Back to top |
|
|
ulenrich Veteran
Joined: 10 Oct 2010 Posts: 1483
|
Posted: Fri Jul 30, 2021 10:38 am Post subject: |
|
|
My first use case is to display reliably and faster than eshowkw, eg: Code: | # time eshowkw -O app-misc/mc;echo ---;time mygendb app-misc/mc
Keywords for app-misc/mc:
| | u |
| a a p s a r | n |
| m r h p p l i i m m s | e u s | r
| d a m p p c a x p a s 6 i 3 | a s l | e
| 6 r 6 p p 6 r 8 h 6 c 8 p 9 | p e o | p
| 4 m 4 a c 4 c 6 a 4 v k s 0 | i d t | o
-------------+-----------------------------+-------+-------
[I]4.8.26-r4 | + + + + + + + + ~ ~ ~ o ~ ~ | 7 o 0 | gentoo
4.8.26-r5 | ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ o ~ ~ | 8 o | gentoo
real 0m1,633s
user 0m1,571s
sys 0m0,060s
---
MERGED G app-misc/mc-4.8.26-r4
gentoo s app-misc/mc-4.8.26-r4
gentoo u app-misc/mc-4.8.26-r5
real 0m0,597s
user 0m0,424s
sys 0m0,185s | If emerge --sync has removed your installed version, you have to use a second command, because eshowkw won't show your merges then. ... And you get some output although you don't remember fully: Code: | # mygendb a*c/mc
MERGED G app-misc/mc-4.8.26-r4
gentoo s app-misc/mc-4.8.26-r4
gentoo u app-misc/mc-4.8.26-r5
gentoo s net-misc/mcproxy-1.1.1-r1 |
|
|
Back to top |
|
|
ulenrich Veteran
Joined: 10 Oct 2010 Posts: 1483
|
Posted: Mon Aug 02, 2021 1:28 am Post subject: |
|
|
inserted in first post of this thread:
mygendb v0.94 - fixed a bug and changed output of searches a bit |
|
Back to top |
|
|
fedeliallalinea Administrator
Joined: 08 Mar 2003 Posts: 31348 Location: here
|
Posted: Mon Aug 02, 2021 6:15 pm Post subject: |
|
|
Moved from Portage & Programming to Documentation, Tips & Tricks. _________________ Questions are guaranteed in life; Answers aren't. |
|
Back to top |
|
|
ulenrich Veteran
Joined: 10 Oct 2010 Posts: 1483
|
Posted: Wed Aug 04, 2021 2:33 pm Post subject: frontend mygshow |
|
|
A frontend for mygendb: mygshow Code: | #!/bin/bash
# script name: mygshow
#
#@ mygshow is a frontend for mygendb
#@ It intends to be the better eshowkw
#@ In a single run it displays
#@ multipe search results with:
#@ mygshow SEARCH_A SEARCH_B SEARCH_C
#@ You can use mygshow with a pipe instead:
#@ mygshow | grep something
#@
#@ example given:
#@ # mygshow | grep -A 1 ^MERGED...x11-wm
#@ MERGED G x11-wm/marco-1.24.2-r0:0/2
#@ gentoo u x11-wm/marco-1.24.2-r0:0/2
#@ --
#@ MERGED G x11-wm/mutter-40.3-r1:0/8
#@ gentoo u x11-wm/mutter-40.3-r1:0/8
#@
#@ What else? Lines you just read with:
#@ mygshow --help
#@ How to use mygshow most effectively:
#@ mygshow --hint
# Changelog:
# - renamed script to resemble eshowkw
# - added pipe awareness
# - added a hint how to use mygendb in postsync
[ "$1" = "-h" -o "$1" = "--help" ] \
&& exec sed -n -e's/^#@//p' $0
[ "$1" = "--hint" ] \
&& exec sed -n -e's/^##@@//p' $0
C="${TMP:-$HOME}/mygenDbCache"
function createCacheFile() {
declare -i Y=0 Z=1
if [ -s $C ] ;then
newBOOL="n"
Y=$(stat -c %Y $C )
for m in /var/cache/mygendb/* ;do
[[ -d $m ]] || continue
Z=$(stat -c %Y $m )
(( $Z > $Y )) \
&& newBOOL='y' \
&& break
done
else
newBOOL="y"
fi
if [ "${newBOOL}" = "y" ] ;then
[ -f "$C" ] && rm "$C"
if not touch "$C" ;then
echo "cannot create cache: $C"
exit
fi
echo " .." >&2
mygendb -a . > "$C"
fi
}
##@@ You can use one single /tmp/mygenDbCache for everyone
##@@ with a line in /etc/portage/repo.postsync.d/FirstScript
##@@ mygendb --update "$1"
##@@
##@@ And these following two lines
##@@ in /etc/portage/postsync.d/SecondScript
##@@ mygendb --update MERGED
##@@ mygendb -a . >/tmp/mygenDbCache
##@@
##@@ Both scripts need the executable bit set
#
# Have general cache instead of having to use createCacheFile?
[ -s "/tmp/mygenDbCache" ] \
&& C="/tmp/mygenDbCache" \
|| createCacheFile
if [ -z "$1" ] ;then
[ -t 1 ] \
&& echo " try: mygshow --help" >&2 \
|| cat $C
else
while [[ -n $1 ]] ;do
grep --color=auto $1 $C
shift
done
fi
|
Last edited by ulenrich on Mon Aug 09, 2021 4:54 pm; edited 3 times in total |
|
Back to top |
|
|
ulenrich Veteran
Joined: 10 Oct 2010 Posts: 1483
|
Posted: Mon Aug 09, 2021 3:57 pm Post subject: |
|
|
Using the above script mygshow is much faster and condensed than with eshowkw:
Code: | # time mygshow|grep -A 1 ^MERGED...x11-wm;time eshowkw x11-wm/marco x11-wm/mutter x11-wm/twm
MERGED G x11-wm/marco-1.24.2-r0:0/2
gentoo u x11-wm/marco-1.24.2-r0:0/2
--
MERGED G x11-wm/mutter-40.3-r1:0/8
gentoo u x11-wm/mutter-40.3-r1:0/8
--
MERGED G x11-wm/twm-1.0.11-r0
gentoo s x11-wm/twm-1.0.11-r0
real 0m0,007s
user 0m0,002s
sys 0m0,007s
Keywords for x11-wm/marco:
| | u |
| a a p s a r | n |
| m r h p p l i i m m s | e u s | r
| d a m p p c a x p a s 6 i 3 | a s l | e
| 6 r 6 p p 6 r 8 h 6 c 8 p 9 | p e o | p
| 4 m 4 a c 4 c 6 a 4 v k s 0 | i d t | o
-------------+-----------------------------+---------+-------
1.24.1-r1 | + ~ ~ o o o o + o o o o o o | 6 o 0/2 | gentoo
[I]1.24.2 | ~ ~ ~ o o o o ~ o o o o o o | 6 o | gentoo
Keywords for x11-wm/mutter:
| | u |
| a a p s a r | n |
| m r h p p l i i m m s | e u s | r
| d a m p p c a x p a s 6 i 3 | a s l | e
| 6 r 6 p p 6 r 8 h 6 c 8 p 9 | p e o | p
| 4 m 4 a c 4 c 6 a 4 v k s 0 | i d t | o
-----------+-----------------------------+---------+-------
40.2.1 | + ~ + o o ~ o + o o o o o o | 7 o 0/8 | gentoo
[I]40.3-r1 | ~ ~ ~ o o ~ o ~ o o o o o o | 7 o | gentoo
Keywords for x11-wm/twm:
| | u |
| a a p s a r | n |
| m r h p p l i i m m s | e u s | r
| d a m p p c a x p a s 6 i 3 | a s l | e
| 6 r 6 p p 6 r 8 h 6 c 8 p 9 | p e o | p
| 4 m 4 a c 4 c 6 a 4 v k s 0 | i d t | o
----------+-----------------------------+-------+-------
[I]1.0.11 | + + + ~ + + + + ~ ~ ~ o ~ ~ | 7 o 0 | gentoo
real 0m2,236s
user 0m2,108s
sys 0m0,124s |
Although there is a little caveat sometimes:
You don't need to write the full package name,
but if get more than you want Code: | # mygshow dev-python/pycurl
MERGED G dev-python/pycurl-7.43.0.6-r0
gentoo s dev-python/pycurl-7.43.0.6-r0
gentoo u dev-python/pycurl-7.44.0-r0
gentoo u dev-python/pycurl-requests-0.2.0-r0
gentoo u dev-python/pycurl-requests-0.2.1-r0 | ... the only way around that obstacle is to add to the search term: Code: | # mygshow dev-python/pycurl-[0-9]
MERGED G dev-python/pycurl-7.43.0.6-r0
gentoo s dev-python/pycurl-7.43.0.6-r0
gentoo u dev-python/pycurl-7.44.0-r0 |
|
|
Back to top |
|
|
|