You are not logged in.

#1 2021-08-19 13:52:39

PowaBanga
Member
Registered: 2021-04-05
Posts: 15

Bash script to check if package(s) with number version exist in repo

Hi everybody,
I am on Archlinux, with a custom repository, and i am trying to do a little script to check if the package existing in the repository path.

So my problem in my while, is find the good regex to put in my condition to make it work with all packages


for i in $(pacman -Slq customrepo)
	do
		if [ -f /customrepo/$i-[0-9A-Za-z]*.pkg.tar.* ]
			then
				echo "$i exist"
			else
				echo "$i Don't !"
		fi
done

For exemple, after launch my complete script with bash -x, for "insync" i have this error message :

+ '[' -f /repository/insync-3.5.1.50115-1-x86_64.pkg.tar.zst /repository/insync-nemo-3.4.0.40973-1-any.pkg.tar.zst ']'
/home/powabanga/Documents/trucs/pkbuilds/kawacheck: line 3: [: /repository/insync-3.5.1.50115-1-x86_64.pkg.tar.zst: binary operator expected

Does anybody can help me to find what should i writte to not have any errors ?

I post here some usefull info if anybody want to help me.

pacman -Slq customrepo
aic94xx-firmware
antimicrox
arc-icon-theme-git
aurutils
b00merang-ios-13-gtk-theme
b00merang-windows-10-dark-gtk-theme
b00merang-windows-10-dark-icons-theme
b00merang-windows-10-gtk-theme
b00merang-windows-10-icons-theme
b00merang-windows-7-gtk-theme
b00merang-windows-7-icons-theme
b00merang-windows-xp-gtk-theme
b00merang-windows-xp-icons-theme
bindfs
brother-mfc-j5330dw
brscan4
buuf-nestort-icons-theme
cinnamon-sound-effects
cnijfilter-mp250
debtap
dhewm3
dxvk-bin
epsxe
epsxe-plugin-gpu-mesagl
epsxe-plugin-gpu-soft
epsxe-plugin-padjoy
epsxe-plugin-spu-alsa
esound
exe-thumbnailer
ffmpeg3.4
gconf
geforcenow-nativefier
glib
gnome-dds-thumbnailer
gnome-directory-thumbnailer
gnome-source-thumbnailer-git
gnome-web-shortcuts-extension-git
gnome-xcf-thumbnailer
google-chrome
gosync-git
gtupdater
hexchat-python2
hid-nintendo-dkms
hid-nintendo-nso-dkms
httpfs2-2gbplus
humanity-icon-theme
iat
insync
insync-nemo
jmtpfs
jstest-gtk-git
kawa-BM
kawa-Banga
kawa-intel
kawa-nvidia
kawa-nvidia-lts
kawa-papaetmaman
kawa-wine
kawaOS
lib32-aom
lib32-babl
lib32-blas
lib32-cblas
lib32-dav1d
lib32-exiv2
lib32-ffmpeg
lib32-gegl
lib32-gimp
lib32-gsm
lib32-imath
lib32-jasper
lib32-l-smash
lib32-lame
lib32-lapack
lib32-lapacke
lib32-lensfun
lib32-libass
lib32-libbluray
lib32-libdav1d
lib32-libde265
lib32-libexif
lib32-libffmpeg
lib32-libgexiv2
lib32-libheif
lib32-libmng
lib32-libmypaint
lib32-libraw
lib32-libspiro
lib32-libusb-compat
lib32-libvmaf
lib32-libwmf
lib32-libxpm
lib32-luajit
lib32-metis
lib32-mpfr
lib32-numactl
lib32-opencore-amr
lib32-openexr
lib32-openjpeg2
lib32-poppler
lib32-poppler-glib
lib32-srt
lib32-suitesparse
lib32-tbb
lib32-vmaf
lib32-x264
lib32-x265
lib32-xvidcore
libbfio-git
liblightdm-qt5-guest
liblnk-tools-git
libreoffice-extension-grammalecte-fr
libvncserver-git
lightdm-guest
lightdm-guest-account
lightdm-webkit2-theme-material2
megasync-nopdfium
mint-sounds
mint-themes
mint-x-icons
mint-y-icons
mkinitcpio-archiso-git
msitools
nodejs-nativefier
optimus-manager
optimus-manager-qt
pangox-compat
powershell
proftpd
python-liblnk-git
python-sentry_sdk
python-spotipy
python2-bcrypt
qt5-styleplugins
rclone-browser
rclonesync-git
realvnc-vnc-server
rtl8821ce-dkms-git
scangearmp-mp250series
scangearmp-mp270series
scangearmp-mp490series
scangearmp-mp550series
scangearmp-mp560series
scangearmp-mp640series
scangearmp-mpseries-common
screenrotator-git
sdx
skypeforlinux-stable-bin
spotify
spotify-adkiller-git
spotify_dl
srain
sublime-text-4
syncthing-gtk
tango-icon-theme
tclkit
teams
teamviewer
ttf-ms-fonts
ttf-vista-fonts
tuxtype
ubuntu-themes
ufraw-thumbnailer
upd72020x-fw
vgrive
wd719x-firmware
x11vnc-git
xampp
xboxdrv
yaru-gnome-shell-theme
yaru-gtk-theme
yaru-gtksourceview-theme
yaru-icon-theme
yaru-metacity-theme
yaru-session
yaru-sound-theme
yaru-unity-theme
yay
zoom
ls /customrepo
aic94xx-firmware-30-9-any.pkg.tar.zst                            lib32-libvmaf-1.5.3-1-x86_64.pkg.tar.zst
antimicrox-3.1.6-1-x86_64.pkg.tar.zst                            lib32-libwmf-0.2.12-2-x86_64.pkg.tar.zst
arc-icon-theme-git-20161122-1-any.pkg.tar.zst                    lib32-libxpm-3.5.13-2-x86_64.pkg.tar.zst
aurutils-3.1.2-2-any.pkg.tar.zst                                 lib32-l-smash-2.14.5-1-x86_64.pkg.tar.zst
b00merang-ios-13-gtk-theme-2.0-2-any.pkg.tar.zst                 lib32-luajit-2.0.5-1-x86_64.pkg.tar.zst
b00merang-windows-10-dark-gtk-theme-3.2-1-any.pkg.tar.zst        lib32-metis-5.1.0.p3-1-x86_64.pkg.tar.zst
b00merang-windows-10-dark-icons-theme-1.0-2-any.pkg.tar.zst      lib32-mpfr-4.1.0.p13-1-x86_64.pkg.tar.zst
b00merang-windows-10-gtk-theme-3.2-2-any.pkg.tar.zst             lib32-numactl-2.0.14-1-x86_64.pkg.tar.zst
b00merang-windows-10-icons-theme-1.0-2-any.pkg.tar.zst           lib32-opencore-amr-0.1.5-3-x86_64.pkg.tar.zst
b00merang-windows-7-gtk-theme-3.2-1-any.pkg.tar.zst              lib32-openexr-3.0.5-1-x86_64.pkg.tar.zst
b00merang-windows-7-icons-theme-1.0-1-any.pkg.tar.zst            lib32-openjpeg2-2.4.0-1-x86_64.pkg.tar.zst
b00merang-windows-xp-gtk-theme-3.1-1-any.pkg.tar.zst             lib32-poppler-21.08.0-1-x86_64.pkg.tar.zst
b00merang-windows-xp-icons-theme-1.0-1-any.pkg.tar.zst           lib32-poppler-glib-21.08.0-1-x86_64.pkg.tar.zst
bindfs-1.14.7-1-x86_64.pkg.tar.zst                               lib32-srt-1.4.3-1-x86_64.pkg.tar.zst
brother-mfc-j5330dw-1.0.1-4-x86_64.pkg.tar.zst                   lib32-suitesparse-5.10.0-1-x86_64.pkg.tar.zst
brscan4-0.4.10_1-5-x86_64.pkg.tar.zst                            lib32-tbb-2020.3-2-x86_64.pkg.tar.zst
buuf-nestort-icons-theme-2.0-1-any.pkg.tar.zst                   lib32-vmaf-1.5.3-1-x86_64.pkg.tar.zst
cinnamon-sound-effects-5.7-1-any.pkg.tar.zst                     lib32-x264-3:0.161.r3039.544c61f-2-x86_64.pkg.tar.zst
cnijfilter-mp250-3.40.1-5.1-x86_64.pkg.tar.zst                   lib32-x265-3.5-1-x86_64.pkg.tar.zst
debtap-3.4.2-1-any.pkg.tar.zst                                   lib32-xvidcore-1.3.7-2-x86_64.pkg.tar.zst
dhewm3-1.5.1-1-x86_64.pkg.tar.zst                                libbfio-git-20210815.3bb082c-1-any.pkg.tar.zst
dxvk-bin-1.9.1-1-x86_64.pkg.tar.zst                              liblightdm-qt5-guest-1:1.30.0-3-x86_64.pkg.tar.zst
epsxe-2.0.5-27-x86_64.pkg.tar.zst                                liblnk-tools-git-20210417.r0.g0c9a2c8-1-x86_64.pkg.tar.zst
epsxe-plugin-gpu-mesagl-1.78-5-x86_64.pkg.tar.zst                libreoffice-extension-grammalecte-fr-2.1.2-1-any.pkg.tar.zst
epsxe-plugin-gpu-soft-1.18-2-x86_64.pkg.tar.zst                  libvncserver-git-0.9.13.r30.g0ac531ed-1-x86_64.pkg.tar.zst
epsxe-plugin-padjoy-0.82-4-x86_64.pkg.tar.zst                    lightdm-guest-1:1.30.0-3-x86_64.pkg.tar.zst
epsxe-plugin-spu-alsa-1.9-6-x86_64.pkg.tar.zst                   lightdm-guest-account-1.30.0-4-any.pkg.tar.zst
esound-0.2.41-4-x86_64.pkg.tar.zst                               lightdm-webkit2-theme-material2-0.0.5-1-any.pkg.tar.zst
exe-thumbnailer-0.10.1-1-any.pkg.tar.zst                         megasync-nopdfium-4.5.3.0-1-x86_64.pkg.tar.zst
ffmpeg3.4-3.4.8-3-x86_64.pkg.tar.zst                             mint-sounds-2.1.8.2-1-any.pkg.tar.zst
gconf-3.2.6+11+g07808097-10-x86_64.pkg.tar.zst                   mint-themes-1.8.8-1-any.pkg.tar.zst
geforcenow-nativefier-20201122-1-x86_64.pkg.tar.zst              mint-x-icons-1.6.3-1-any.pkg.tar.zst
glib-1.2.10-18-x86_64.pkg.tar.zst                                mint-y-icons-1.5.8-1-any.pkg.tar.zst
gnome-dds-thumbnailer-2016.02.19-1-any.pkg.tar.zst               mkinitcpio-archiso-git-58.r0.gbdad4a1-1-any.pkg.tar.zst
gnome-directory-thumbnailer-0.1.11-1-x86_64.pkg.tar.zst          msitools-0.101-3-x86_64.pkg.tar.zst
gnome-source-thumbnailer-git-r10.6bacb2d-1-any.pkg.tar.zst       nodejs-nativefier-45.0.0-1-any.pkg.tar.zst
gnome-web-shortcuts-extension-git-r16.2d89c1e-2-any.pkg.tar.zst  optimus-manager-1.4-2-any.pkg.tar.zst
gnome-xcf-thumbnailer-1.0-10-x86_64.pkg.tar.zst                  optimus-manager-qt-1.6.4-1-x86_64.pkg.tar.zst
google-chrome-92.0.4515.159-1-x86_64.pkg.tar.zst                 pangox-compat-0.0.2+2+gedb9e09-3-x86_64.pkg.tar.zst
gosync-git-0.4-1-any.pkg.tar.zst                                 powershell-7.1.3-1-x86_64.pkg.tar.zst
gtupdater-1.1-1-any.pkg.tar.zst                                  proftpd-2:1.3.7b-1-x86_64.pkg.tar.zst
hexchat-python2-2.14.3-1-x86_64.pkg.tar.zst                      python2-bcrypt-3.1.7-4-x86_64.pkg.tar.zst
hid-nintendo-dkms-3.2-2-any.pkg.tar.zst                          python-liblnk-git-20210417.r0.g0c9a2c8-1-x86_64.pkg.tar.zst
hid-nintendo-nso-dkms-1.2-1-x86_64.pkg.tar.zst                   python-sentry_sdk-1.3.1-1-any.pkg.tar.zst
httpfs2-2gbplus-0.1.5-1-x86_64.pkg.tar.zst                       python-spotipy-2.19.0-1-any.pkg.tar.zst
humanity-icon-theme-0.6.15-1-any.pkg.tar.zst                     qt5-styleplugins-5.0.0.20170311-26-x86_64.pkg.tar.zst
iat-0.1.7-4-x86_64.pkg.tar.zst                                   rclone-browser-1.8.0-2-x86_64.pkg.tar.zst
insync-3.5.1.50115-1-x86_64.pkg.tar.zst                          rclonesync-git-3.2.r3.gae6e71d-1-any.pkg.tar.zst
insync-nemo-3.4.0.40973-1-any.pkg.tar.zst                        realvnc-vnc-server-6.7.4-1-x86_64.pkg.tar.zst
jmtpfs-0.5-2-x86_64.pkg.tar.zst                                  rtl8821ce-dkms-git-1.0.5.r128.gf93db73-1-x86_64.pkg.tar.zst
jstest-gtk-git-0.1.0.r115.g420317b-1-x86_64.pkg.tar.zst          scangearmp-mp250series-1.40-11-x86_64.pkg.tar.zst
kawa-Banga-1.1-3-any.pkg.tar.zst                                 scangearmp-mp270series-1.40-11-x86_64.pkg.tar.zst
kawa-BM-0.4-1-any.pkg.tar.zst                                    scangearmp-mp490series-1.40-11-x86_64.pkg.tar.zst
kawa.db                                                          scangearmp-mp550series-1.40-11-x86_64.pkg.tar.zst
kawa.db.tar.gz                                                   scangearmp-mp560series-1.40-11-x86_64.pkg.tar.zst
kawa.files                                                       scangearmp-mp640series-1.40-11-x86_64.pkg.tar.zst
kawa.files.tar.gz                                                scangearmp-mpseries-common-1.40-11-x86_64.pkg.tar.zst
kawa-intel-0.4-5-any.pkg.tar.zst                                 screenrotator-git-1:r25.e1de8b7-1-x86_64.pkg.tar.zst
kawa-nvidia-0.1-1-any.pkg.tar.zst                                sdx-20110317-1-any.pkg.tar.zst
kawa-nvidia-lts-0.1-1-any.pkg.tar.zst                            skypeforlinux-stable-bin-8.75.0.140-1-x86_64.pkg.tar.zst
kawaOS-2-6-any.pkg.tar.zst                                       spotify-1:1.1.56.595-1-x86_64.pkg.tar.zst
kawa-papaetmaman-0.4-1-any.pkg.tar.zst                           spotify-adkiller-git-r177.2dabf81-1-any.pkg.tar.zst
kawa-wine-0.6-1-any.pkg.tar.zst                                  spotify_dl-v7.6.0.r3.g836929c-1-any.pkg.tar.zst
lib32-aom-3.1.1-1-x86_64.pkg.tar.zst                             srain-1:1.2.4-1-x86_64.pkg.tar.zst
lib32-babl-0.1.86-1-x86_64.pkg.tar.zst                           sublime-text-4-4.4113-1-x86_64.pkg.tar.zst
lib32-blas-3.9.0-1-x86_64.pkg.tar.zst                            syncthing-gtk-1:0.9.4.4-2-any.pkg.tar.zst
lib32-cblas-3.9.0-1-x86_64.pkg.tar.zst                           tango-icon-theme-0.8.90-14-any.pkg.tar.zst
lib32-dav1d-0.9.1-1-x86_64.pkg.tar.zst                           tclkit-8.6.11-1-x86_64.pkg.tar.zst
lib32-exiv2-0.27.3-2-x86_64.pkg.tar.zst                          teams-1.4.00.13653-1-x86_64.pkg.tar.zst
lib32-ffmpeg-2:4.4-2-x86_64.pkg.tar.zst                          teamviewer-15.20.6-1-x86_64.pkg.tar.zst
lib32-gegl-0.4.30-2-x86_64.pkg.tar.zst                           ttf-ms-fonts-2.0-12-any.pkg.tar.zst
lib32-gimp-2.10.24-2-x86_64.pkg.tar.zst                          ttf-vista-fonts-1-10-any.pkg.tar.zst
lib32-gsm-1.0.19-1-x86_64.pkg.tar.zst                            tuxtype-1.8.1-1-x86_64.pkg.tar.zst
lib32-imath-3.1.2-1-x86_64.pkg.tar.zst                           ubuntu-themes-20.10-2-any.pkg.tar.zst
lib32-jasper-2.0.33-1-x86_64.pkg.tar.zst                         ufraw-thumbnailer-0.2-2-any.pkg.tar.zst
lib32-lame-3.100-2-x86_64.pkg.tar.zst                            upd72020x-fw-20200826-3-any.pkg.tar.zst
lib32-lapack-3.9.0-1-x86_64.pkg.tar.zst                          vgrive-1.6.1-5-x86_64.pkg.tar.zst
lib32-lapacke-3.9.0-1-x86_64.pkg.tar.zst                         wd719x-firmware-1-7-any.pkg.tar.zst
lib32-lensfun-0.3.95-2-x86_64.pkg.tar.zst                        x11vnc-git-1:0.9.16.r38.gad85c2c-1-x86_64.pkg.tar.zst
lib32-libass-0.14.0-3-x86_64.pkg.tar.zst                         xampp-8.0.9-1-x86_64.pkg.tar.zst
lib32-libbluray-1.3.0-1-x86_64.pkg.tar.zst                       xboxdrv-0.8.8-6-x86_64.pkg.tar.zst
lib32-libdav1d-0.9.1-1-x86_64.pkg.tar.zst                        yaru-gnome-shell-theme-21.10.1-1-any.pkg.tar.zst
lib32-libde265-1.0.8-1-x86_64.pkg.tar.zst                        yaru-gtksourceview-theme-21.10.1-1-any.pkg.tar.zst
lib32-libexif-0.6.22-1-x86_64.pkg.tar.zst                        yaru-gtk-theme-21.10.1-1-any.pkg.tar.zst
lib32-libffmpeg-2:4.4-2-x86_64.pkg.tar.zst                       yaru-icon-theme-21.10.1-1-any.pkg.tar.zst
lib32-libgexiv2-0.12.2-1-x86_64.pkg.tar.zst                      yaru-metacity-theme-21.10.1-1-any.pkg.tar.zst
lib32-libheif-1.12.0-1-x86_64.pkg.tar.zst                        yaru-session-21.10.1-1-any.pkg.tar.zst
lib32-libmng-2.0.3-1-x86_64.pkg.tar.zst                          yaru-sound-theme-21.10.1-1-any.pkg.tar.zst
lib32-libmypaint-1.6.1-1-x86_64.pkg.tar.zst                      yaru-unity-theme-21.10.1-1-any.pkg.tar.zst
lib32-libraw-0.20.2-3-x86_64.pkg.tar.zst                         yay-10.3.1-1-x86_64.pkg.tar.zst
lib32-libspiro-20200505-1-x86_64.pkg.tar.zst                     zoom-5.7.5-1-x86_64.pkg.tar.zst
lib32-libusb-compat-0.1.7-4-x86_64.pkg.tar.zst

Hoping to find some help here smile

Offline

#2 2021-08-19 14:16:50

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 25,723
Website

Re: Bash script to check if package(s) with number version exist in repo

This is definitely an X-Y problem - you have shown us how you are working on 'Y' but I can't even imagine what 'X' is.  What is your end goal?

You're having pacman list all packages in the repo but explicitly telling it to not list version numbers ... then you are checking if each one of those exists with *any* version number?  Well, of course they do.

Are you trying to find mismatches between the packages and/or versions in the repo db and the actual file content?  If so, there are definitely better ways.

Do you wan to see which packages exist in a local cache with version numbers?  If so, there are definitely better ways, e.g. ask pacman where it'd get the package (and check if they are http(s):// or file:// sources):

 pacman -Slq customrepo | pacman -S --print -

That said, the likely problem with your script is that you need to quote the variable ... that would likely avoid the shell error, but I still don't see how the whole thing would do anything useful.

You can throw a bit of sed at the output of the last command if you really want it formated in a not-so-useful way:

pacman -Slq customrepo | pacman -S --print - | sed "s|file:///var/cache/pacman/pkg/|Exists: |;s|http.*/os/x86_64/|Doesn't: |"

But I suspect in reality you don't want to print "Exists" or "Doesn't" but instead just filter with grep for what you actually need, e.g instead of sed:

... | grep -v '^file:///'

Last edited by Trilby (2021-08-19 14:27:29)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2021-08-19 15:27:33

PowaBanga
Member
Registered: 2021-04-05
Posts: 15

Re: Bash script to check if package(s) with number version exist in repo

hm...
in fact, there is two goals of this script :
(in my case the repository path is /repository , and the repository name is "kawa)

  • First : use it to build a table, with column who check "X" or "V" if the package exist in :

    • Build directory (path where i build all my packages with makepkg command

    • Repository database (does it exist in pacman -Sl custom repo command ?)

    • Repository path (if package is not in the folder with my customrepo.db, I will cannot install it with "pacman -S")

    • AUR repository (it can be useful to know if the package exist in aur or not )

    Here is my full script :

    check-AUR-vs-kawadb ()
    {
    	sudo pacman -Sy
    	echo -e "aa.Pakages;A;L;D;R\033[0m"
    	for i in $(pacman -Slq kawa)
    		do
    			#Checkin for the presence of a kawa's package in AUR
    			curl -s https://aur.archlinux.org/packages/$i | grep -e "[pP]age [Nn]ot [Ff]ound"
    			presence=$?
    			if [ $presence = 1 ]
    				then 
    					AUR="\033[32m\033[1mV\033[0m\033[0m"
    					AURNAME=$(curl -s https://aur.archlinux.org/packages/$i | grep -e https://aur.archlinux.org/[.]* | grep -e "\.git" | sed "s/(.*)//g ; s/.git<.*>//g ; s/\t*<a.*.\">https:\/\/aur.archlinux.org\///g ; s/ //g" )
    				else
    					AUR="\033[31m\033[1mX\033[0m\033[0m"
    			fi
    			# From pacman -Sl repo :
    			# is there a PKGBUILD in the build path ?
    			if [ $presence = 1 ]
    				then
    					if [ -f $AURNAME/PKGBUILD ]
    						then
    							dossier="\033[32m\033[1mV\033[0m\033[0m"
    						else
    							dossier="\033[31m\033[1mX\033[0m\033[0m"
    					fi
    				else
    
    					if [ -f $i/PKGBUILD ]
    						then
    							dossier="\033[32m\033[1mV\033[0m\033[0m"
    						else
    							dossier="\033[31m\033[1mX\033[0m\033[0m"
    					fi
    			fi
    			# Package is it in the repository path ?
    			if [ -f $REPOPATH/$i-[0-9A-Za-z]*.pkg.tar.* ]
    				then
    					repo="\033[32m\033[1mV\033[0m\033[0m"
    				else
    					repo="\033[31m\033[1mX\033[0m\033[0m"
    			fi
    		echo -e "$i;$AUR;$dossier;\033[32m\033[1mV\033[0m\033[0m;$repo"
    		done
    	# Here, will be added a ligne to show local folders from build path to show package under construction who are not in repository's data base.
    	for o in $(ls $BUILDPATH | sed '/kawaupd/d ; /kawaremove/d ; /liste/d ; /kawaadd/d ; /kawacheck/d ; /.log/d ; /.bkp/d')
    		do
    		echo $o
    			# from ls $BUILDPATH, the folder's name :
    			# is it in the database ?
    			if [ -z $(pacman -Slq kawa | grep -x $o) ]
    				then
    										if [ -z $(pacman -Slq kawa | grep $ISIT) ]
    						then
    							KAWA="\033[31m\033[1mX\033[0m\033[0m"
    						else
    						# If it do not work with folder's name : chack via package name...
    						# ! Should probably done sytematicly... ? !
    							ISIT=$(cat $BUILDPATH/$o/PKGBUILD |grep -e "^pkgname=" | sed 's/pkgname=//g ; s/(//g ; s/)//g ; s/ //g' | sed -e 's/'\''//g')
    							if [ $ISIT = $(pacman -Slq kawa | grep $ISIT) ]
    								then
    									KAWA="\033[92m\033[1mV\033[0m\033[0m"
    								else
    									KAWA="\033[31m\033[1mX\033[0m\033[0m"
    							fi
    			fi
    			# Is it in AUR ?
    			curl -s https://aur.archlinux.org/packages/$o | grep -e "[pP]age [Nn]ot [Ff]ound"
    			presence=$?
    			if [ $presence = 1 ]
    				then 
    					AUR="\033[32m\033[1mV\033[0m\033[0m"
    				else
    					AUR="\033[31m\033[1mX\033[0m\033[0m"
    			fi
    			# Is the package in the repository path ?
    			if [ -f $REPOPATH/$o.*.pkg.tar.* ]
    				then
    					repo="\033[32m\033[1mV\033[0m\033[0m"
    				else
    					repo="\033[31m\033[1mX\033[0m\033[0m"
    			fi
    			echo -e "$o;$AUR;\033[92m\033[1mV\033[0m\033[0m;$KAWA;$repo"
    	fi
    
    done
    }
    
    REPOPATH="/repository"
    
    BUILDPATH=$PWD
    
    
     echo -e "\033[1mA=AUR L=Local D=DataBase R=Repository"
     check-AUR-vs-kawadb | sed '/;/!d' | sort | column -t -s ";"
  • Second : use it to find duplicate package in my repository path. I do not want to keep packages whose version is obsolete.
    here is the script :

    REPOPATH="/repository"
    for i in $(pacman -Slq kawa | sed 's/ //g')
    	do
    		if [ $(ls $REPOPATH | grep -e "^$i-[0-9]-*" | wc -l) -gt 1 ]
    			then
    				for e in $(ls $REPOPATH | grep -e "^$i-[0-9]-*"  | sort -V | sed '$d')
    					do
    					rm -rf $REPOPATH/$e
    					echo "une ancienne version de $i à été supprimée"
    				done	
    		fi 
    done

Offline

#4 2021-08-19 15:48:25

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 25,723
Website

Re: Bash script to check if package(s) with number version exist in repo

I'd *strongly* advise drastically simplifying that script at every level.  Most notably, do not loop through every package, and do every check each time through the loop.  Most (if not all) of those checks can be done as a single batch.  Specifically for that last code box seems to loop through all possible entries and for each one it does an ls, grep, wc, then another for loop dependening on the output of that.  This could result in thousands of processes when only a few are necessary.  I have no idea what that sed is for after pacman -Slq: package names can't have spaces, so the sed is a no-op.  But in addition to that, there's no reason to get the list of packages from the repo: the goal seems to be to remove all but the most recent version of each package in REPOPATH.

The below is a good start at doing that without the loops.  I've left out the deletion as you should check the results first - but this should give the list of deletion candidates.  No loops, and just three processes regardless of how many packages are in the repo.

find  $REPOPATH -maxdepth 1 -printf %f\\n | sort -rV | awk '$1 == lastpkg; { lastpkg = $1; }'

Actually, I wouldn't be surprised if there weren't pacman or pacman-contrib tools to do this too - but I've never maintained my own repo - but certainly loops within loops with countless commands are not necessary.  And all that unnecessry code makes troubleshooting very difficult.  Simplify first.

EDIT:  And now I've just realized this is *exactly* what paccache does: use that instead!

paccache -c $REPOPATH -rk1

Last edited by Trilby (2021-08-19 15:52:30)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

Board footer

Powered by FluxBB