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

Help for Current Versions of MX
When asking for help, use Quick System Info from MX Tools. It will be properly formatted using the following steps.
1. Click on Quick System Info in MX Tools
2. Right click in your post and paste.
Message
Author
frmald
Posts: 29
Joined: Sat Dec 05, 2020 5:47 am

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

#1 Post 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
Last edited by frmald on Mon Jan 09, 2023 9:59 am, edited 2 times in total.

User avatar
dolphin_oracle
Developer
Posts: 22214
Joined: Sun Dec 16, 2007 12:17 pm

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

#2 Post 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.
http://www.youtube.com/runwiththedolphin
lenovo ThinkPad X1 Extreme Gen 4 - MX-23
FYI: mx "test" repo is not the same thing as debian testing repo.

frmald
Posts: 29
Joined: Sat Dec 05, 2020 5:47 am

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

#3 Post 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.

frmald
Posts: 29
Joined: Sat Dec 05, 2020 5:47 am

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

#4 Post 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).

User avatar
dolphin_oracle
Developer
Posts: 22214
Joined: Sun Dec 16, 2007 12:17 pm

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

#5 Post 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.
http://www.youtube.com/runwiththedolphin
lenovo ThinkPad X1 Extreme Gen 4 - MX-23
FYI: mx "test" repo is not the same thing as debian testing repo.

DeepDayze
Posts: 133
Joined: Tue Jan 18, 2022 3:34 pm

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

#6 Post 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.
Real Men Use Linux

User avatar
dolphin_oracle
Developer
Posts: 22214
Joined: Sun Dec 16, 2007 12:17 pm

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

#7 Post 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)
http://www.youtube.com/runwiththedolphin
lenovo ThinkPad X1 Extreme Gen 4 - MX-23
FYI: mx "test" repo is not the same thing as debian testing repo.

DeepDayze
Posts: 133
Joined: Tue Jan 18, 2022 3:34 pm

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

#8 Post 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.
Real Men Use Linux

DeepDayze
Posts: 133
Joined: Tue Jan 18, 2022 3:34 pm

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

#9 Post by DeepDayze »

Alright...this time desktop-defaults-mx-common installed cleanly. Thanks for resolving this, DO!
Real Men Use Linux

User avatar
Adrian
Developer
Posts: 8932
Joined: Wed Jul 12, 2006 1:42 am

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

#10 Post 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:

Post Reply

Return to “MX Help”