Currently, I'm trying to automate a procedure we use at work. Whenever we install Oracle's JDK, we need to manually add it to our global PATH variable. Here's an excerpt from the procedure :
sudo vi /etc/environment
add this at the beginning of the PATH : "/opt/jdk1.6.0_45/bin:"
Here is the content of /etc/environment on my computer :
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
Here is what it will look like after its modification :
PATH="/opt/jdk1.6.0_45/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
Do not forget that this file is not a script, but rather a file containing KEY=VALUES. This file stores the system-wide locale and path settings.
My question is how can I add a new path to the PATH variable from /etc/environment without involving any manual operation, preferably using only a bash script. Additionnaly, I would like to avoid seeing my JDK path added more than once if I run the resulting script twice.