3

So I am trying to make a standard shellscript to install some standard software which are useful for me like net-tools, OpenSSH, Omada Controller and so on. As the standard .deb for the TP Link Omada Controller software needs some extra commands to configure correctly for it to start. One of them is the command

update-alternatives --config java

This gives me a prompt with three options, 0, 1 and 2. The answer needs to be 2. Always, or at least in the version that is out now.

This is what I have in my script now for the controller and I plan to put them all in a 'while'-statement to prompt if user wants to install instead of installing it automatically. The printf could be removed if it all works like I would like.

#install omada controller
cd /tmp
apt -y install gdebi-core
apt -y install openjdk-8-jdk
printf ${RED}"----------------------------\n\nPress 2 in this next prompt\n\n----------------------------\n"${NC}
update-alternatives --config java
wget https://static.tp-link.com/2020/202012/20201211/omada_v4.2.8_linux_x64.deb
export JAVA_HOME=/usr/lib/jvm/default-java
echo $JAVA_HOME
gdebi omada_v4.2.8_linux_x64.deb

Is there a way to put this into the Shell script? I have seen ways to specify answers in the same line as where the script is executed in the CLI but this is not what I want. I'd like to make it fully automated with only the prompts that are already in some installation processes and prompting to install the mentioned package.

2
  • You should always put variables in quotes unless you have a good reason not to: printf "$RED--…--\n$NC" and echo "$JAVA_HOME". And it’s somewhat safer to use printf '%s\n'text ….  You probably don’t need the {} braces. Dec 27, 2020 at 0:46
  • The JAVA_HOME thing was something I have found exactly like that in the installation documentation so that's why I didn't put them in quotes. The bracket part isn't needed anymore as I've replaced it with an expect-script. Thanks for the info though!
    – NHendriks
    Dec 29, 2020 at 11:24

3 Answers 3

4

You can split this interactive --configue option in two silent options : --query and --set:

update-alternatives --query <package>

To install/remove alternatives packages you can use --install and --remove options.

To display the configured package in update-alternatives

To set the priority :

update-alternatives --set <package> <PATH>

The gdebi command can be executed as follow:

LANG=en_US.UTF-8 yes |gdebi omada_v4.2.8_linux_x64.deb
0
2

You can do answers to prompts with expect. You can either call a different expect script from bash or implement expect commands inside bash.

If you install expect you will also get autoexpect which will generate expect script for you, that you can call from your bash script.

If you run autoexpect update-alternatives --config java it will start the process normally, and you can then answer any questions, once the process is complete autoexpect will generate expect script that automatically answers the prompts with answers you made during the installation.

1
  • Ooh that worked like a charm! I've made the shell script install expect as well and when the time comes for the update-alternative I use wget to download in the script,. make it executable with chmod and then run it. That worked out great. Now all I have to do is put this into a while as I don't need to install the Omada package on every instance.
    – NHendriks
    Dec 26, 2020 at 13:03
1

Okay I got it working! Or at least the part I have asked for. Still need to test the whole sequence of commands but that will be fine. Thanks a lot! Below is what I have now and the expect-thing does work as expected (pun intended 😄)

#install omada controller
cd /tmp
apt -y install gdebi-core
apt -y install openjdk-8-jdk
wget https://raw.githubusercontent.com/NHendriks01/ubuntu/main/configure-java.exp
chmod +x configure-java.exp
./configure-java.exp
wget https://static.tp-link.com/2020/202012/20201211/omada_v4.2.8_linux_x64.deb
export JAVA_HOME=/usr/lib/jvm/default-java
echo $JAVA_HOME
yes |gdebi omada_v4.2.8_linux_x64.deb

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .