suse: zypper: Pre-select the solution in shell script

1.7k views Asked by At

I am trying to install a package via zypper package manager in SUSE Micro OS.

I am trying to automate the software package installation with help of a bash/shell script.

$ zypper install libopenssl-devel
Loading repository data...
Reading installed packages...
Resolving package dependencies...

Problem: nothing provides libopenssl0_9_8 = 0.9.8h needed by libopenssl-devel-0.9.8h-30.11.x86_64
 Solution 1: do not install libopenssl-devel-0.9.8h-30.11.x86_64
 Solution 2: break libopenssl-devel-0.9.8h-30.11.x86_64 by ignoring some of its dependencies

Choose from above solutions by number or cancel [1/2/c] (c):

As part of the process, I would like to pre-select solution 2, that is, I need a way to choose the preferred solution in the script itself.

I tried some options and it didn't work. All the below options choose option c which is the default behaviour.

zypper install libopenssl-devel <<< echo "2"
echo "2" | zypper install libopenssl-devel
zypper -n install --force libopenssl-devel

I can't use the rpm package manager.

1

There are 1 answers

4
Ahmet Said Akbulut On

yes command should do it. Also take a look here for other methods => https://stackoverflow.com/a/53465375/14320738

$ yes 2 | zypper install libopenssl-devel

Edit

Create an expect script:

[root@10 folder]# cat expctscript
#!/usr/bin/expect -f
spawn bash -c "yum install perl"
expect "Is this ok"
send "N\r"
interact

make it an executable file to avoid permission denied error.

[root@10 folder]# chmod +x expctscript 

run expctscript

[root@10 folder]# ./expctscript

Output

[root@10 folder]# ./expctscript
spawn bash -c yum install perl
Last metadata expiration check: 1:40:25 ago on Wed 07 Jul 2021 11:05:58 AM +03.
Dependencies resolved.
================================================================================
 Package                      Arch   Version                    Repository
                                                                           Size
================================================================================
Installing:
 perl                         x86_64 4:5.26.3-419.el8           AppStream  73 k
...
...
...
...
...
...
Transaction Summary
================================================================================
Install  113 Packages
Upgrade    3 Packages

Total download size: 18 M
Is this ok [y/N]: N
Operation aborted.
[root@10 folder]#

note: I can't test installing libopenssl-devel on my centOS as it is a Suse package. So modify expctscript content accordingly.