Issue
I am currently writing an RPM which contains both configuration and reversion scripts that will be run manually after the completion of the install.
When I deploy an older package I want to keep my existing reversion scripts, not overwrite them with the old ones. During an upgrade then the reversion scripts folder should be overwritten.
(Simplified: During the upgrade I want to add new scripts, during the downgrade I don't want the newer scripts removed.)
My current approach is to copy the old scripts to a temporary folder during the pre install which is working, and then copy them back to the reversion script folder in the post install which isn't. I can copy the files manually upon completion of the deployment.
I am using the following command:
'cp' -f TempScriptFolder ScriptFolder.
At this point I'm pretty confused by this RPM goop, and not really sure what else to try.
Solution
Your pre-
and post-
approach to preserving your script files is fine, you just need a bit of help with the logic. Your first problem is you are not copying anything with your command above due to your lack of -r
or -a
options to cp
. cp
will not copy recursively without one or the other. Try:
'cp' -af TempScriptFolder ScriptFolder
Second, it would be helpful if you were able to append a version to the script directory name so that you have a reference of which version the scripts came from. (you have the version available in the .spec file, which you could write to a temp .ver file or pass to your pre/post scripts) In pre-install
you could use the mv
command to accomplish what you need. You could move ScriptFolder
to a new folder as follows:
mv -f ScriptFolder ScriptFolder.version
That would preserve the scripts for any version in a separate directory. If you want them all included under the script folder, the mv
again is your friend. Just mv -f ScriptFolder.version ScriptFolder
to place the versioned directory under the existing ScriptFolder directory.
On the upgrade/downgrade, you could obtain the version again and check ScriptFolde/*.version
for an existing set of scripts for that version and then restore to that version with a round-robin mv
. Something like:
mv -f ScriptFolder/ScriptFolder.version tmp.version
mv -f ScriptFolder.saveversion
mv -f tmp.version ScriptFolder
You can work out an approach that fits for you.
Answered By - David C. Rankin Answer Checked By - Katrina (WPSolving Volunteer)