User:Tsu2/BASH zypper

Jump to: navigation, search

Repository Add and Initial Setup

Adding a repo

The following adds the LEAP 42.1 Perl repo, non-interactively automatically accepting defaults (Yes to all questions) and sets the repo to auto-refresh

zypper -n ar -f http://download.opensuse.org/repositories/devel:/languages:/perl/openSUSE_Leap_42.1/ LEAP_42.1:Perl

Auto accept GPG keys

The following refreshes all repos, and automatically accepts the GPG keys for all newly added repos

zypper --gpg-auto-import-keys ref

Detect OS version and auto insert into add repo URI automatically

The following automatically detects the running openSUSE version, and installs the Perl repo example for that distro. The following does not support Tumbleweed.

VERSION=$(grep VERSION /etc/SuSE-release | sed -e 's/VERSION = //') && \
zypper ar -nf http://download.opensuse.org/repositories/devel:/languages:/perl/openSUSE_Leap_$VERSION/ openSUSE_$VERSIONIn:Perl

Tumbleweed vs all other stable openSUSE

The following can detect Tumbleweed vs all other current stable openSUSE. In the following example, if Tumbleweed is detected "net-tools-deprecated" is installed if a network setup requires consistent network interface naming across all openSUSE versions.

#!/bin/bash

ID=$(grep -w ID= /etc/os-release | sed -e 's/ID=//')
VERSION_ID=$(grep -w VERSION_ID= /etc/os-release | sed -e 's/VERSION_ID=//' | sed -e 's/"//g')

if [ "$ID" = '"opensuse-tumbleweed"' ]; then

echo Tumbleweed detected, do TW stuff
zypper in net-tools-deprecated
# zypper -n ar -f http://download.opensuse.org/repositories/science/openSUSE_Factory/ openSUSE_Factory:science
# zypper --gpg-auto-import-keys ref


else
if [ "$ID" = '"opensuse-leap"' ]; then

echo This must be LEAP $VERSION_ID
echo Do LEAP stuff
# zypper -n ar -f http://download.opensuse.org/repositories/science/openSUSE_Leap_$VERSION_ID/ openSUSE_$VERSION_ID:science
# zypper --gpg-auto-import-keys ref
fi
fi

Regular Expressions

A very important thing to know, how to handle Regular Expressions properly.
Includes a section and explanation about using quotes to avoid unintended Expansions

Regular Expressions

SED

An important, powerful and versatile tool... It will search for any character or sequence in your text and replace...replace with a "nothing" and you've removed it! A really cool list of examples can be found at

http://www.theunixschool.com/2014/08/sed-examples-remove-delete-chars-from-line-file.html