WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: useBusybox function causes syntax error in GUI terminal  (Read 2865 times)

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1496
useBusybox function causes syntax error in GUI terminal
« on: March 27, 2023, 01:46:29 PM »
These commands cause no problems when run in a terminal in my router, which is CLI only (no X):
Code: [Select]
$ . /etc/init.d/tc-functions
$ useBusybox
$

Here are same commands on my laptop, in urxvt terminal emulator inside a GUI (Xorg) session:
Code: [Select]
$ . /etc/init.d/tc-functions
$ useBusybox
sh: /etc/init.d/busybox-aliases: line 85: syntax error: unexpected "("

Another oddity is that in the GUI session, "useBusybox" and all subsequent commands are in bold. It seems something in /etc/init.d/busybox-aliases is being interpreted as an escape sequence. Is this worth looking into and fixing?

P.S. Both machines are running TCL14-beta Pure x86_64

« Last Edit: March 27, 2023, 02:00:29 PM by GNUser »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11573
Re: useBusybox function causes syntax error in GUI terminal
« Reply #1 on: March 27, 2023, 02:15:08 PM »
Hi GNUser
I just tried it under  TCL14-alpha1 Pure x86_64  and got the same message
except it was  line 21. I used  aterm.tcz.

You don't need  . /etc/init.d/tc-functions.  It's already sourced in  ~/.ashrc.

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1496
Re: useBusybox function causes syntax error in GUI terminal
« Reply #2 on: March 27, 2023, 02:23:06 PM »
Hi GNUser
I just tried it under  TCL14-alpha1 Pure x86_64  and got the same message
except it was  line 21. I used  aterm.tcz.
Hi Rich. It's unsightly, isn't it? I think it would be worth fixing.

Quote
You don't need  . /etc/init.d/tc-functions.  It's already sourced in  ~/.ashrc.
Yep, I see it in there. Good to know. Thank you.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11573
Re: useBusybox function causes syntax error in GUI terminal
« Reply #3 on: March 27, 2023, 02:24:40 PM »
Hi GNUser
I get the same results on  TCL14-alpha1 x86, TCL13 x86 and x86_64.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11573
Re: useBusybox function causes syntax error in GUI terminal
« Reply #4 on: March 27, 2023, 05:10:07 PM »
Hi GNUser
Turns out this happens on TC9 x86 and TC10 x86 too:
Code: [Select]
tc@E310:~$ . /etc/init.d/busybox-aliases
sh: /etc/init.d/busybox-aliases: line 21: syntax error: unexpected "("
tc@E310:~$ . /etc/init.d/tc-functions
tc@E310:~$

I suspect what's happening is the contents of  busybox-aliases  is being interpreted as
a command because it doesn't use  alias  anymore. In TC4 useBusybox looked like this:
Code: [Select]
useBusybox(){
alias ar="busybox ar"
alias awk="busybox awk"
alias cat="busybox cat"
alias clear="busybox clear"
alias cp="busybox cp"
alias cpio="busybox cpio"
alias dc="busybox dc"
alias df="busybox df"
alias du="busybox du"
alias depmod="busybox depmod"
alias expr="busybox expr"
alias fdisk="busybox fdisk"
alias fold="busybox fold"
alias grep="busybox grep"
alias gunzip="busybox gunzip"
alias hostname="busybox hostname"
alias kill="busybox kill"
alias killall="busybox killall"
alias ls="busybox ls"
alias md5sum="busybox md5sum"
alias mount="busybox mount"
alias sed="busybox sed"
alias sort="busybox sort"
alias swapoff="busybox swapoff"
alias sync="busybox sync"
alias tar="busybox tar"
alias umount="busybox umount"
alias wc="busybox wc"
alias wget="busybox wget"
alias sudo='sudo '
}

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1496
Re: useBusybox function causes syntax error in GUI terminal
« Reply #5 on: March 27, 2023, 09:15:08 PM »
Hi Rich. I can confirm that if I change the useBusybox function in /etc/init.d/tc-functions from this:

Code: [Select]
useBusybox(){
  . /etc/init.d/busybox-aliases
}

to this:

Code: [Select]
useBusybox(){
alias ar="busybox ar"
alias awk="busybox awk"
alias cat="busybox cat"
alias clear="busybox clear"
alias cp="busybox cp"
alias cpio="busybox cpio"
alias dc="busybox dc"
alias df="busybox df"
alias du="busybox du"
alias depmod="busybox depmod"
alias expr="busybox expr"
alias fdisk="busybox fdisk"
alias fold="busybox fold"
alias grep="busybox grep"
alias gunzip="busybox gunzip"
alias hostname="busybox hostname"
alias kill="busybox kill"
alias killall="busybox killall"
alias ls="busybox ls"
alias md5sum="busybox md5sum"
alias mount="busybox mount"
alias sed="busybox sed"
alias sort="busybox sort"
alias swapoff="busybox swapoff"
alias sync="busybox sync"
alias tar="busybox tar"
alias umount="busybox umount"
alias wc="busybox wc"
alias wget="busybox wget"
alias sudo='sudo '
}

then typing useBusybox in a terminal emulator inside a GUI session works as intended, without any syntax errors.

Maybe the TC4-style useBusybox function should make a comeback? If so, /etc/init.d/busybox-aliases becomes superfluous and can be removed from base system.

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1496
Re: useBusybox function causes syntax error in GUI terminal
« Reply #6 on: March 28, 2023, 08:38:13 AM »
Hi Rich. There are scenarios where a user might want to call useBusybox from a GUI terminal emulator, so I think this should be fixed.

I went ahead and created a pull request on GitHub to go back to the old approach where useBusybox creates actual aliases. I made sure to include  cut  and  ps  among the aliases :)

P.S. aliasing sudo to sudo seems bizarre, so I took it out. Besides, it is not present in TCL13 and TCL14-beta's /etc/init.d/busybox-aliases. It can be put back in if someone wants/needs it for some obscure reason. Maybe there used to be some hard-to-alter places where a space was missing between sudo and the command that followed it?
« Last Edit: March 28, 2023, 08:42:12 AM by GNUser »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11573
Re: useBusybox function causes syntax error in GUI terminal
« Reply #7 on: March 28, 2023, 10:21:09 AM »
Hi GNUser
... P.S. aliasing sudo to sudo seems bizarre, ...
Agreed. It is not present in TCL10's  /etc/init.d/busybox-aliases  either.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11573
Re: useBusybox function causes syntax error in GUI terminal
« Reply #8 on: April 01, 2023, 02:27:02 PM »
Hi GNUser
I had an idea I'd like to get feedback on.

Remove  /e tc/init.d/busybox-aliases.
Change  useBusybox  to:
Code: [Select]
useBusybox(){
if [ ! -f /e tc/init.d/busybox-aliases ]
then
for Command in $(busybox --list)
do
case $Command in
xyzzy|plugh) # Commands that should never be aliased go here.
continue
;;

*)
echo "alias $Command=\"busybox $Command\"" >> /e tc/init.d/busybox-aliases
;;
esac
done

for Command in $(busybox.suid --list)
do
case $Command in
xyzzy|plugh) # Commands that should never be aliased go here.
continue
;;

*)
echo "alias $Command=\"busybox.suid $Command\"" >> /e tc/init.d/busybox-aliases
;;
esac
done
fi

  . /e tc/init.d/busybox-aliases
}
Sorry, the full path for busybox-aliases was causing the  Forum Error
message so I had to change  /etc/  to /e tc/.

The first time  useBusybox  gets called, it creates  /e tc/init.d/busybox-aliases
and then sources it. After that it only sources it when it gets called.

This way if commands get added or removed,  /e tc/init.d/busybox-aliases  will
always match busyboxes configuration.

By the way, these 2 won't work:
Code: [Select]
alias mount="busybox mount"
alias mount="busybox mount"
In TC4 everything was provide by busybox. After that, some commands
were provided by  busybox.suid , including those 2.
« Last Edit: April 01, 2023, 02:29:55 PM by Rich »

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11041
Re: useBusybox function causes syntax error in GUI terminal
« Reply #9 on: April 02, 2023, 01:53:52 AM »
An alias does cause some overhead, so creating one for every command wouldn't be desirable.  The aliases are specifically for those commands called from core scripts that might break when GNU/other tools are installed, due to differing args or missing deps.
The only barriers that can stop you are the ones you create yourself.