Page 1 of 1

to whoever broke desktop-defaults-mx-common, a bit of shell advice

Posted: Mon Jan 09, 2023 9:54 am
by frmald
To @delphin_oracle or whoever wrote the postinst script of desktop-defaults-mx-common, I can't reply to the announcement, so I'm posting here. Here's what that piece of... beauty (/var/lib/dpkg/info/desktop-defaults-mx-common.postinst)... looks like, and how to fix it (see "# ME:" comments):

Code: Select all

  #! /bin/sh
   
  set -e
   
  if [ -x /etc/init.d/umountnfs-alternative.sh ]; then
    if [ -x /usr/sbin/update-rc.d ]; then
      update-rc.d umountnfs-alternative.sh remove >/dev/null 2>&1
      update-rc.d umountnfs-alternative.sh defaults >/dev/null 2>&1
    fi
  fi
   
  ##fix mx-tools menu files (mx 21 and older)
  FILES="$(find /home/ -true -wholename "*.config/menus/applications-merged/mx-tools.menu")"
  if [ -n "$FILES" ]; then
          for i in "$FILES"; do   # ME: you want to word-split $FILES, so DON'T QUOTE!!! Your construct breaks if there are multiple users 
              sed -i 's/MX-Tools/mx-tools/' "$i"
          done
  fi
   
  exit 0
The most important part is to NOT QUOTE:

Code: Select all

for i in $FILES; do
Otherwise, the script will break on multi-user systems. Hopefully you see why.

Also, you should check with

Code: Select all

[ -w "$i" ]
(and probably also -r) before calling sed.

Also, you don't usually save

Code: Select all

$(find)
results into a variable. You use

Code: Select all

find ... -exec ... ';'
.

Also, for the future, if you're quoting a string and you DON'T want expansion, use single quotes, not double quotes.

Also, and finally, instead of

Code: Select all

find -true -wholename
you could have simply said

Code: Select all

for i in /home/*/config/menus/applications-merged/mx-tools.menu
(and obviously check with [ -w "$i" ]). This would have averted the entire problem.

To users: simply edit

Code: Select all

/var/lib/dpkg/info/desktop-defaults-mx-common.postinst

Re: to whoever broke desktop-defaults-mx-common, a bit of shell advice

Posted: Mon Jan 09, 2023 9:57 am
by dolphin_oracle
I couldn't because it could not deal with folders with spaces in the name.

I fixed the problem by removing the work entirely. I shouldn't have had it there to begin with.

I did test on multiuser system, but apparently not enough.

I've bookmarked this for later. it comes up, so thanks.

Re: to whoever broke desktop-defaults-mx-common, a bit of shell advice

Posted: Mon Jan 09, 2023 10:01 am
by frmald
Well, yeah. My last bit of advice above was to use a simple glob (for i in /home/*/config/menus/applications-merged/mx-tools.menu) and ditch "find". Then you wouldn't have had any problems. Anyway, good luck.

Re: to whoever broke desktop-defaults-mx-common, a bit of shell advice

Posted: Mon Jan 09, 2023 10:11 am
by frmald
Also, now that I think about it, the whole approach is misguided, because (1) not everything under /home is the homedir of a user, (2) not every user has their $HOME under /home, (3) it's probably not a good idea to modify random files without user's approval.

For example, some users could have their HOME under /home2; there might be a directory called /home/myself-mx19-backup (which the user probably doesn't want to touch); or there might be /home/* folders that only get used under a different boot of the system (say, /home/myself-archlinux).

Re: to whoever broke desktop-defaults-mx-common, a bit of shell advice

Posted: Mon Jan 09, 2023 10:21 am
by dolphin_oracle
yeah, I woke up wanting to pull the update for those kinds of reasons, and the install problems just sealed the deal.

Re: to whoever broke desktop-defaults-mx-common, a bit of shell advice

Posted: Mon Jan 09, 2023 10:22 am
by DeepDayze
I just purged it as it fails to install as get errors. When it's fixed I will reinstall it. I have a user_sv folder under /home as it has legacy files from another install on that same machine and it errors out when trying to update the menu file.

Re: to whoever broke desktop-defaults-mx-common, a bit of shell advice

Posted: Mon Jan 09, 2023 10:24 am
by dolphin_oracle
DeepDayze wrote: Mon Jan 09, 2023 10:22 am I just purged it as it fails to install as get errors. When it's fixed I will reinstall it.
its fixed now, and the code was removed. the mirrors will get it over time. the mxrepo.com sites all have it (and I think a few of the faster mirrors do too)

Re: to whoever broke desktop-defaults-mx-common, a bit of shell advice

Posted: Mon Jan 09, 2023 10:37 am
by DeepDayze
dolphin_oracle wrote: Mon Jan 09, 2023 10:24 am
DeepDayze wrote: Mon Jan 09, 2023 10:22 am I just purged it as it fails to install as get errors. When it's fixed I will reinstall it.
its fixed now, and the code was removed. the mirrors will get it over time. the mxrepo.com sites all have it (and I think a few of the faster mirrors do too)
Ok thanks, DO...will check back later.

Re: to whoever broke desktop-defaults-mx-common, a bit of shell advice

Posted: Mon Jan 09, 2023 10:46 am
by DeepDayze
Alright...this time desktop-defaults-mx-common installed cleanly. Thanks for resolving this, DO!

Re: to whoever broke desktop-defaults-mx-common, a bit of shell advice

Posted: Mon Jan 09, 2023 11:24 am
by Adrian
frmald wrote: Mon Jan 09, 2023 9:54 am Also, and finally, instead of

Code: Select all

find -true -wholename
you could have simply said

Code: Select all

for i in /home/*/config/menus/applications-merged/mx-tools.menu
(and obviously check with [ -w "$i" ]). This would have averted the entire problem.
Thanks for the advice and catching this. The idea with "find" was mine, I was suggesting to pipe the result to "xargs sed", or use -exec, which I think would not have created the problem, but I guess when two cooks work on the same meal the meal gets burned :grin: