0

I have a rpm spec file which produces a rpm named cdplayer-1.10.x86_64.rpm. The rpm on target machines (rpm -ivh cdplayer-1.10.x86_64.rpm --nodeps)creates a directory "/opt/cd-player/" and put all files in it. What I need is when user runs rpm command on target m/c then it should check if directory exists and if yes then create different directory "/opt/cd-player_2/" and install files there otherwise install as "/opt/cd-player/". If we run one more then it should create "/opt/cd-player_3/".

Spec file:

  BuildArch: x86_64
  Prefix: /opt
  code_root=/home/user/

  %install
  rm -rf $RPM_BUILD_ROOT
  vds_root=$RPM_BUILD_ROOT/opt/cd-player
  cp $code_root/abc        $vds_root/abc

  %files

  %defattr(-,root,root)
  /opt/cd-player
  %pre
  count=`rpm -qa | grep cd-player | wc -l`
  name=`rpm -qa | grep cd-player`
  if [ $count -gt 0 ]; then
  echo
  echo "Error:  $name is already installed!!!"
  echo
  exit 1
  fi

How can i create a directory before installing and extract rpm there ?

frankhermes
  • 4,720
  • 1
  • 22
  • 39
Manish
  • 1,999
  • 2
  • 15
  • 26

1 Answers1

3

RPM does not support this kind of install. If you want multiple versions, you need to have them install into predefined directories and then have some kind of symlink or something to point to the one you want - see Packaging:Alternatives.

Aaron D. Marasco
  • 6,506
  • 3
  • 26
  • 39
  • Thank You. You gave the hint and now I solved it.What I have done is I install the rpm by default in /tmp/ and then in %post section I check the count of " /opt/cd-player". If its more than one then I move it to /opt as cd-player_2 and so on. Since I have no symlinks I have no problem otherwise I would have adjusted it. – Manish Feb 18 '15 at 05:08
  • 1
    You can't uninstall the RPM now... and you assume that `/tmp` is on the same partition / has enough space... The Fedora Project has an entire documented and well-thought-out policy for this, and you've ignored it... – Aaron D. Marasco Feb 19 '15 at 00:54
  • I agree i can't uninstall using rpm -e but I can delete it and I don't seem to have any problem now. My ultimate aim was to have multiple instances of cd_player each having some different properties. I wanted a fresh installation every time, that's why I tried this. – Manish Feb 25 '15 at 04:45