How to automate running this shell script that installs some software?


#1

I have a shell script that installs some software I need to run my tests successfully. I can download that shellscript with wget and then execute it - but unfortunately there are no parameters to skip input - I have to page through a licence and then type “yes” a few times.

How can I automate this input, so the shell script can successfully run and install the software?


#2

Probably a duplicate of this question.


#3

Thanks, I will see if there is an undocumented --yes param and try to use yes | command.


#4

No --yes option.
Running yes | sudo sh script.sh doesn’t work for the licence terms, when I confirm those manually nothing happen on actual prompt that would need “yes”.


#6

Note: This does not actually automate input, but gives me a workaround where no input is necessary :slight_smile:


Trying --yes gave me this interesting output:

$ sudo sh script.sh --yes
Unrecognized flag : --yes
Makeself version 2.1.4
 1) Getting help or info about script.sh :
  [...]
 
 2) Running iTMSTransporter_installer_linux_1.9.7.sh :
  iTMSTransporter_installer_linux_1.9.7.sh [options] [--] [additional arguments to embedded script]
  with following options (in that order)
  --confirm             Ask before running embedded script
  --noexec              Do not run embedded script
  --keep                Do not erase target directory after running
			the embedded script
  --nox11               Do not spawn an xterm
  --nochown             Do not give the extracted files to the current user
  --target NewDirectory Extract in NewDirectory
  --tar arg1 [arg2 ...] Access the contents of the archive through the tar command
  --                    Following arguments will be passed to the embedded script

By using --target and --noexec I could extract the content into a folder, without executing the script at the same time:

sudo sh script.sh --target=foo --noexec

This directory foo now contains:

-rwxr-xr-x 1 root root 2633 Okt 27 04:59 install_script.sh
drwxr-xr-x 5 root root 4096 Dez 15 19:36 foo
-rw-r--r-- 1 root root  11565 Dez 15 19:42 License.txt
-rw-r--r-- 1 root root  135 Okt 27 04:59 Welcome.txt

install_script.sh contains code like this:

...
more License.txt
agreed=
while [ x$agreed = x ]; do
    echo
    echo "Do you agree to the above license terms? [yes or no] "
    read reply leftover
    case $reply in
        y* | Y*)
            agreed=1;;
        n* | N*)
    echo "You must agree to the license agreement to install this software!";
    exit 1;;
    esac
done
...

which is the prompt I had problems with as it would page - and now I could just remove by opening the file with sudo gedit install_script.sh.

(Removing those lines can be scripted with sudo sed -e '2d;12,27d;57d' install_script.sh which removes lines 2, 12 to 27 and 57)

(Alternatively I could also have extracted the actual installation logic from there and put this into my step, but removing some lines seems simpler)

Now running sudo ./install_script.sh in that folder installs the software as it should.

Or from my config.yml:

      - run:
          name: Install additional dependency 
          command: |
            cd /tmp
            wget https://example.org/script.sh
            sudo sh script.sh --target foo --noexec
            cd foo
            sudo sed -e '15,43d' -i install_script.sh
            sudo ./install_script.sh

#7

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.