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 ?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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.
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...
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.