SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
config() {
NEW="$1"
OLD="${NEW%.new}"
# If there's no config file by that name, mv it over:
if [ ! -r "$OLD" ]; then
mv "$NEW" "$OLD"
elif [ "$(md5sum < "$OLD")" = "$(md5sum < "$NEW")" ]; then
# toss the redundant copy
rm "$NEW"
fi
# Otherwise, we leave the .new copy for the admin to consider...
}
"for infile in $1; do [...] done" variant seems pointless to me but I may be missing something. "md5sum < file" already used but not everywhere.
Code:
preserve_perms() {
NEW="$1"
OLD="${NEW%.new}"
if [ -e "$OLD" ]; then
for cmd in ch{own,mod}; do
$cmd --reference="$OLD" "$NEW"
done
fi
config "$NEW"
}
Maybe it should do more than just chown and chmod? (Due to "cp -a ${OLD} ${NEW}.incoming" and I saw even "touch -r ${NEW} ${NEW}.incoming".)
Some ideas by lopid from ##slackware-help at Freenode.
config() {
NEW="$1"
OLD="${NEW%.new}"
# If there's no config file by that name, mv it over:
if [ ! -r "$OLD" ]; then
mv "$NEW" "$OLD"
elif [ "$(md5sum < "$OLD")" = "$(md5sum < "$NEW")" ]; then
# toss the redundant copy
rm "$NEW"
fi
# Otherwise, we leave the .new copy for the admin to consider...
}
... "md5sum < file" already used but not everywhere.
Hi,
I do not see the point of using md5sum here. For once, there is the chance of hash collisions. Even if the chances are low, why risk it? A diff -q would not only eliminate that risk, it is also faster - not that performance matters much with files this size, you only notice the difference with files >100MB. But still, why introduce the computational overhead of a checksum comparison to get a worse result?
Clearly I, too, am missing something here. So if you know of a reason why md5sum is preferred over diff then please let me know.
I took md5sum as an axiom but sure, why not to use diff?
Wait, not so sure, md5sum comes with coreutils and you need diffutils for diff. Also, later we could need that MD5 stored and use for improved *.new handling.
Last edited by opty; 03-27-2021 at 10:47 AM.
Reason: revision
Wait, not so sure, md5sum comes with coreutils and you need diffutils for diff.
Good point, I assume coreutils is installed before diffutils, so it makes sense to have it this way during system installation.
Quote:
Originally Posted by opty
Also, later we could need that MD5 stored and use for improved *.new handling.
I have a hunch that storing MD5 sums for later comparisons would introduce too big a complication. Just think about the possibility of stale files. As I mentioned earlier, with the file sizes we are dealing here speed is not much of an issue.
Quote:
Originally Posted by GazL
diff is not the correct utility. If you must change it from md5sum, then I'd suggest cmp.
Why? Cmp is in the diffutils package, just as diff.
It should be noted that my slack-install doinst.sh will no longer work with -current - Pat now uses a cookie in the extracted /install/ path in order to allow multiple package installations at the same time (presumably, I can't think of other reasons to make that path random).
Also, the slack-install stuff was never meant for wide package use - it is used for my own custom packages because I can do the necessary md5suming on a small number Vs a huge number in the distro... it would prove to be far too much effort to maintain. opty and I have already discussed an alternative that would work automatically and still provide the same feature (ie, not leaving .new files around if the admin has no edited the file) - I just need to code it up sometime.
A feature of Slackware is that the install media can also be used as rescue media, so you also need to consider compatibility with busybox.
If you use md5sum, then the output is a string variable that is the same in GNU and busybox.
If you use 'cmp -s', then the exit values are the same in GNU and busybox, although the outputs differ if -s is not specified and files are different.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.