WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Sourcing tc-functions in .ashrc may clash with extensions  (Read 451 times)

Offline polikuo

  • Sr. Member
  • ****
  • Posts: 414
Sourcing tc-functions in .ashrc may clash with extensions
« on: October 04, 2020, 09:53:51 AM »
I am learning how to use autotools.
When I execute "autoscan", it yields weird outputs.  :-\
Quote
sh: /mnt/mmcblk0p1/: unknown operand
sh: /mnt/mmcblk0p2/: unknown operand

Then I find out there's a function with the exact name defined in /etc/init.d/tc-functions
TC runs the command as that function instead of the perl script you'll find in autoconf.tcz  :(

Digging more into the Core-scripts, only these scripts are calling that function:
Code: [Select]
/usr/bin/tce-update
/usr/bin/tce-setup
/etc/init.d/tc-restore.sh
/etc/init.d/tc-functions
/etc/init.d/tc-config

I don't quite understand the purpose of the function, so I hunt down how tc-functions script is sourced.
The answer is .ashrc, line 3.

Honestly, I don't think a user would ever need that.  ::)
In a way, it annoying to spend your time debugging the tools only to find out they're irrelevant.

I suggest removing that line from /etc/skel/.ashrc
What do you think ?  :)

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 634
Re: Sourcing tc-functions in .ashrc may clash with extensions
« Reply #1 on: October 04, 2020, 12:37:39 PM »
It’s used in almost every tc script..... more than what you’ve listed.  But I’m not sure why it needs to be in .ashrc.

Have you tried to just remove it from /home/tc/.ashrc and see if you have any problems?

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 8223
Re: Sourcing tc-functions in .ashrc may clash with extensions
« Reply #2 on: October 04, 2020, 07:06:30 PM »
Hi polikuo
I don't see anything in  .ashrc  that would require it.

Offline polikuo

  • Sr. Member
  • ****
  • Posts: 414
Re: Sourcing tc-functions in .ashrc may clash with extensions
« Reply #3 on: October 04, 2020, 07:18:00 PM »
It’s used in almost every tc script..... more than what you’ve listed.  But I’m not sure why it needs to be in .ashrc.

I know there's more than what I've listed, that particular list is just a collection of scripts that use the "autoscan" function.

Have you tried to just remove it from /home/tc/.ashrc and see if you have any problems?

Of course I have, nothing happens really.

Since almost every scripts that need tc-functions have source it at the beginning, I believe it's safe to remove it from the system .ashrc

IIRC, the /etc/skel/.ashrc file is copied into the home folder of any new users that are created on a system.
The .ashrc file is a shell script which is run every time a user opens a new shell.
You put commands that you want to run every single time in it.
That's why I said it's a tad weird to source the "tc-functions" as a user.

Hi polikuo
I don't see anything in  .ashrc  that would require it.

Exactly  ;D

I believe it's redundant.

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 8223
Re: Sourcing tc-functions in .ashrc may clash with extensions
« Reply #4 on: October 04, 2020, 07:28:08 PM »
Hi polikuo
Since  tc-functions  is used all over the place, I suspect it was rubber stamped into  .ashrc  out of habit.

Offline polikuo

  • Sr. Member
  • ****
  • Posts: 414
Re: Sourcing tc-functions in .ashrc may clash with extensions
« Reply #5 on: October 04, 2020, 07:48:05 PM »
Hi polikuo
Since  tc-functions  is used all over the place, I suspect it was rubber stamped into  .ashrc  out of habit.

Hah, learn some English today.  :D

Anyway~, as I dig in more, it seems that, the /etc/skel/.ashrc indeed is copied into a user's home directory.
Here's a snippet of the setupHome function. (again, it's in tc-functions)
Code: [Select]
setupHome(){
   read USER < /etc/sysconfig/tcuser
   if [ ! -d /home/"$USER" ] || [ "`ls -la /home/${USER} | wc -l`" -le 3 ]
   then
      mkdir -p /home/"$USER"/.X.d
      mkdir -p /home/"$USER"/.local/bin
      chown -R "$USER".staff /home/"$USER/"
      chmod -R g+s,o-rwx /home/"$USER/"
   fi
   LIST=`mktemp`
   > "$LIST"
   for S in `find /etc/skel -type f`
   do
ITEM="${S#/etc/skel/}"
if [ ! -e /home/"$USER"/"$ITEM" ]
then
echo "$ITEM" >> "$LIST"
fi
   done
   if [ -s "$LIST" ]
   then
      tar -C /etc/skel -T "$LIST" -cf - | tar -C /home/"$USER" -xf -
      while read ITEM
do chown -R "$USER".staff /home/"$USER"/"${ITEM%%/*}"
      done < "$LIST"
   fi
   rm "$LIST" 2>/dev/null
}
I find it a bit funny to see the method it copies the skel files  ;)
Code: [Select]
tar -C /etc/skel -T "$LIST" -cf - | tar -C /home/"$USER" -xf -
Back to the point, my memory holds.
I was right that the /etc/skel/.ashrc file is copied into the home folder.
And that's the only place you'll ever need that file.
Judging by the purpose of the rc script, you don't need tc-functions as a user.

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 8223
Re: Sourcing tc-functions in .ashrc may clash with extensions
« Reply #6 on: October 04, 2020, 07:55:03 PM »
Hi polikuo
... Anyway~, as I dig in more, it seems that, the /etc/skel/.ashrc indeed is copied into a user's home directory. ...
Yes, but only if that directory does not exist. If you have a persistent (or backed up) home directory, it won't be overwritten
so you can edit it.

Offline polikuo

  • Sr. Member
  • ****
  • Posts: 414
Re: Sourcing tc-functions in .ashrc may clash with extensions
« Reply #7 on: October 04, 2020, 08:10:24 PM »
Sure, that's what TC is all about.

Extremely flexible and customizable.

However, imagine a newbie user who follows the autotools tutorial and run "autoscan", then everything backfires...

This is a TCB thread, just speaking out my opinion about the base system.
« Last Edit: October 04, 2020, 08:12:06 PM by polikuo »

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 8223
Re: Sourcing tc-functions in .ashrc may clash with extensions
« Reply #8 on: October 04, 2020, 08:28:47 PM »
Hi polikuo
I just wanted to clarify that the copying only takes place when the home directory does not exist for anyone else reading
this thread.
« Last Edit: October 05, 2020, 06:03:07 AM by Rich »

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 10289
Re: Sourcing tc-functions in .ashrc may clash with extensions
« Reply #9 on: October 04, 2020, 11:50:11 PM »
IIRC Roberts set it up, he used some of the tc-functions regularly from a shell. We could just rename autoscan to tc-autoscan, want to send a patch?
The only barriers that can stop you are the ones you create yourself.

Offline polikuo

  • Sr. Member
  • ****
  • Posts: 414
Re: Sourcing tc-functions in .ashrc may clash with extensions
« Reply #10 on: October 04, 2020, 11:58:10 PM »
IIRC Roberts set it up, he used some of the tc-functions regularly from a shell. We could just rename autoscan to tc-autoscan, want to send a patch?

How about a git pull request ?

BTW, shell functions don't allow '-', but '_' is OK.
So that will be tc_autoscan

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 10289
Re: Sourcing tc-functions in .ashrc may clash with extensions
« Reply #11 on: October 05, 2020, 10:11:23 AM »
Yes, that works.
The only barriers that can stop you are the ones you create yourself.

Offline polikuo

  • Sr. Member
  • ****
  • Posts: 414
Re: Sourcing tc-functions in .ashrc may clash with extensions
« Reply #12 on: October 05, 2020, 09:08:31 PM »
Hi, I just sent you 2 pull requests.
One for the master branch, the other for the picore branch

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 10289
Re: Sourcing tc-functions in .ashrc may clash with extensions
« Reply #13 on: October 05, 2020, 11:47:24 PM »
Merged both, thanks.
The only barriers that can stop you are the ones you create yourself.