Author Topic: Need a script to query and remove parts in several lines  (Read 538 times)

Offline Archie

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8590
  • Aurum nostrum non est aurum vulgi.
Need a script to query and remove parts in several lines
« on: July 23, 2012, 01:14:24 AM »
Having all the development libraries installed on our build environment makes is easy to our packages but quite often many of these won't be listed on the BuildRequire: section of our specfile. IMO it is not a good practice.

I used to leave the devels on my build environment after packaging. I am changing my habits that after every successful or failed builds, I would remove whatever was required to build the previous package hence a close-to-clean build environment. I don't mind it this way.

Before starting with a package, I would generate a list of what the package requires to be built. I save it on a text file. I would use the same text file to remove what were installed.

The problem is quite often the list can be hundreds of lines. Every line on the list is in two parts - the package name and enclosed in parenthesis is the version-release-id-year. We all know that to install from the command line, we # apt-get install <package> and to remove we # pat-get remove <package>.

Code: [Select]
...
207 libmtp-devel
208 libncursesw-devel
209 libnotify4-devel
210 libogg-devel
211 liboggz-devel
212 liboggz1
213 liboldx6 (1.0.1-5pclos2007)
214 liboldx6-devel (1.0.1-5pclos2007)
215 libopencdk-devel (0.6.6-1pclos2009)
216 libopencdk10 (0.6.6-1pclos2009)
217 libopencore-amrnb-devel (0.1.2-1pclos2010)
...

The above example shows that I have manually removed those "extras" up to line 212 and still have more to go. I know there's an easier way to edit the list of packages and remove the parenthesis and the version-release-id-year in between.

I just realized this and I'm pretty sure that if I spend a bit more time in thought on it (with the help of the Internet), I would come up with a solution. But since I think this might also benefit some (if any) of our packagers, it would be a good exercise for those in the know to help out.

EDIT:
BTW none of the pkgutils-kde (don't know about thunar) service menus have this.
« Last Edit: July 23, 2012, 01:55:57 AM by Archie »
Since 2006 | LiCo 401868 | Bare Metal | What is necessary is never unwise. --Sarek, 2258.42


Offline Archie

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8590
  • Aurum nostrum non est aurum vulgi.
Re: Need a script to query and remove parts in several lines
« Reply #1 on: July 23, 2012, 02:17:30 AM »
Never mind ...

it was just a simple:

Code: [Select]
echo -n "Enter filename: "
read file

cat $file | grep devel | cut -d ' ' -f1 > $file

Now, I'd have to automatically add a trailing <space>\ after the suffix devel, and I'm done.

EDIT:
The problem with this is if the package line does not have devel in it are not included on the output .... Hmmmm  :-\
« Last Edit: July 23, 2012, 02:22:12 AM by Archie »
Since 2006 | LiCo 401868 | Bare Metal | What is necessary is never unwise. --Sarek, 2258.42


Offline ghostbunny

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 1164
Re: Need a script to query and remove parts in several lines
« Reply #2 on: July 23, 2012, 02:21:24 AM »
hi Archie,

i use this script i wrote

Code: [Select]
#!/bin/bash

TEXT="Insert dependencies to uninstall"

DEPENDS=$(yad --entry --editable --entry-label="$TEXT" --title="uninstallDependencies" --width=400 --height=50)

if [ $? -eq 0 ]; then

DEPENDS=$(echo "$DEPENDS" | sed 's/(.*)//g')
DEPENDS=$(echo "$DEPENDS" | tr -d '\n')

apt-get remove --purge -y $DEPENDS
else
exit 1
fi

exit 0

but i have to say i use a very old school way.

I do install deps manually and uninstall them via this script by copying the packages i installed from the synamtic history


btw. why do you want to uninstall only devel files and not everything you installed for the build?
« Last Edit: July 23, 2012, 02:26:49 AM by ghostbunny »
The full life is a big mess

PS:
I'm German. Sorry because of possible mistakes in my written messages xD


Offline Archie

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8590
  • Aurum nostrum non est aurum vulgi.
Re: Need a script to query and remove parts in several lines
« Reply #3 on: July 23, 2012, 03:02:59 AM »
Heya ghostbunny,

I, too am very old school and I use the konsole all the time. I don't depend on the right-clicks on the context menus, except for one - Install SRPM" ... and even that I have a shortcut for it. I mostly use bash shortcuts. "txz <filename.ext>" for converting a tar.gz to tar.xz, "rb <name>.spec>" for rpmbuild -ba <name>.spec", etc. Even my entry for %changelog is handled by a simple "csig" and all I have to change is the version-release + the actual changelog.

I first "rb <name>.spec and I get a list of BuildRequires. I copy and paste these to a text file, remove all the extras inside the parenthesis and add a trailing \ at the end of each line. The I select all and Ctrl+c.

On the Konsole, I just type agi then Ctrl+v and I get a more extensive list of what are actually going to be installed for the build. Again, I repeat the process of copy and paste to a text file, remove all the stuff between the parentheses, Ctrl+c, agr on Konsole, Ctrl+v and y to install all that is required.

After the build (whether it is successful or not), I agr Ctrl+v to remove all that was installed. then I type 123 to clean up the SPEC/, SOURCES, BUILD/ BUILDROOT/ and src/tmp leaving only the SRPM and the RPM.

I am used to this and I am looking for a way to cut down the time by quickly removing the extras between the parentheses.

I don't even have yad installed!  ;)

Since 2006 | LiCo 401868 | Bare Metal | What is necessary is never unwise. --Sarek, 2258.42


Offline ghostbunny

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 1164
Re: Need a script to query and remove parts in several lines
« Reply #4 on: July 23, 2012, 03:09:59 AM »
im not sure but i think there was a script in pkgutils to install everything required and with a option there was the possibility to create such a list i think. maybe check this so you dont have to create the list manually

its possible to replace yad by zenity or even by echo and read for the console gurus :D
« Last Edit: July 23, 2012, 03:27:08 AM by ghostbunny »
The full life is a big mess

PS:
I'm German. Sorry because of possible mistakes in my written messages xD


Offline Archie

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8590
  • Aurum nostrum non est aurum vulgi.
Re: Need a script to query and remove parts in several lines
« Reply #5 on: July 23, 2012, 03:47:45 AM »
im not sure but i think there was a script in pkgutils to install everything required and with a option there was the possibility to create such a list i think. maybe check this so you dont have to create the list manually

its possible to replace yad by zenity or even by echo and read for the console gurus :D

I don't think so either. Besides I rarely use the service menu. And yes again, I would prefer to use echo but don't even be fooled by my passionate use of the Konsole ... I am but a humble PCLOS user who just finds that some tasks are done faster using the Konsole .. too inexperienced to even be at the foot of any bash/zsh/tsh/vim/emac gurus ;)

But I'm gonna try your sed soon enough. :)
Since 2006 | LiCo 401868 | Bare Metal | What is necessary is never unwise. --Sarek, 2258.42


Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Need a script to query and remove parts in several lines
« Reply #6 on: July 23, 2012, 04:05:14 AM »
pkgutils has >>>     
right click - install dependencies & option to save the list of files (as .remove)
right click (on .remove file) -- SPEC dependency log for removal     

Offline Archie

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8590
  • Aurum nostrum non est aurum vulgi.
Re: Need a script to query and remove parts in several lines
« Reply #7 on: July 23, 2012, 04:45:13 AM »
pkgutils has >>>     
right click - install dependencies & option to save the list of files (as .remove)
right click (on .remove file) -- SPEC dependency log for removal     

I did a quick test, Neal. Dependencies were installed and opted to save the list of .remove files. Clicked Run rmvpkg and got mixed results. It said the build dependencies were removed but only one was actually removed. I still had to apt-get remove the rest.

It would be useful for the packagers if we can fix the service menus ... but in the meantime, I'll use the way that I think is more effective.
Since 2006 | LiCo 401868 | Bare Metal | What is necessary is never unwise. --Sarek, 2258.42


Offline ghostbunny

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 1164
Re: Need a script to query and remove parts in several lines
« Reply #8 on: July 23, 2012, 06:32:53 AM »
hey Archie,

what do you think about doing

Code: [Select]
rpm -qa

before the installation of the buildrequirements and than after it.

then compair the lists and look what are the differences maybe you can get this via diff.

after getting the list of differences you have also to replace the version things then you should have a list with the packeges which have to uninstalled after the build.
The full life is a big mess

PS:
I'm German. Sorry because of possible mistakes in my written messages xD


Offline Archie

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8590
  • Aurum nostrum non est aurum vulgi.
Re: Need a script to query and remove parts in several lines
« Reply #9 on: July 23, 2012, 09:30:17 AM »
Hi ghostbunny,

I am already doing too many steps, and I really don't need to get a list of the rpms installed prior to installing the buildreq for a package.

I just need to be able to remove the parentheses and everything in between.

My simple example is OK but only applies to lines with devels in them. If a line on the list doesn't have devel, say ImageMagick, it will be removed from the list and I don't want anything on the list removed, rather just the parentheses and what's in between them.

I haven't tried sed yet ... as there are other things I am doing right now ... I will later. Thanks.
Since 2006 | LiCo 401868 | Bare Metal | What is necessary is never unwise. --Sarek, 2258.42