bash as shell and MC with subshell toggle

Any questions about the Command Line Interface can be placed here!
Forum rules
Please note the disclaimer before modifying your Synology Product.
HighTower
Rookie
Rookie
Posts: 36
Joined: Fri Aug 30, 2013 11:42 am

bash as shell and MC with subshell toggle

Postby HighTower » Fri Aug 30, 2013 11:55 am

Hello,

I wonder if it is possible to have bash as default shell for root/admin user while ssh connection and MC with subshell working (so ctrl+O switch to shell and back)?

Any success stories and may be guides?

Thanks in advance.
User avatar
maxxfi
Compiler
Compiler
Posts: 6794
Joined: Sun Dec 27, 2009 12:13 pm
Location: Espoo, Finland

Re: bash as shell and MC with subshell toggle

Postby maxxfi » Sat Aug 31, 2013 8:31 am

In short: the best solution is to leave the default as it is (ash) and then e.g. from root .profile first test if bash binary is present and in that case do an 'exec bash'.

The issue is that bash is not (and it doesn't need to be) part of Synology image, so if you install your own bash in the system partition, it will be wiped out at next DSM upgrade, and if you install it in a user volume (like with ipkg/optware stuff), when the volume is down, bash will be inaccessible. In both cases, you end up with a system that cannot run root's scripts, and the whole system may get unbootable.
DS-106j > DS-210j > DS-411
User avatar
johnk.dev.null
Versed
Versed
Posts: 264
Joined: Tue Apr 02, 2013 8:00 pm
Location: UK

Re: bash as shell and MC with subshell toggle

Postby johnk.dev.null » Tue Sep 03, 2013 6:23 pm

What maxxfi said is important ... so ...

Keep /bin/ash as your root shell and in /root/.profile add these lines at the end -

Code: Select all

if [[ -x /opt/bin/bash ]]; then
  exec /opt/bin/bash
fi

This gives you a bash root shell with no risk when upgrading DSM or if you lose /opt.
Next create /root/.bashrc and add these lines -

Code: Select all

PS1='\u@\h:\w \$ '
export SHELL=/opt/bin/bash

The first line gives you a nice bash prompt. The second explicitly sets the SHELL variable to your correct shell. Ctl+O now works once you have logged out and back in again.

As always when changing root shell settings, keep a separate root shell window open until you have confirmed all of the changes work.

Regards JohnK
DS413: DSM 6.0.2-8451 Update 9
HighTower
Rookie
Rookie
Posts: 36
Joined: Fri Aug 30, 2013 11:42 am

Re: bash as shell and MC with subshell toggle

Postby HighTower » Wed Sep 04, 2013 7:24 am

Thanks you very much!
It works as I want!
Cool ))
User avatar
delebre
Student
Student
Posts: 65
Joined: Wed Jun 06, 2012 6:51 pm

Re: bash as shell and MC with subshell toggle

Postby delebre » Fri Feb 21, 2014 12:44 am

Hey guys, I wanted to look into this a little bit so I tried it out. After doing the instructions line for line, I log out and log back in. No problem. This is what I see:

Code: Select all

login as: root
Authenticating with public key "MyKey"

BusyBox v1.16.1 (2014-01-20 02:29:16 CST) built-in shell (ash)
Enter 'help' for a list of built-in commands.

root@SynoNAS:~ #


This means I am in a bash shell now, correct? How do I go back to just ash?

After re-reading this thread, it looks like I might need MC (Midnight Commander?) with subshell working. How do I achieve this?

Thank you for further clarifying this useful tweak!
User avatar
maxxfi
Compiler
Compiler
Posts: 6794
Joined: Sun Dec 27, 2009 12:13 pm
Location: Espoo, Finland

Re: bash as shell and MC with subshell toggle

Postby maxxfi » Fri Feb 21, 2014 7:23 am

delebre wrote:This means I am in a bash shell now, correct? How do I go back to just ash?

Do you mean only in the current session?
You can either just run "/bin/ash" (if you don't mind to keep the login bash 'behind': if you type 'exit' you'll go back to initial bash) or "exec /bin/ash" if you want to leave only ash opened (when you exit, you'll terminate the session).
DS-106j > DS-210j > DS-411
User avatar
delebre
Student
Student
Posts: 65
Joined: Wed Jun 06, 2012 6:51 pm

Re: bash as shell and MC with subshell toggle

Postby delebre » Fri Feb 21, 2014 12:12 pm

Ok, I'll clarify my confusion. I log into SSH, and the first prompt I get is:

root@SynoNAS:~ #

Which I know is for the bash shell. So it's defaulting to BASH first. Is this a problem? Specifically:
...it will be wiped out at next DSM upgrade, and if you install it in a user volume (like with ipkg/optware stuff), when the volume is down, bash will be inaccessible.


Excuse my ignorance, this is new for me!

Now, to swap back to ASH, I can indeed type /bin/ash and I get the (ASH) prompt:

~ #

Once I am in the ASH prompt, I can type 'exit' and it will exit my /bin/ash and pop me back into BASH
root@SynoNAS:~ #

So everything is working, I just want to make sure that there isn't going to be some issue with DSM upgrades later down the line. If everything is kosher, then this is an excellent tweak and I'm really stoked how you guys did this. So thank you!
User avatar
johnk.dev.null
Versed
Versed
Posts: 264
Joined: Tue Apr 02, 2013 8:00 pm
Location: UK

Re: bash as shell and MC with subshell toggle

Postby johnk.dev.null » Sun Feb 23, 2014 3:36 pm

The lines you added to your ./.profile script test to see if /opt/bin/bash exists before running it. If it doesn't exist then it doesn't try to run it. This is done to deal with DSM updates removing /opt. After a DSM upgrade you will get the usual ash default shell.

If you want to revert to a default ash shell at the moment then just remove or comment out the lines you added in .profile. i.e.

Code: Select all

if [[ -x /opt/bin/bash ]]; then
  exec /opt/bin/bash
fi

To comment them out, add a hash symbol at the start of each line

Code: Select all

# if [[ -x /opt/bin/bash ]]; then
#   exec /opt/bin/bash
# fi


Regards

JohnK
DS413: DSM 6.0.2-8451 Update 9
User avatar
delebre
Student
Student
Posts: 65
Joined: Wed Jun 06, 2012 6:51 pm

Re: bash as shell and MC with subshell toggle

Postby delebre » Thu Mar 06, 2014 7:06 pm

Thanks!!
bobdaniel
Trainee
Trainee
Posts: 14
Joined: Fri Apr 22, 2011 9:31 am

Re: bash as shell and MC with subshell toggle

Postby bobdaniel » Fri Mar 14, 2014 1:27 pm

I suppose I have a fundamental misunderstanding of bash startup.
Logging in as a non-root user.
At the end of ~/.profile I have put

Code: Select all

case "$0" in
*bash)
;;
*)
echo "Using shell: $0"
BASH=$(type -p bash)
if [ ! -z "$BASH" -a -x "$BASH" ]; then
echo "Switching to bash"
unset BASH
exec bash -l
fi
;;
esac

and I see "Using shell: -sh" "Switching to bash"
.bashrc is

Code: Select all

echo "In .bashrc Hello one and all"
alias RUBBISH='RUBBISH'

but this doesn't get echoed and RUBBISH isn't set. .bash_profile is

Code: Select all

echo "In bash_profile"
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi

but I don't get the echo.
Is there something obviously wrong that I am doing? The file permissions are

Code: Select all

-rw-r--r--    1 bob      users           72 Mar 14 11:57 .bash_profile
-rw-r--r--    1 bob      users          174 Mar 14 11:57 .bashrc
-rw-rw-rw-    1 bob      users          630 Mar 14 12:15 .profile
User avatar
johnk.dev.null
Versed
Versed
Posts: 264
Joined: Tue Apr 02, 2013 8:00 pm
Location: UK

Re: bash as shell and MC with subshell toggle

Postby johnk.dev.null » Fri Mar 14, 2014 4:38 pm

I have reproduced your method with the following login results -

Code: Select all

BusyBox v1.16.1 (2014-03-06 14:27:52 CST) built-in shell (ash)
Enter 'help' for a list of built-in commands.

Using shell: -ash
Switching to bash
.bash_profile called
.bashrc called
john@diskstation:~ $


So it works for me. I see no obvious mistakes in the scripting. I suggest you change your output line to

Code: Select all

echo "Switching to $BASH"

in order to see exactly what you are calling. Since your script finds something that is apparently executable you should try running it manually just to make sure it does work.

Note that this method still leaves your $SHELL variable incorrect. You should set it explicitly to /opt/bin/bash or whatever in .bashrc (once you get it working).

Your permissions are ok on the files. I think the user only has to be able to read the files.

Regards

JohnK
DS413: DSM 6.0.2-8451 Update 9
bobdaniel
Trainee
Trainee
Posts: 14
Joined: Fri Apr 22, 2011 9:31 am

Re: bash as shell and MC with subshell toggle

Postby bobdaniel » Fri Mar 14, 2014 5:56 pm

Thank you John. In the meantime, in the true spirit of linguistic philosophy I (dis)solved the problem by at the end of .profile putting an explicit rcfile

Code: Select all

if [ -x /opt/bin/bash ]; then
 exec bash -rcfile .bash_profile
fi

I admit .bash_profile is a silly name, I was lazy.
Mirabile dictu, SHELL gets set OK.

I have NO IDEA what's going on (a bit like linguistic philosophers now I come to think of it.)

Regards
Bob
P.S. I have

Code: Select all

BusyBox v1.16.1 (2014-02-11 20:03:27 CST) built-in shell (ash)
User avatar
johnk.dev.null
Versed
Versed
Posts: 264
Joined: Tue Apr 02, 2013 8:00 pm
Location: UK

Re: bash as shell and MC with subshell toggle

Postby johnk.dev.null » Fri Mar 14, 2014 8:18 pm

Glad you sorted it out one way or another. Note that with nothing specified after 'exec bash', .bashrc still gets called. So you could just have put all you need in that one file.

Regards
Johnk
DS413: DSM 6.0.2-8451 Update 9
bobdaniel
Trainee
Trainee
Posts: 14
Joined: Fri Apr 22, 2011 9:31 am

Re: bash as shell and MC with subshell toggle

Postby bobdaniel » Fri Mar 14, 2014 9:30 pm

John
I tried putting things in .bashrc but they never got obeyed. Maybe I had the ownership/permissions on .bashrc wrong at some point.
As I said, I've no idea what was going on.
Thanks for your interest.
Bob

Return to “Command Line Interface”

Who is online

Users browsing this forum: No registered users and 1 guest