LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 03-26-2021, 05:56 PM   #1
opty
Member
 
Registered: Mar 2021
Posts: 176

Rep: Reputation: Disabled
doinst.sh improvements suggestion


doinst.sh improvements suggestion:

Code:
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.
 
Old 03-27-2021, 10:15 AM   #2
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Quote:
Originally Posted by opty View Post
Code:
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.
 
1 members found this post helpful.
Old 03-27-2021, 10:30 AM   #3
opty
Member
 
Registered: Mar 2021
Posts: 176

Original Poster
Rep: Reputation: Disabled
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
 
1 members found this post helpful.
Old 03-27-2021, 11:55 AM   #4
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,910

Rep: Reputation: 5027Reputation: 5027Reputation: 5027Reputation: 5027Reputation: 5027Reputation: 5027Reputation: 5027Reputation: 5027Reputation: 5027Reputation: 5027Reputation: 5027
diff is not the correct utility. If you must change it from md5sum, then I'd suggest cmp.
 
1 members found this post helpful.
Old 03-27-2021, 12:32 PM   #5
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Quote:
Originally Posted by opty View Post
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 View Post
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 View Post
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.
 
1 members found this post helpful.
Old 03-27-2021, 01:38 PM   #6
opty
Member
 
Registered: Mar 2021
Posts: 176

Original Poster
Rep: Reputation: Disabled
Ad MD5: e.g. slack-install by tadgy
 
Old 03-27-2021, 06:27 PM   #7
tadgy
Member
 
Registered: May 2018
Location: UK
Distribution: Slackware (servers), Void (desktop/laptop)
Posts: 299

Rep: Reputation: 401Reputation: 401Reputation: 401Reputation: 401Reputation: 401
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.
 
Old 03-27-2021, 08:48 PM   #8
chrisretusn
Senior Member
 
Registered: Dec 2005
Location: Philippines
Distribution: Slackware64-current
Posts: 2,979

Rep: Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556
Quote:
Originally Posted by crts View Post
Why? Cmp is in the diffutils package, just as diff.
Perhaps this:
Quote:
GNU diff - compare files line by line
Quote:
GNU cmp - compare two files byte by byte
 
Old 03-28-2021, 08:25 AM   #9
opty
Member
 
Registered: Mar 2021
Posts: 176

Original Poster
Rep: Reputation: Disabled
Maybe due to config() used for binaries too? (sudo in the middle warning!):

Code:
sed -n '/\.new$/{ s/\(.\+\)\.new$/\/\1/; p; }' /var/lib/pkgtools/packages/* |& sudo file -f - |& egrep -v "text|empty"
Most probably the reason for using md5sum.

Last edited by opty; 03-28-2021 at 08:27 AM. Reason: specification
 
Old 03-28-2021, 08:27 AM   #10
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,377

Rep: Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757
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.
 
2 members found this post helpful.
Old 03-28-2021, 08:50 AM   #11
opty
Member
 
Registered: Mar 2021
Posts: 176

Original Poster
Rep: Reputation: Disabled
BTW, maybe the migration from md5sum to e.g. b2sum (BLAKE2) or even b3sum (BLAKE3) still doesn't yield the cost-benefit ratio worth doing it.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
src2pkg doinst.sh auto library links rpedrica Slackware 2 04-02-2011 10:02 AM
Can I just generate doinst.sh with package? binarybob0001 Slackware 11 11-03-2007 01:07 PM
doinst.sh syntax (help please) Dark Carnival Slackware 3 01-25-2007 09:08 AM
doinst.sh i need to install packages using command line Clarence27 Zenwalk 2 10-07-2006 07:03 AM
appending to perllocal.pod via doinst.sh jong357 Slackware 1 10-31-2005 10:48 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 06:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration