Basically I want to replace a file on user’s system with the newly installed one but at the same time i want to make a backup of it given that it exists.
Tl;dr → mv ~.abc ~.abc.bak if it exists. Skip this step if it doesn’t
Found something here: How can be this done inside PKGBUILD? Also is it okay to use &&?
You can’t do this in a PKGBUILD. The PKGBUILD runs at the time the package is built, not at the time the package is installed. The package may even be built on a different machine.
If you wanted to do something like that, you would need to do it in the install file. However, that will be running as root so ~ might not mean what you think it means.
That being said, even if you could, you shouldn’t because:
Thanks everyone for the help. I am actually creating a custom zsh theme and uploading it in the AUR. You guys are right. One shouldn’t touch someone’s $HOME. So my last q is that should I drop the .zshrc in /etc/skel and let the user copy/paste it? or could there be any other approoach. Thanks.
I think saving it to /etc/skel is a okayish way. If it exists than pacman should automatically tell the user that’s it is saved as .zshrc.new. if it isn’t there than no problem.
This can be done but how to tell the user? echo "copy .zshrc from /blah/blah in PKGBUILD?
Also /etc/skel folder is used by useradd only not there to store configs to be used from already created users…
it would be more some place like /usr/share/packagename/
I have come to the conclusion that i should put backup=(etc/skel/.zshrc) in PKGBUILD so original doesnt get overwritten and the new is saved as .zshrc.new.
not only in /etc/skel
And as I mentioned /etc/skel will only be used on new user creation after it is present there… to get configs for already installed user you will need somehow a tutorial or a script to run as user…
I will make one more attempt and then let you do what you want.
Many Arch-based distros ship an /etc/skel/.zshrc by default from a settings package. Your package won’t be installable on those distros. pacman will throw a file exists error and refuse to proceed. The backup array doesn’t handle conflicting packages with the same file. It lets the user retain changes made to that file.
This is how you should package a set of zsh settings. Write a file to /usr/share and ask the user to include that file at the end of their .zshrc
As there were only two important source ... line in .zshrc, as suggested above i will put (echo put source ... in zshrc) in post install file rather than messing around with there files.