How to use zypper in bash scripts for someone coming from apt-get?
In general, you should use --non-interactive
mode, in shortcut -n
, when running zypper non-interactively:
zypper -n install curl
That might seem confusing for someone coming from apt-get install -y curl
. Some zypper sub-commands also support a command-specific -y
/--no-confirm
option as an alias for -n
/--non-interactive
, but not all sub-commands do. As the install
command does implement that, this command is equivalent to the above:
zypper install -y curl
Note that the -y
must come after install
, while the global -n
option comes before the subcommand (zypper install -n
means something different; read the man page for that).
[Edit] The section below is no longer accurate, but is retained for historical reference. Current zypper supports the --gpg-auto-import-keys
option to automatically import and trust the gpg keys associated with a new repository.
According to documentation there's no way how to accept a GPG key without interactive mode:
a new key can be trusted or imported in the interactive mode only
Even with --no-gpgp-checks
the GPG key will be rejected.
A workaround for scripts is to use pipe and echo
:
zypper addrepo http://repo.example.org my_name | echo 'a'
You have the --non-interactive option. From the man page:
Switches to non-interactive mode.
In this mode zypper doesn't ask user to type answers to various prompts, but uses default answers automatically.
The behaviour of this option is somewhat different than that of options like '--yes', since zypper can answer different answers to different questions.
The answers also depend on other options like '--no-gpg-checks'.
There is no real correspondense to apt-get's autoremove. The closest is the --clean-deps
option of the remove
command, which cleans dependencies right away (but not afterwards).
That is a sample
zypper --non-interactive --quiet addrepo --refresh -p 90 http://packman.inode.at/suse/openSUSE_Leap_15.0/ 'packman'
zypper --gpg-auto-import-keys refresh
zypper --non-interactive dist-upgrade --allow-vendor-change --from packman
zypper --non-interactive install vlc vlc-codecs
Of course you can include more options like --auto-agree-with-licenses
but remember that makes difference if its before or after install