3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# Distribution version discovery
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# Copyright (C) 2014 Red Hat
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# This program is free software; you can redistribute it and/or modify
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# it under the terms of the GNU General Public License as published by
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# the Free Software Foundation; either version 3 of the License, or
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# (at your option) any later version.
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# This program is distributed in the hope that it will be useful,
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# but WITHOUT ANY WARRANTY; without even the implied warranty of
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# GNU General Public License for more details.
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# You should have received a copy of the GNU General Public License
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# along with this program. If not, see <http://www.gnu.org/licenses/>.
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashovif [ -z ${_DISTRO_SH+set} ]; then
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# Distribution family (lowercase)
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# Distribution ID (lowercase)
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# Distribution release (lowercase)
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai KondrashovDISTRO_ID=`lsb_release --id | sed -e 's/^[^:]*:\s*\(.*\)$/\L\1\E/'`
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai KondrashovDISTRO_RELEASE=`lsb_release --release | sed -e 's/^[^:]*:\s*\(.*\)$/\L\1\E/'`
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# Distribution branch (lowercase)
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashovdeclare -r DISTRO_BRANCH="-$DISTRO_FAMILY-$DISTRO_ID-$DISTRO_RELEASE-"
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# Install packages.
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# Args: [pkg_name...]
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov declare prompt=$'Need root permissions to install packages.\n'
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov prompt+="Enter sudo password for $USER: "
51c4da6e4941dfc5fca40bffa2248b9a77f139b2Lukas Slebodnik if [[ "$DISTRO_BRANCH" == -redhat-fedora-2[2-5]* ]]; then
73585f9af928913200999c5b3b983bb9266ee266Lukas Slebodnik # https://bugzilla.redhat.com/show_bug.cgi?id=1215208 is fixed
73585f9af928913200999c5b3b983bb9266ee266Lukas Slebodnik yum-deprecated --assumeyes install -- "$@" |&
73585f9af928913200999c5b3b983bb9266ee266Lukas Slebodnik # Pass input to output, fail if a missing package is reported
73585f9af928913200999c5b3b983bb9266ee266Lukas Slebodnik /^No package .* available.$/ {s=1}
73585f9af928913200999c5b3b983bb9266ee266Lukas Slebodnik END {exit s}'
51c4da6e4941dfc5fca40bffa2248b9a77f139b2Lukas Slebodnik elif [[ "$DISTRO_BRANCH" == -redhat-fedora-* ]]; then
73585f9af928913200999c5b3b983bb9266ee266Lukas Slebodnik elif [[ "$DISTRO_BRANCH" == -redhat-* ]]; then
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov [ $# != 0 ] && sudo -p "$prompt" yum --assumeyes install -- "$@" |&
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov # Pass input to output, fail if a missing package is reported
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov /^No package .* available.$/ {s=1}
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov elif [[ "$DISTRO_BRANCH" == -debian-* ]]; then
cf37196dca93a8785c5a4e0af6e9a5053bff4e3aLukas Slebodnik [ $# != 0 ] && DEBIAN_FRONTEND=noninteractive \
cf37196dca93a8785c5a4e0af6e9a5053bff4e3aLukas Slebodnik sudo -p "$prompt" apt-get --yes install -- "$@"
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov echo "Cannot install packages on $DISTRO_BRANCH" >&2
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# Remove packages.
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# Args: [pkg_name...]
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov declare prompt=$'Need root permissions to remove packages.\n'
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov prompt+="Enter sudo password for $USER: "
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov if [[ "$DISTRO_BRANCH" == -redhat-* ]]; then
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov [ $# != 0 ] && sudo -p "$prompt" yum --assumeyes remove -- "$@"
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov elif [[ "$DISTRO_BRANCH" == -debian-* ]]; then
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov [ $# != 0 ] && sudo -p "$prompt" apt-get --yes remove -- "$@"
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov echo "Cannot remove packages on $DISTRO_BRANCH" >&2
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashovfi # _DISTRO_SH