Add rpmbuild utility scripts.
authorSam Hague <shague@redhat.com>
Wed, 14 May 2014 00:16:58 +0000 (20:16 -0400)
committerSam Hague <shague@redhat.com>
Wed, 14 May 2014 00:16:58 +0000 (20:16 -0400)
Three scripts are added to help when working with RPMs:
- setbuildrpm.sh: Used to setup an environment to build RPMs.
- odlrepo.sh: Used to setup a local repo with the built RPMs.
- checkint: Used to validate the RPMs against the integration builds.

All the scripts have "-?" text to show the options and usage.

Change-Id: I512d815242463160e8420d23dcf2b2f621c3dfd1
Signed-off-by: Sam Hague <shague@redhat.com>
packaging/rpm/util/checkint.sh [new file with mode: 0755]
packaging/rpm/util/odlrepo.sh [new file with mode: 0755]
packaging/rpm/util/setbuildrpm.sh [new file with mode: 0755]

diff --git a/packaging/rpm/util/checkint.sh b/packaging/rpm/util/checkint.sh
new file mode 100755 (executable)
index 0000000..6c8a387
--- /dev/null
@@ -0,0 +1,339 @@
+#!/bin/bash
+#set -vx
+
+options=$1
+gitdir=$2
+
+function usage {
+    local rc=$1
+    local outstr=$2
+
+    if [ "$outstr" != "" ]; then
+        echo "$outstr"
+        echo
+    fi
+
+    echo "This script is used to validate the rpm builds for each edition."
+    echo "The script will compare the different editions against each other"
+    echo "to identify the proper filters when starting the controller,"
+    echo "list the dependencies in the different editions and identify"
+    echo "any inconsistencies between the edition poms and the project specs."
+    echo
+    echo "Usage: `basename $0` [OPTION...]"
+    echo
+    echo "Test options:"
+    echo "  --options OPTIONS  List of test options. Available options:"
+    echo "                     integration: compare integration editions"
+    echo "                     pom: get pom dependencies from integration poms"
+    echo "                     spec: compare projects specs against the pom dependencies"
+    echo "  --gitdir DIR       git root directory where projects are cloned"
+    echo
+    echo "Help options:"
+    echo "  -?, -h, --h, --help  Display this help and exit"
+    echo
+
+    exit $rc
+}
+
+function parse_options {
+    while true ; do
+        case "$1" in
+        --options)
+            shift; options="$1"; shift
+            ;;
+
+         --gitdir)
+            shift; gitdir="$1"; shift
+            if [ "$gitdir" = "" ]; then
+                usage 1 "Missing directory.";
+            fi
+            ;;
+
+        -? | -h | --h | --help)
+            usage 0
+            ;;
+        "")
+            break
+            ;;
+        *)
+            echo "Ignoring unknown option: $1"; shift;
+        esac
+    done
+}
+
+function array_contains () {
+    local array="$1[@]"
+    local seeking=$2
+    local in=1
+    for element in "${!array}"; do
+        if [ $element = $seeking ]; then
+            in=0
+            break
+        fi
+    done
+    return $in
+}
+
+
+function compare_integration () {
+    local gitdir=$1
+
+    echo
+    echo "========================================================================="
+    echo "                          Comparing dirs"
+    echo "========================================================================="
+
+    cd $gitdir/integration
+
+    rm -rf /tmp/base/*
+    basezip=$(find . -name "*distributions-base*.zip")
+    unzip -qd /tmp/base $basezip
+
+    rm -rf /tmp/virt/*
+    virtzip=$(find . -name "*distributions-virtualization*.zip")
+    unzip -qd /tmp/virt $virtzip
+
+    rm -rf /tmp/sp/*
+    spzip=$(find . -name "*distributions-serviceprovider*.zip")
+    unzip -qd /tmp/sp $spzip
+
+    # Compare one edition against another.
+
+    echo
+    echo "Compare base and virt:"
+    echo "-------------------------------------------------------------------------"
+    diff -qr /tmp/base/opendaylight/ /tmp/virt/opendaylight/
+    echo
+    echo "Compare base and sp:"
+    echo "-------------------------------------------------------------------------"
+    diff -qr /tmp/base/opendaylight/ /tmp/sp/opendaylight/
+    echo
+    echo "Compare virt and sp:"
+    echo "-------------------------------------------------------------------------"
+    diff -qr /tmp/virt/opendaylight/ /tmp/sp/opendaylight/
+
+    # Compare one edition against the other two.
+
+    rm -rf /tmp/base_virt
+    mkdir /tmp/base_virt
+    cp -rf /tmp/base/* /tmp/base_virt/
+    cp -rf /tmp/virt/* /tmp/base_virt/
+
+    rm -rf /tmp/base_sp
+    mkdir /tmp/base_sp
+    cp -rf /tmp/base/* /tmp/base_sp/
+    cp -rf /tmp/sp/* /tmp/base_sp/
+
+    rm -rf /tmp/virt_sp
+    mkdir /tmp/virt_sp
+    cp -rf /tmp/virt/* /tmp/virt_sp/
+    cp -rf /tmp/sp/* /tmp/virt_sp/
+
+    echo
+    echo
+    echo "Compare base and virt_sp."
+    echo "-------------------------------------------------------------------------"
+    diff -qr /tmp/base/opendaylight/ /tmp/virt_sp/opendaylight/
+    echo
+    echo "Compare virt and base_sp. Useful to see what virt pulls in - look for Only in /tmp/virt."
+    echo "-------------------------------------------------------------------------"
+    diff -qr /tmp/virt/opendaylight/ /tmp/base_sp/opendaylight/
+    echo
+    echo "Compare sp and base_virt. Useful to see what sp pulls in - look for Only in /tmp/sp."
+    echo "-------------------------------------------------------------------------"
+    diff -qr /tmp/sp/opendaylight/ /tmp/base_virt/opendaylight/
+}
+
+function check_affinity () {
+#      allaffinity=$(find /tmp/virt -name "*affinity.*.jar")
+#      while read line; do
+#              if [ "line" ]
+    echo "here"
+}
+
+function read_dom () {
+    local IFS=\>
+    read -d \< ENTITY CONTENT
+}
+
+function read_poms () {
+    local gitdir="$1"
+    local distribution="$2"
+    local pomfile=$gitdir/integration/distributions/$distribution/pom.xml
+    local FILE=$pomfile
+    local i=$pomcnt
+    local groupy=0
+    local state="null"
+
+    echo
+    echo "read_poms $gitdir $distribution"
+    echo "-------------------------------------------------------------------------"
+
+    while read_dom; do
+        case "$state" in
+        null)
+            if [ "$ENTITY" = "dependencies" ]; then
+                state="dependencies"
+            fi
+            ;;
+
+        dependencies)
+            case "$ENTITY" in
+            groupId)
+                groupIds[i]=$CONTENT
+                groups=1
+                editions[i]=$distribution
+                ;;
+
+            artifactId)
+                if [ $groups -eq 1 ]; then
+                    artifactIds[i]=$CONTENT
+                fi
+                ;;
+
+            version)
+                if [ $groups -eq 1 ]; then
+                    versions[i]=$CONTENT
+                    groups=0
+                    ((i++))
+                fi
+                ;;
+
+            /dependencies)
+                state="done"
+                break
+                ;;
+            esac
+            ;;
+        esac
+    done < "$pomfile"
+
+    end=$((i-1))
+    for index in `seq $pomcnt $end`; do
+        echo "$index artifact: ${groupIds[$index]}.${artifactIds[$index]}-${versions[$index]}"
+    done
+
+    pomcnt=$i
+}
+
+function check_poms () {
+    local gitdir=$1
+    pomcnt=0
+
+    echo
+    echo "========================================================================="
+    echo "                          Checking poms"
+    echo "========================================================================="
+
+    read_poms "$gitdir" "base"
+    read_poms "$gitdir" "serviceprovider"
+    read_poms "$gitdir" "virtualization"
+}
+
+function read_spec () {
+    local gitdir="$1"
+    local project="$2"
+    local specfile=$gitdir/integration/packaging/rpm/opendaylight-$project.spec
+    local FILE=$specfile
+    local state="null"
+    local i=0
+
+    unset specarts
+
+    echo
+    echo "read_spec $gitdir $project"
+    echo "-------------------------------------------------------------------------"
+
+    while read line; do
+        case "$state" in
+        null)
+            if [ "$line" = "done <<'.'" ]; then
+                state="artifacts"
+            fi
+            ;;
+
+        artifacts)
+            if [ "$line" = "." ]; then
+                state="done"
+                break
+            else
+                specarts[i]=$line
+                ((i++))
+            fi
+            ;;
+        esac
+    done < "$specfile"
+
+    for index in ${!specarts[*]}; do
+        echo "$index spec artifact: ${specarts[$index]}"
+    done
+}
+
+
+function check_project () {
+    local gitdir=$1
+    local project=$2
+    local specfile=$gitdir/integration/packaging/rpm/opendaylight-$project.specfile
+    local k=0
+
+    unset notfoundarts
+    unset notfoundeds
+
+    echo
+    echo "check_project $gitdir $project"
+    echo "-------------------------------------------------------------------------"
+
+    read_spec "$gitdir" "$project"
+
+    for i in ${!groupIds[*]}; do
+        if [ ${groupIds[$i]} = "org.opendaylight.$project" ]; then
+            found=0
+            for j in ${!specarts[*]}; do
+                specart=$(echo ${specarts[$j]} | sed -e "s/-\*.*//")
+                artifactId=${artifactIds[$i]}
+                if [ "$specart" = "$artifactId" ]; then
+                    found=1
+                    break
+                fi
+            done
+
+            if [ $found -eq 0 ]; then
+                notfoundeds[k]=${editions[$i]}
+                notfoundarts[k]=${artifactIds[$i]}
+                ((k++))
+            fi
+        fi
+    done
+
+    for index in ${!notfoundarts[*]}; do
+        echo ">>>>> $index missing artifact: ${notfoundeds[$index]}: ${notfoundarts[$index]}"
+    done
+}
+
+function check_specs () {
+    local gitdir=$1
+
+    echo
+    echo "========================================================================="
+    echo "                          Checking specs"
+    echo "========================================================================="
+
+    check_project "$gitdir" "affinity"
+    check_project "$gitdir" "bgpcep"
+    check_project "$gitdir" "lispflowmapping"
+    check_project "$gitdir" "snmp4sdn"
+    check_project "$gitdir" "yangtools"
+}
+
+function main () {
+    parse_options "$@"
+
+    if [ ! -d "$dir" ]; then
+        usage 1 "Invalid path."
+    fi
+
+}
+
+main "$@"
+
+exit 0
diff --git a/packaging/rpm/util/odlrepo.sh b/packaging/rpm/util/odlrepo.sh
new file mode 100755 (executable)
index 0000000..741d667
--- /dev/null
@@ -0,0 +1,188 @@
+#!/bin/bash
+#set -vx
+
+mkrepofile=0
+mkrepo=0
+crrepo=0
+cprpms=0
+repodir="/home/repo"
+yumdir="/etc/yum.repos.d"
+reponame="localodl.repo"
+rpmdir="~/data/rpmbuild/test1/bld_1/repo"
+
+
+function usage {
+    local rc=$1
+    local outstr=$2
+
+    if [ "$outstr" != "" ]; then
+        echo "$outstr"
+        echo
+    fi
+
+    echo "This script is used to create a local yum repo for testing rpm installs."
+    echo "The script can make the local repo directory, run createrepo to"
+    echo "initialize it as a repo, create the yum repo file and copy rpms to"
+    echo "the repo."
+    echo
+    echo "Usage: `basename $0` [OPTION...]"
+    echo
+    echo "Script options"
+    echo "  --mkrepo           make the repodir"
+    echo "  --crrepo           createrepo the repodir"
+    echo "  --mkrepofile       name of the yum.repos.d repo file"
+    echo "  --cprpms           copy the rpms to the repo"
+    echo "  --repodir DIR      directory to make into a repo"
+    echo "  --yumdir DIR       yum directory with repo files"
+    echo "  --rpmdir DIR       directory with rpms"
+    echo
+    echo "Help options:"
+    echo "  -?, -h, --h, --help  Display this help and exit"
+    echo
+
+    exit $rc
+}
+
+function parse_options {
+    while true ; do
+        case "$1" in
+        --mkrepofile)
+            shift; mkrepofile=1;
+            ;;
+
+        --mkrepo)
+            shift; mkrepo=1;
+            ;;
+
+        --crrepo)
+            shift; crrepo=1;
+            ;;
+
+        --cprpms)
+            shift; cprpms=1;
+            ;;
+
+         --reponame)
+            shift; reponame="$1"; shift
+            if [ "$reponame" = "" ]; then
+                usage 1 "Missing repo name.";
+            fi
+            ;;
+
+         --repodir)
+            shift; repodir="$1"; shift
+            if [ "$repodir" = "" ]; then
+                usage 1 "Missing yum directory.";
+            fi
+            ;;
+
+         --yumdir)
+            shift; yumdir="$1"; shift
+            if [ "$yumdir" = "" ]; then
+                usage 1 "Missing yum directory.";
+            fi
+            ;;
+
+         --rpmdir)
+            shift; rpmdir="$1"; shift
+            if [ "$rpmdir" = "" ]; then
+                usage 1 "Missing rpm directory.";
+            fi
+            ;;
+
+        -? | -h | --h | --help)
+            usage 0
+            ;;
+        "")
+            break
+            ;;
+        *)
+            echo "Ignoring unknown option: $1"; shift;
+        esac
+    done
+}
+
+function check_dir () {
+    local dir=$1
+
+    if [ ! -d "$dir" ]; then
+        usage 1 "Invalid dir: $dir"
+    fi
+}
+
+function make_repo_file () {
+    local yumdir=$1
+    local reponame=$2
+
+    rm -f $yumdir/$reponame
+
+    echo "$yumdir/$reponame"
+    cat <<EOF > $yumdir/$reponame
+[localodl]
+name=Local ODL
+baseurl=file:///home/repo
+enabled=1
+gpgcheck=0
+metadata_expire=1m
+
+[localodlftp]
+name=Local FTP ODL
+baseurl=ftp://127.0.0.1/pub
+enabled=1
+gpgcheck=0
+metadata_expire=1m
+EOF
+}
+
+function make_repo () {
+    local repodir=$1
+
+    mkdir -p $repodir
+    chmod -R 777 $repodir
+}
+
+function create_repo () {
+    local repodir=$1
+
+    check_dir $repodir
+
+    createrepo -d $repodir
+}
+
+function copy_rpms_to_repo () {
+    local rpmdir=$1
+    local repodir=$2
+
+    check_dir $rpmdir
+    check_dir $repodir
+
+    for rpm in $( find $rpmdir -name *.rpm ); do
+        cp $rpm $repodir
+    done
+}
+
+function main () {
+    parse_options "$@"
+
+    eval rpmdir=$rpmdir
+
+    if [ $mkrepo -eq 1 ]; then
+        make_repo $repodir
+    fi
+
+    if [ $cprpms -eq 1 ]; then
+        copy_rpms_to_repo $rpmdir $repodir
+    fi
+
+    if [ $crrepo -eq 1 ]; then
+        create_repo $repodir
+    fi
+
+    if [ $mkrepofile -eq 1 ]; then
+        make_repo_file $yumdir $reponame
+    fi
+}
+
+main "$@"
+
+exit 0
diff --git a/packaging/rpm/util/setbuildrpm.sh b/packaging/rpm/util/setbuildrpm.sh
new file mode 100755 (executable)
index 0000000..ebd0822
--- /dev/null
@@ -0,0 +1,181 @@
+#!/bin/bash
+#set -vx
+
+archive=0
+cloneremote=0
+clonelocal=0
+gitdir="~/git"
+rpmbuilddir="~/rpmbuild"
+version="0.1.0"
+
+projects=(integration controller ovsdb openflowjava openflowplugin lispflowmapping snmp4sdn affinity yangtools bgpcep opendove)
+
+function usage {
+    local rc=$1
+    local outstr=$2
+
+    if [ "$outstr" != "" ]; then
+        echo "$outstr"
+        echo
+    fi
+
+    echo "This script is used to prepare a buildrpm environment."
+    echo "The script can archive and existing git dir containing all the projects,"
+    echo "clone all projects from a remote repo or from a local repo."
+    echo
+    echo "Usage: `basename $0` [OPTION...]"
+    echo
+    echo "Script options"
+    echo "  --archive          archive all the projects in the git directory"
+    echo "  --cloneremote      clone all the projects in the remote repo"
+    echo "  --clonelocal       clone all the projects in the local repo"
+    echo "  --gitdir DIR       git root directory where projects are cloned"
+    echo "  --rpmbuilddir DIR  rpmbuild root directory where rpms are built"
+    echo "  --version VERSION  version tag to use for archives"
+    echo
+    echo "Help options:"
+    echo "  -?, -h, --h, --help  Display this help and exit"
+    echo
+
+    exit $rc
+}
+
+function parse_options {
+    while true ; do
+        case "$1" in
+        --archive)
+            shift; archive=1;
+            ;;
+
+        --cloneremote)
+            shift; cloneremote=1;
+            ;;
+
+        --clonelocal)
+            shift; clonelocal=1;
+            ;;
+
+         --gitdir)
+            shift; gitdir="$1"; shift
+            if [ "$gitdir" = "" ]; then
+                usage 1 "Missing git directory.";
+            fi
+            ;;
+
+         --outdir)
+            shift; outdir="$1"; shift
+            if [ "$outdir" = "" ]; then
+                usage 1 "Missing out directory.";
+            fi
+            ;;
+
+         --rpmbuilddir)
+            shift; rpmbuilddir="$1"; shift
+            if [ "$rpmbuilddir" = "" ]; then
+                usage 1 "Missing rpmbuild directory.";
+            fi
+            ;;
+
+         --version)
+            shift; version="$1"; shift
+            if [ "$version" = "" ]; then
+                usage 1 "Missing version.";
+            fi
+            ;;
+
+        -? | -h | --h | --help)
+            usage 0
+            ;;
+        "")
+            break
+            ;;
+        *)
+            echo "Ignoring unknown option: $1"; shift;
+        esac
+    done
+}
+
+function check_dir () {
+    local dir=$1
+
+    if [ ! -d "$dir" ]; then
+        usage 1 "Invalid dir: $dir"
+    fi
+}
+
+function archive_projects () {
+    local gitdir=$1
+    local rpmbuilddir=$2
+    local version=$3
+
+    check_dir "$gitdir"
+    check_dir "$rpmbuilddir"
+
+    cd $gitdir
+    mkdir -p zips
+
+    for project in ${projects[*]}; do
+        cd $gitdir/$project
+        zipfile=../zips/opendaylight-$project-$version.tar.xz
+        echo "Archiving $project to $zipfile"
+        git archive --prefix=opendaylight-$project-$version/ HEAD | xz > $zipfile
+        src=$gitdir/zips/opendaylight-$project-$version.tar.xz
+        echo "Linking $src to $rpmbuilddir/SOURCES"
+        ln -sf $src $rpmbuilddir/SOURCES
+    done
+}
+
+function clone_remote () {
+    local outdir=$1
+
+    mkdir -p $outdir
+    cd $outdir
+
+    for project in ${projects[*]}; do
+        echo "Cloning $project to $outdir/$project"
+        git clone https://git.opendaylight.org/gerrit/p/$project.git
+    done
+}
+
+function clone_local () {
+    local gitdir=$1
+    local outdir=$2
+
+    mkdir -p $outdir
+    cd $outdir
+
+    check_dir "$gitdir"
+
+    for project in ${projects[*]}; do
+        echo "Cloning $project to $outdir/$project"
+        git clone $gitdir/$project
+    done
+}
+
+function main () {
+    parse_options "$@"
+
+    eval gitdir=$gitdir
+    eval rpmbuilddir=$rpmbuilddir
+
+
+    if [ ! -d "$gitdir" ]; then
+        usage 1 "Invalid path."
+    fi
+
+    if [ $archive -eq 1 ]; then
+        archive_projects "$gitdir" "$rpmbuilddir" "$version"
+    fi
+
+    if [ $cloneremote -eq 1 ]; then
+        clone_remote $outdir
+    fi
+
+    if [ $clonelocal -eq 1 ]; then
+        clone_local $gitdir $outdir
+    fi
+}
+
+main "$@"
+
+exit 0