Thanks for the good work. Here my version with some minor changes.
file is meant to be /usr/local/bin/lsxzmgrep
Code: Select all
root@porteus:~# md5sum /usr/local/bin/lsxzmgrep
0a88e959966b3dbb6f8dc2b91534733c /usr/local/bin/lsxzmgrep
Dr. Copy & Mr. Paste here:
Code: Select all
#!/bin/bash
# https://forum.porteus.org/viewtopic.php?p=67979#p67979 brokenman
# https://forum.porteus.org/viewtopic.php?p=3522#p3522 82issa
# https://forum.porteus.org/viewtopic.php?p=80427#p80427 Ed_P
# https://forum.porteus.org/viewtopic.php?p=80384#p80384 &
# https://forum.porteus.org/viewtopic.php?p=80428#p80428 Rava
VERSION=2020-12-17
echo -n $(tput sgr0)
echo $(tput bold)$(tput setaf 3)lsxzmgrep$(tput sgr0) V$(tput setaf 3)${VERSION}$(tput sgr0)
if [ $# -ne 2 ]; then
echo $(tput bold)$(tput setaf 1)No xzm name and grep search pattern specified.$(tput sgr0)
exit 1
fi
if [ `whoami` != "root" ]; then
echo "Enter root's password" $(tput bold) $(tput setaf 1)
su -c "/bin/bash $0 $1 $2"
echo -n $(tput sgr0)
exit 0
fi
for module in $(find $1 -type f -name "*.xzm"); do
lsxzm ${module} | grep "$2" | sed -r "s#.+#>${module}\n&#"
done
When run as guest and using | e.g. for |tail the bold red of Password: is not displayed.
Without any | all looks normal:
guest@porteus:/mnt/sda4/TEST$ lsxzmgrep . /usr/
lsxzmgrep V2020-12-17
Enter root's password
Password:
lsxzmgrep V2020-12-17
>./032-webp-pixbuf-loader-20191003.fb04954-x86_64-1_slonly.xzm
/usr/doc
>./032-webp-pixbuf-loader-20191003.fb04954-x86_64-1_slonly.xzm
/usr/doc/webp-pixbuf-loader-20191003.fb04954
[…]
, but with |tail
guest@porteus:/mnt/sda4/TEST$ lsxzmgrep . /usr/|tail
Password:
/usr/share/locale/ru
>./florence-0.6.3-x86_64-1_slonly.xzm
/usr/share/locale/ru/LC_MESSAGES
>./florence-0.6.3-x86_64-1_slonly.xzm
/usr/share/locale/ru/LC_MESSAGES/florence.mo
>./florence-0.6.3-x86_64-1_slonly.xzm
/usr/share/pixmaps
>./florence-0.6.3-x86_64-1_slonly.xzm
/usr/share/pixmaps/florence.svg
Password: is printed plain. Also observe that the info output of
Code: Select all
echo $(tput bold)$(tput setaf 3)lsxzmgrep$(tput sgr0) V$(tput setaf 3)${VERSION}$(tput sgr0)
is omitted.
Also: known bugs:
you can specify a single module via
or via
Code: Select all
lsxzmgrep /path/to/module.xzm pattern
or all modules in a folder via
when you are in said folder or via
Code: Select all
lsxzmgrep /path/to/modules/folder/ pattern
when you are not.
But for now you cannot specify specific modules:
Code: Select all
lsxzmgrep /path/to/module1.xzm /anotherpath/to/module2.xzm pattern
will fail.
And finally, if you do not want any non-root user able to execute lsxzmgrep you do not have to change the code.
Just do the following as root:
Code: Select all
root@porteus:/usr/local/bin# chown root.root lsxzmgrep
root@porteus:/usr/local/bin# chmod 0744 lsxzmgrep
Check as root:
Code: Select all
root@porteus:/usr/local/bin# ls -l lsxzmgrep
-rwxr--r-- 1 root root 807 Dec 17 06:43 lsxzmgrep
root@porteus:/usr/local/bin# lsxzmgrep
lsxzmgrep V2020-12-17
No xzm name and grep search pattern specified.
Check as guest:
Code: Select all
guest@porteus:/mnt/sda4/TEST$ lsxzmgrep . /usr/
bash: /usr/local/bin/lsxzmgrep: Permission denied
When you want guest or any other non-root user able to execute lsxzmgrep I recommend this:
Code: Select all
root@porteus:/usr/local/bin# chown root.root lsxzmgrep
root@porteus:/usr/local/bin# chmod 0755 lsxzmgrep
root@porteus:/usr/local/bin# ls -l lsxzmgrep
-rwxr-xr-x 1 root root 807 Dec 17 06:43 lsxzmgrep
I could even upload both versions as modules, one with lsxzmgrep set with chmod 0744 and one set with chmod 0755. But in my book that would be overkill.