Author Topic: Need to add scriptlet to %post  (Read 1459 times)

Offline Archie

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8821
  • Aurum nostrum non est aurum vulgi.
Need to add scriptlet to %post
« on: June 27, 2012, 11:54:43 PM »
I needed to add a scriptlet to %post and of course another to remove the files, and this should be on %postun.

I needed to copy a whole folder to the user's home folder

Code: [Select]
%post
/sbin/ldconfig
cp -R %_datadir/kde4/apps/plasma/plasmoids/veromix-plasmoid ~/.kde4/share/apps/plasma/plasmoids/

%postun
/sbin/ldconfig
rm -rf ~/.kde4/share/apps/plasma/plasmoids/veromix-plasmoid

The problem with this is when installing from Synaptic, the files would have to be copied to /root and the code fails. What I need is to copy the folder to the user's home folder.

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


Offline ghostbunny

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 1194
Re: Need to add scriptlet to %post
« Reply #1 on: June 28, 2012, 12:12:49 AM »
How about this

Code: [Select]
%post
/sbin/ldconfig
cp -R %_datadir/kde4/apps/plasma/plasmoids/veromix-plasmoid /home/*/.kde4/share/apps/plasma/plasmoids/

%postun
/sbin/ldconfig
rm -rf /home/*/.kde4/share/apps/plasma/plasmoids/veromix-plasmoid

maybe %post needs some better solution it copies the files also to /home/mysql and so on
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: 8821
  • Aurum nostrum non est aurum vulgi.
Re: Need to add scriptlet to %post
« Reply #2 on: June 28, 2012, 02:24:05 AM »
How about this

Code: [Select]
%post
/sbin/ldconfig
cp -R %_datadir/kde4/apps/plasma/plasmoids/veromix-plasmoid /home/*/.kde4/share/apps/plasma/plasmoids/

%postun
/sbin/ldconfig
rm -rf /home/*/.kde4/share/apps/plasma/plasmoids/veromix-plasmoid

maybe %post needs some better solution it copies the files also to /home/mysql and so on


Got the solution, ghosbunny. Instead of /home/* ... it was just a very simple /home/$USER ... and I didn't go ahead with the cp -R. Instead I opted for symlinks. I'm testing the app now. Thanks for your help.
Since 2006 | LiCo 401868 | Bare Metal | What is necessary is never unwise. --Sarek, 2258.42


Offline TerryN

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 740
Re: Need to add scriptlet to %post
« Reply #3 on: June 28, 2012, 03:10:48 AM »
Got the solution, ghosbunny. Instead of /home/* ... it was just a very simple /home/$USER ... and I didn't go ahead with the cp -R. Instead I opted for symlinks. I'm testing the app now. Thanks for your help.

I hope part of your testing includes logging in as a different user  ;) ;D

The generally accepted way to do this is:

Code: [Select]
SYSUSERS=`cat /etc/passwd | grep "/bin/bash" |grep "[0-9][0-9][0-9]" |cut -d: -f1`
SYSUSERS=${SYSUSERS/named/}
for idx in $SYSUSERS
 do INP1= cp  -R %_datadir/kde4/apps/plasma/plasmoids/veromix-plasmoid /home/$idx/.kde4/share/apps/plasma/plasmoids/; done

Symlinks are only suitable if there is NO user customizable data there.


Terry.
« Last Edit: June 28, 2012, 04:05:22 AM by TerryN »
Dell E521 - AMD 64 X2 5000+, 4GB RAM, ATI X1300 graphics
PCLinuxOS 2013 (KDE)
|Twitter|

Offline Archie

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8821
  • Aurum nostrum non est aurum vulgi.
Re: Need to add scriptlet to %post
« Reply #4 on: June 28, 2012, 04:05:29 AM »
That's a good point you made. No, I haven't tested login on as another user .... but I'm pretty sure the symlinks won't be created on the other users' home folder simple because $USER is only identified as the current session and the users running Synaptic.

The scenario is a user installs via Synaptic so the app only gets installed on that user's home folder. And I'm pretty sure that is what I've done.

Now, it would be better if on install time all users on the system including root would get a symlink of their respective folder.

Thanks for the tip, TerryN. It might be just  the %post I am looking for. I opted for symlink so I don't have to copy recursive folders and files.

INP1 ... did you just come up with that?
Since 2006 | LiCo 401868 | Bare Metal | What is necessary is never unwise. --Sarek, 2258.42


Offline Bald Brick

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 6475
  • I'm going South
Re: Need to add scriptlet to %post
« Reply #5 on: June 28, 2012, 04:08:20 AM »


maybe %post needs some better solution it copies the files also to /home/mysql and so on


Instead of /home/* ... it was just a very simple /home/$USER ...
[/quote]

But when run as root $USER can mean different things depending on how you've become root:

[erik  ~]$ su
Password:
[root@localhost erik]# echo $USER
erik
[root@localhost erik]# exit
exit
[erik  ~]$ su -
Password:
[root@localhost ~]# echo $USER
root
[root@localhost ~]#
Feed the trolls!
They need it!

AMD Athlon 7450 Dual-Core Processor, 7.80 GiB RAM, Nvidia GeForce GT 120/PCIe/SSE2, OpenGL/ES-version: 3.3 0 NVIDIA 295.40, SBx00 Azalia (Intel HDA) soundcard, ‎Logitech B500 webcam, SAA7146 DVB card, HDDs: Seagate 250824AS, Western Digital WD10EAVS-00D

Offline Archie

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8821
  • Aurum nostrum non est aurum vulgi.
Re: Need to add scriptlet to %post
« Reply #6 on: June 28, 2012, 04:15:36 AM »
Instead of /home/* ... it was just a very simple /home/$USER ...

But when run as root $USER can mean different things depending on how you've become root:

[erik  ~]$ su
Password:
[root@localhost erik]# echo $USER
erik
[root@localhost erik]# exit
exit
[erik  ~]$ su -
Password:
[root@localhost ~]# echo $USER
root
[root@localhost ~]#


I did realize the problem it would have if there are two or more users on a system. Listing users on the system is a more viable method. Thanks for your input, BB.
Since 2006 | LiCo 401868 | Bare Metal | What is necessary is never unwise. --Sarek, 2258.42


Offline Archie

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8821
  • Aurum nostrum non est aurum vulgi.
Re: Need to add scriptlet to %post
« Reply #7 on: June 28, 2012, 04:42:14 AM »
Heya Terry ...

Code: [Select]
SYSUSERS=`cat /etc/passwd | grep "/bin/bash" |grep "[0-9][0-9][0-9]" |cut -d: -f1`
won't include root on the list of users, would it?

UPDATE:
This following is what Synaptic threw back at me.

Quote
/var/tmp/rpm-tmp.7xIuCP: line 9: syntax error: unexpected end of file
warning: %post(plasma-applet-veromix-0.18.3-1_archie_2012.i586) scriptlet failed, exit status 2

The scriptlet: (tell me what's wrong)

Code: [Select]
%post
/sbin/ldconfig

#Thanks to TerryN
SYSUSERS=`cat /etc/passwd | grep "/bin/bash" |grep "[0-9][0-9][0-9]" |cut -d: -f1`
SYSUSERS=${SYSUSERS/named/}
for idx in $SYSUSERS
 do INP1=
ln -s /usr/share/kde4/apps/plasma/plasmoids/veromix-plasmoid/ /home/$idx/.kde4/share/apps/plasma/plasmoids/veromix-plasmoid  && ln -s /usr/share/kde4/services/plasma-widget-veromix.desktop /home/$idx/.kde4/share/kde4/services/veromix.desktop

%postun
/sbin/ldconfig
SYSUSERS=`cat /etc/passwd | grep "/bin/bash" |grep "[0-9][0-9][0-9]" |cut -d: -f1`
SYSUSERS=${SYSUSERS/named/}
for idx in $SYSUSERS
 do INP1= rm -rf /home/$idx/.kde4/share/apps/plasma/plasmoids/veromix-plasmoid && rm -f /home/$idx/.kde4/share/kde4/services/veromix.desktop
« Last Edit: June 28, 2012, 04:49:27 AM by Archie »
Since 2006 | LiCo 401868 | Bare Metal | What is necessary is never unwise. --Sarek, 2258.42


Offline TerryN

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 740
Re: Need to add scriptlet to %post
« Reply #8 on: June 28, 2012, 04:47:49 AM »
Heya Terry ...

Code: [Select]
SYSUSERS=`cat /etc/passwd | grep "/bin/bash" |grep "[0-9][0-9][0-9]" |cut -d: -f1`won't include root on the list of users, would it?

Nope.  The second grep excludes non-user UIDs
If you want root included you need an extra step (as root's home directory is not under /home)

Terry.
Dell E521 - AMD 64 X2 5000+, 4GB RAM, ATI X1300 graphics
PCLinuxOS 2013 (KDE)
|Twitter|

Offline TerryN

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 740
Re: Need to add scriptlet to %post
« Reply #9 on: June 28, 2012, 04:59:45 AM »

Quote
/var/tmp/rpm-tmp.7xIuCP: line 9: syntax error: unexpected end of file
warning: %post(plasma-applet-veromix-0.18.3-1_archie_2012.i586) scriptlet failed, exit status 2

Looks like you've missed ;done (to terminate the do)

Terry.

P.S I'm assuming the user cannot customize or adjust this applet?  Because if they can then using symlinks may mean that any change one user makes will automatically be propagated to other users and all customizations would be lost if the package is updated.
I don't know this particuar applet but I have not seen an instance before where it has been necessary for applet data to be placed under $HOME at install time.  Usually the applet creates it (from the system wide data) when the applet is added by the user.

« Last Edit: June 28, 2012, 05:13:56 AM by TerryN »
Dell E521 - AMD 64 X2 5000+, 4GB RAM, ATI X1300 graphics
PCLinuxOS 2013 (KDE)
|Twitter|

Offline Archie

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8821
  • Aurum nostrum non est aurum vulgi.
Re: Need to add scriptlet to %post
« Reply #10 on: June 28, 2012, 05:08:36 AM »
Ohh, I am such a dork! Oki-dokie, one more try and I need to create the folders ... /home/mysql complain No file or folder ... or maybe I just leave it like that since it is not a valid user anyway. ;D

Thanks again, TerryN. I'm sure this is as good as it gets.
Since 2006 | LiCo 401868 | Bare Metal | What is necessary is never unwise. --Sarek, 2258.42


Offline pinoc

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2881
    • other projects...
Re: Need to add scriptlet to %post
« Reply #11 on: June 28, 2012, 07:58:01 AM »
that was an older version of determining system users, the correct version is this one:
Code: [Select]
SYSUSERS=`cat /etc/passwd | grep "/home/.*/bash" |grep "[0-9][0-9][0-9]" |cut -d: -f1`

then you will not get the mysql nor the named but instead all system users but root, see addlocale for details.
best,
-p.

Offline Just17

  • PCLinuxOS Tester
  • Super Villain
  • *******
  • Posts: 11064
  • MLUs Forever!
Re: Need to add scriptlet to %post
« Reply #12 on: June 28, 2012, 08:06:44 AM »
that was an older version of determining system users, the correct version is this one:
Code: [Select]
SYSUSERS=`cat /etc/passwd | grep "/home/.*/bash" |grep "[0-9][0-9][0-9]" |cut -d: -f1`

then you will not get the mysql nor the named but instead all system users but root, see addlocale for details.
best,
-p.

Just wondering ........  as PCLOS only uses user ids from 500 could/should the above be

SYSUSERS=`cat /etc/passwd | grep "/home/.*/bash" |grep "[5-9][0-9][0-9]" |cut -d: -f1`

or even

SYSUSERS=`cat /etc/passwd | grep "/home/.*/bash" |grep "[5-9]" |cut -d: -f1`
MLUs rule the roost!

Linux XPS 3.4.48-pclos1.bfs  64 bit
Intel Core2 Quad CPU Q9450 @ 2.66GHz
4 GB RAM
MCP51 High Def Audio
GeForce GTX 550 Ti
PHILIPS  ‎DVD+-RW DVD8701
‎Logitech ‎BT Mini-Receiver
Afatech DTT

Offline Bald Brick

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 6475
  • I'm going South
Re: Need to add scriptlet to %post
« Reply #13 on: June 28, 2012, 09:10:03 AM »
that was an older version of determining system users, the correct version is this one:
Code: [Select]
SYSUSERS=`cat /etc/passwd | grep "/home/.*/bash" |grep "[0-9][0-9][0-9]" |cut -d: -f1`

then you will not get the mysql nor the named but instead all system users but root, see addlocale for details.
best,
-p.

Just wondering ........  as PCLOS only uses user ids from 500 could/should the above be

SYSUSERS=`cat /etc/passwd | grep "/home/.*/bash" |grep "[5-9][0-9][0-9]" |cut -d: -f1`

or even

SYSUSERS=`cat /etc/passwd | grep "/home/.*/bash" |grep "[5-9]" |cut -d: -f1`

Makes sense but then you'd never find O-P's user ID. He told us some months ago that he still numbers his users starting with 1000.
Feed the trolls!
They need it!

AMD Athlon 7450 Dual-Core Processor, 7.80 GiB RAM, Nvidia GeForce GT 120/PCIe/SSE2, OpenGL/ES-version: 3.3 0 NVIDIA 295.40, SBx00 Azalia (Intel HDA) soundcard, ‎Logitech B500 webcam, SAA7146 DVB card, HDDs: Seagate 250824AS, Western Digital WD10EAVS-00D

Offline Archie

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8821
  • Aurum nostrum non est aurum vulgi.
Re: Need to add scriptlet to %post
« Reply #14 on: June 28, 2012, 10:04:11 AM »
:)

We're not gonna deal with the extraordinary ... just the standard.
Since 2006 | LiCo 401868 | Bare Metal | What is necessary is never unwise. --Sarek, 2258.42