dev/provisioning/modules/puppi/files/scripts/yum.sh
changeset 28 b0b56e0f8c7f
equal deleted inserted replaced
27:a2342f26c9de 28:b0b56e0f8c7f
       
     1 #!/bin/bash
       
     2 # yum.sh - Made for Puppi
       
     3 
       
     4 # Sources common header for Puppi scripts
       
     5 . $(dirname $0)/header || exit 10
       
     6 
       
     7 # Show help
       
     8 showhelp () {
       
     9     echo "This script performs the yum operations required by puppi::project::yum"
       
    10     echo "It integrates and uses variables provided by other core Puppi scripts"
       
    11     echo "It has the following options:"
       
    12     echo "-a <action> (Optional) What action to perform. Available options: deploy (default), rollback, remove"
       
    13     echo "-n <rpm_name> (Required) Name of the package to handle"
       
    14     echo "-v <rpm_version> (Optional) The version of the rpm to manage. Default: latest"
       
    15     echo "-r <install_root> (Optional) The Instll root path. Default: /"
       
    16     echo 
       
    17     echo "Examples:"
       
    18     echo "yum.sh -a deploy -n ${rpm} -r ${install_root} -v ${rpm_version}"
       
    19 }
       
    20 
       
    21 rpm_version="latest"
       
    22 install_root="/"
       
    23 
       
    24 # Check Arguments
       
    25 while [ $# -gt 0 ]; do
       
    26   case "$1" in
       
    27     -a)
       
    28       case $2 in
       
    29           rollback)
       
    30           action="rollback"
       
    31           ;;
       
    32           remove)
       
    33           action="remove"
       
    34           ;;
       
    35           *)
       
    36           action="install"
       
    37           ;;
       
    38       esac 
       
    39       shift 2 ;;
       
    40     -n)
       
    41       rpm_name=$2
       
    42       shift 2 ;;
       
    43     -v)
       
    44       rpm_version=$2
       
    45       shift 2 ;;
       
    46     -r)
       
    47       install_root=$2
       
    48       shift 2 ;;
       
    49     *)
       
    50       showhelp
       
    51       exit ;;
       
    52   esac
       
    53 done
       
    54 
       
    55 
       
    56 do_install () {
       
    57     if [ x$rpm_version == "xlatest" ] ; then
       
    58         full_rpm_name=$rpm_name
       
    59     else
       
    60         full_rpm_name=$rpm_name-$rpm_version
       
    61     fi
       
    62 
       
    63     # Archives version of the rpm to update
       
    64     oldversion=$(rpm -q $rpm_name --qf  "%{VERSION}-%{RELEASE}\n")
       
    65     if [ "$?" = "0" ]; then
       
    66         mkdir -p $archivedir/$project/$oldversion
       
    67         if [ $archivedir/$project/latest ] ; then
       
    68             rm -f $archivedir/$project/latest
       
    69         fi
       
    70         ln -sf $archivedir/$project/$oldversion $archivedir/$project/latest
       
    71     fi
       
    72 
       
    73     if [ x$install_root != "x/" ] ; then
       
    74         yum install -y -q --installroot=$install_root $full_rpm_name
       
    75     else
       
    76         yum install -y -q $full_rpm_name
       
    77     fi
       
    78 }
       
    79 
       
    80 do_rollback () {
       
    81     yum downgrade -y -q $rpm_name-$rollbackversion
       
    82 }
       
    83 
       
    84 do_remove () {
       
    85     yum remove -y -q $rpm_name
       
    86 }
       
    87 
       
    88 # Action!
       
    89 case "$action" in
       
    90     install) do_install ;;
       
    91     rollback) do_rollback ;;
       
    92     remove) do_remove ;;
       
    93 esac