Difference between revisions of "Setup Bash"

From WebOS Internals
Jump to navigation Jump to search
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
= Setting up Bash as a Replacment Shell for /bin/sh=
+
= Setting up bash as a replacment shell for /bin/sh=
 +
The Palm webOS devices like Pre and Pixi come with the [http://en.wikipedia.org/wiki/Bash_%28Unix_shell Bourne shell] as the default stock shell. The [http://en.wikipedia.org/wiki/Bash_(Unix_shell) Bourne-Again Shell], or bash, is available via optware. This is how you can set it up.
  
 
== Preliminaries==
 
== Preliminaries==
Line 50: Line 51:
 
These are my preferred ls cmds (yours may vary):
 
These are my preferred ls cmds (yours may vary):
  
PATH is adding the /opt/bin and /opt/sbin paths so your optware binaries work easily. This is a complete overwrite of the PATH set by default and applies to your unprivileged user as well as root. Keep that in mind if you try to run stuff out of /sbin dirs...
+
'''PATH''' is adding the /opt/bin and /opt/sbin paths so your optware binaries work easily. This is a complete overwrite of the PATH set by default and applies to your unprivileged user as well as root. Keep that in mind if you try to run stuff out of /sbin dirs...
  
EDITOR is setting your editor of choice for things like crontab edits or subversion if you were using that on the Pre. If you are happy with vi, you can skip the EDITOR set. If you're reading this guide, you probably want nano...
+
'''EDITOR''' is setting your editor of choice for things like crontab edits or subversion if you were using that on the Pre. If you are happy with vi, you can skip the EDITOR set. If you're reading this guide, you probably want nano...
  
nano is easily installed with ipkg-opt install nano...
+
nano is easily installed with  
 +
<pre><nowiki>ipkg-opt install nano</nowiki></pre>
  
 
Okay. You are done...remount the root file system as readonly:
 
Okay. You are done...remount the root file system as readonly:

Latest revision as of 20:31, 25 September 2010

Setting up bash as a replacment shell for /bin/sh

The Palm webOS devices like Pre and Pixi come with the Bourne shell as the default stock shell. The Bourne-Again Shell, or bash, is available via optware. This is how you can set it up.

Preliminaries

  1. Gain root access.
  2. Setup the Optware Feed.
  3. Open the root file system to read/write with rootfs_open. If you haven't yet altered your PATH (see below) use the following:
/usr/sbin/rootfs_open -w

Install bash

ipkg-opt install bash

Super Important: Before you switch your login shell in /etc/passwd, you MUST create /etc/shells and add /opt/bin/bash and /bin/sh to it. If you do not, you will lock yourself out of the Pre on anything but novacom term if you switch your default shell.

echo -e "# /etc/shells: valid login shells\n/opt/bin/bash\n/bin/sh" >/etc/shells

now you can vi/nano whatever /etc/passwd and replace your unprivileged user shell with /opt/bin/bash.

Before:

> youruser:yourpasswordhash:1001:1001:Linux User,,,:/var/home/youruser:/bin/sh

After:

> youruser:yourpasswordhash:1001:1001:Linux User,,,:/var/home/youruser:/opt/bin/bash

Try to SSH in with that user and be sure you can access the machine. Change root as well if you desire. Since you will probably 'sudo su' to root to perform larger tasks, you will want to stay in consistent shell.

Setup your bash profile

When a user logs in, the shell provides a certain environment for the programs running in your users context. This is achieved by setting environment variables in scripts, stored in multiple locations. That includes /etc/profile (for all users) and all the files in the /etc/profile.d directory. (Other linux distributions often add ~/.bash_profile and ~/.bashrc as well to the home directories of users.)

/etc/profile.d/ is a good place to put your application specific setups and thereby setting up custom aliases, paths, editors etc. Additionally, we can append aliases and logout scripts into this /etc/profile.d folder.

1. Create the directory:

mkdir /etc/profile.d

2. Add your rc file (name doesn't matter as long as it isn't a .file):

vi/nano/etc /etc/profile.d/profile.custom

3) Add aliases and PATH options. Here is what I have:

alias nano='nano -zwc'
alias ls='ls -aF'
alias ll='ls -alF'
PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin::/opt/bin:/opt/sbin
EDITOR='nano'
export PATH EDITOR

nano -zwc will allow nano to suspend with ctl-z and not wordwrap by default as well as show you the line numbers that your cursor is on (avoid having to hit ctrl-c looking for line numbers).

These are my preferred ls cmds (yours may vary):

PATH is adding the /opt/bin and /opt/sbin paths so your optware binaries work easily. This is a complete overwrite of the PATH set by default and applies to your unprivileged user as well as root. Keep that in mind if you try to run stuff out of /sbin dirs...

EDITOR is setting your editor of choice for things like crontab edits or subversion if you were using that on the Pre. If you are happy with vi, you can skip the EDITOR set. If you're reading this guide, you probably want nano...

nano is easily installed with

ipkg-opt install nano

Okay. You are done...remount the root file system as readonly:

mount -o remount,ro /

There's no need to reboot, but if you logout and log back in you can make sure you are in bash... Type some gibberish:

> root@castle:/etc# asdf
> bash: asdf: command not found

Mmm, bashalicious...

NOTE The 2nd command from the top was adding /bin/bash to /etc/shells, NOT /bin/sh. I fixed it. Also, I wasn't able to get /etc/profile.d/profile.custom to work, so I used ~/.bashrc instead. -hopspitfire

Credits

Submitted by retry. Tested to work by hopspitfire (see NOTE above).