test/update.sh
author J. Ali Harlow <ali@juiblex.co.uk>
Thu Jul 14 12:49:48 2016 +0100 (2016-07-14)
changeset 491 b18e0bf48a91
parent 456 bae5adee8c8c
permissions -rwxr-xr-x
razor_path_to_uri() should cope with relative paths better
     1 #!/bin/sh
     2 if [ $# -gt 0 ]; then
     3     razor="$1"
     4 else
     5     razor=../src/razor
     6 fi
     7 fs_check_file()
     8 {
     9     if [ ! -e "$tmpdir$1" ]; then 
    10 	echo $1: Not in filesystem >&2
    11 	ls -R "$tmpdir" >&2
    12 	exit 1
    13     fi
    14 }
    15 fs_check_file_contents()
    16 {
    17     fs_check_file "$1"
    18     if [ `cat "$tmpdir$1"` != "$2" ]; then
    19 	echo $1: Unexpected contents >&2
    20 	cat "$tmpdir$1" >&2
    21 	exit 1
    22     fi
    23 }
    24 fs_check_no_file()
    25 {
    26     if [ -e "$tmpdir$1" ]; then 
    27 	echo $1: Still in filesystem >&2
    28 	exit 1
    29     fi
    30 }
    31 check_file()
    32 {
    33     $razor list-files | grep -F -x "$1" > /dev/null
    34     if [ $? -ne 0 ]; then
    35 	echo $1: Not in database >&2
    36 	$razor list-files >&2
    37 	exit 1
    38     fi
    39     $razor list-files "$1" | grep -F -x "$1" > /dev/null
    40     if [ $? -ne 0 ]; then
    41 	echo $1: Not seen by patterned list >&2
    42 	$razor list-files "$1" >&2
    43 	exit 1
    44     fi
    45     pkgs=`$razor list-file-packages "$1"`
    46     if [ -z "$pkgs" ]; then
    47 	echo $1: Not owned by any package >&2
    48 	$razor list-file-packages "$1"
    49 	exit 1
    50     fi
    51     for nevra in "$pkgs"; do
    52 	name=`echo $nevra | sed 's/\-.*$//'`
    53 	$razor list-package-files "$name" | grep -F -x "$1" > /dev/null
    54 	if [ $? -ne 0 ]; then
    55 	    echo $1: Not in database for package $name >&2
    56 	    $razor list-package-files "$name"
    57 	    exit 1
    58 	fi
    59     done
    60     fs_check_file $1
    61 }
    62 check_no_file()
    63 {
    64     $razor list-files | grep -F -x "$1" > /dev/null
    65     if [ $? -eq 0 ]; then
    66 	echo $1: Still in database >&2
    67 	exit 1
    68     fi
    69     fs_check_no_file $1
    70 }
    71 check_install_count()
    72 {
    73     count=`$razor list "$1" | wc -l`
    74     if [ "$count" != "$2" ]; then
    75 	echo $1: Install count $count, should be $2 >&2
    76 	exit 1
    77     fi
    78 }
    79 set_repository()
    80 {
    81     export YUM_URL="file:`pwd`/$1"
    82     cp $1/repodata/primary.xml.gz $1/repodata/filelists.xml.gz .
    83     rm -rf rpms
    84     ln -s $1/Packages rpms
    85 }
    86 tmpdir=`mktemp -dt` || exit 1
    87 export RAZOR_ROOT="file:$tmpdir"
    88 $razor init || exit 1
    89 set_repository base
    90 $razor import-yum || exit 1
    91 $razor install --relocate /usr=/opt zip || exit 1
    92 fs_check_file_contents /opt/bin/zip zip-1-1
    93 fs_check_file /opt/var/lib/zip/data.zap
    94 trap "set_repository base" 0
    95 set_repository updates
    96 $razor import-yum || exit 1
    97 $razor update --relocate /usr=/opt || exit 1
    98 check_file /opt/bin/zip
    99 fs_check_file_contents /opt/bin/zip zip-2-1
   100 fs_check_file /opt/var/lib/zip/data.zap
   101 $razor remove zip || exit 1
   102 fs_check_no_file /opt/var/lib/zip/data.zap
   103 set_repository base
   104 $razor import-yum || exit 1
   105 $razor install --relocate /usr=/opt zip || exit 1
   106 $razor install --relocate /usr=/opt zip || exit 1
   107 check_install_count zip 2
   108 set_repository updates
   109 $razor import-yum || exit 1
   110 $razor update --relocate /usr=/opt || exit 1
   111 check_file /opt/bin/zip
   112 fs_check_file_contents /opt/bin/zip zip-2-1
   113 fs_check_file /opt/var/lib/zip/data.zap
   114 check_install_count zip 1
   115 $razor remove zip || exit 1
   116 fs_check_no_file /opt/var/lib/zip/data.zap
   117 set_repository base
   118 $razor import-yum || exit 1
   119 $razor install --relocate /usr=/opt zip || exit 1
   120 $razor update --relocate /usr=/opt zip || exit 1
   121 check_install_count zip 1
   122 rm -rf "$tmpdir"