doinst.sh improvements suggestion
by opty from LinuxQuestions.org on (#5FVDQ)
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.


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.