openpkg/release.sh

changeset 13
cb59d6afeb61
child 428
f880f219c566
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/openpkg/release.sh	Tue Jan 06 23:40:39 2009 +0100
     1.3 @@ -0,0 +1,147 @@
     1.4 +#!@l_prefix@/lib/openpkg/bash
     1.5 +##
     1.6 +##  release -- OpenPKG Release Determination Utility
     1.7 +##  Copyright (c) 2000-2007 OpenPKG Foundation e.V. <http://openpkg.net/>
     1.8 +##  Copyright (c) 2000-2007 Ralf S. Engelschall <http://engelschall.com/>
     1.9 +##
    1.10 +##  Permission to use, copy, modify, and distribute this software for
    1.11 +##  any purpose with or without fee is hereby granted, provided that
    1.12 +##  the above copyright notice and this permission notice appear in all
    1.13 +##  copies.
    1.14 +##
    1.15 +##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
    1.16 +##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    1.17 +##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    1.18 +##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
    1.19 +##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.20 +##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    1.21 +##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
    1.22 +##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    1.23 +##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    1.24 +##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
    1.25 +##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    1.26 +##  SUCH DAMAGE.
    1.27 +##
    1.28 +
    1.29 +#   configuration
    1.30 +prefix="@l_prefix@"
    1.31 +
    1.32 +#   minimum command line parsing
    1.33 +opt_F="OpenPKG-%t %u"
    1.34 +opt_r=""
    1.35 +while [ $# -gt 0 ]; do
    1.36 +    case "$1" in
    1.37 +        -F          ) opt_F="$2"; shift;                      shift ;;
    1.38 +        --fmt       ) opt_F="$2"; shift;                      shift ;;
    1.39 +        -F*         ) opt_F="`expr ".$1" : '.-F\(.*\)'`";     shift ;;
    1.40 +        --fmt=*     ) opt_F="`expr ".$1" : '.--fmt=\(.*\)'`"; shift ;;
    1.41 +        -r          ) opt_r="$2"; shift;                      shift ;;
    1.42 +        --release   ) opt_r="$2"; shift;                      shift ;;
    1.43 +        -r*         ) opt_r="`expr ".$1" : '.-r\(.*\)'`";     shift ;;
    1.44 +        --release=* ) opt_r="`expr ".$1" : '.--release=\(.*\)'`"; shift ;;
    1.45 +        *       ) break ;;
    1.46 +    esac
    1.47 +done
    1.48 +
    1.49 +#   translate a release number to a release tag
    1.50 +number_to_tag () {
    1.51 +    sed -e 's;^;X;' \
    1.52 +        -e 's;^X\([^.-][^.-]*\.[^.-][^.-]*\)\.[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*$;\1-SOLID;' \
    1.53 +        -e 's;^X\([^.-][^.-]*\.[^.-][^.-]*\)\.[^.-][^.-]*.*$;\1-RELEASE;' \
    1.54 +        -e 's;^X\([^.-][^.-]*\)\.[^.-][^.-]*.*$;\1-STABLE;' \
    1.55 +        -e 's;^X[^.-][^.-]*.*$;CURRENT;' \
    1.56 +        -e 's;^X.*$;UNKNOWN;'
    1.57 +}
    1.58 +
    1.59 +#   sanity check a release tag
    1.60 +tag_sanity () {
    1.61 +    sed -e 's;^;X;' \
    1.62 +        -e 's;^X[^.-][^.-]*\.[^.-][^.-]*-RELEASE$;OK;' \
    1.63 +        -e 's;^X[^.-][^.-]*\.[^.-][^.-]*-SOLID-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$;OK;' \
    1.64 +        -e 's;^X[^.-][^.-]*\.[^.-][^.-]*-SOLID$;OK;' \
    1.65 +        -e 's;^X[^.-][^.-]*-STABLE-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$;OK;' \
    1.66 +        -e 's;^X[^.-][^.-]*-STABLE$;OK;' \
    1.67 +        -e 's;^XCURRENT-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$;OK;' \
    1.68 +        -e 's;^XCURRENT$;OK;' \
    1.69 +        -e 's;^X.*$;ERROR;'
    1.70 +}
    1.71 +
    1.72 +#   determine release
    1.73 +tag=""
    1.74 +if [ ".$opt_r" != . ]; then
    1.75 +    tag=`echo ".$opt_r" | sed -e 's;^\.;;' | number_to_tag`
    1.76 +elif [ -f "$prefix/etc/openpkg/release" ]; then
    1.77 +    tag=`(cat $prefix/etc/openpkg/release; echo "") | sed \
    1.78 +        -e 's;^;X;' \
    1.79 +        -e 's;^X *TAG *= *\([^ ][^ ]*\).*;\1;' \
    1.80 +        -e '/^X/d' | \
    1.81 +        sed -n -e '$p'`
    1.82 +else
    1.83 +    tag=`$prefix/bin/openpkg rpm \
    1.84 +        -q --qf '%{VERSION}\n' openpkg | number_to_tag`
    1.85 +fi
    1.86 +if [ .`echo ".$tag" | sed -e 's;^\.;;' | tag_sanity` = .ERROR ]; then
    1.87 +    echo "openpkg:release: WARNING: unable to determine OpenPKG release tag" 1>&2
    1.88 +    tag="UNKNOWN"
    1.89 +fi
    1.90 +
    1.91 +#   determine distribution URL
    1.92 +url=""
    1.93 +if [ -f "$prefix/etc/openpkg/release" ]; then
    1.94 +    url=`(cat $prefix/etc/openpkg/release; echo "") | sed \
    1.95 +        -e 's;^;X;' \
    1.96 +        -e 's;^X *URL *= *\([^ ][^ ]*\).*;\1;' \
    1.97 +        -e '/^X/d' | \
    1.98 +        sed -n -e '$p'`
    1.99 +fi
   1.100 +if [ ".$url" = . ]; then
   1.101 +    url="ftp://ftp.openpkg.org/*"
   1.102 +fi
   1.103 +case ".$url" in
   1.104 +    */\* )
   1.105 +        url=`echo ".$url" | sed -e 's;^\.;;' -e 's;/\*$;;'`
   1.106 +        case "$tag" in
   1.107 +            CURRENT )
   1.108 +                url="$url/current/SRC/"
   1.109 +                ;;
   1.110 +            CURRENT-* )
   1.111 +                version=`echo "$tag" | sed -e 's;^CURRENT-;;'`
   1.112 +                url="$url/current/$version/"
   1.113 +                ;;
   1.114 +            *-STABLE )
   1.115 +                version=`echo "$tag" | sed -e 's;^\(.*\)-STABLE$;\1;'`
   1.116 +                url="$url/stable/$version/"
   1.117 +                ;;
   1.118 +            *-STABLE-* )
   1.119 +                version=`echo "$tag" | sed -e 's;^\(.*\)-STABLE-\(.*\)$;\1.\2;'`
   1.120 +                url="$url/stable/$version/"
   1.121 +                ;;
   1.122 +            *-SOLID )
   1.123 +                version=`echo "$tag" | sed -e 's;^\(.*\)-SOLID$;\1;'`
   1.124 +                url="$url/solid/$version/"
   1.125 +                ;;
   1.126 +            *-SOLID-* )
   1.127 +                version=`echo "$tag" | sed -e 's;^\(.*\)-SOLID-\(.*\)$;\1.\2;'`
   1.128 +                url="$url/solid/$version/"
   1.129 +                ;;
   1.130 +            *-RELEASE )
   1.131 +                version=`echo "$tag" | sed -e 's;^\(.*\)-RELEASE$;\1;'`
   1.132 +                url="$url/release/$version/"
   1.133 +                ;;
   1.134 +        esac
   1.135 +        ;;
   1.136 +esac
   1.137 +
   1.138 +#   read uuid
   1.139 +[ -f "$prefix/etc/openpkg/uuid" ] && . "$prefix/etc/openpkg/uuid"
   1.140 +
   1.141 +#   generate output
   1.142 +echo "X$opt_F" |\
   1.143 +sed -e 's/^X//' \
   1.144 +    -e "s;%t;${tag};g" \
   1.145 +    -e "s;%u;${url};g" \
   1.146 +    -e "s;%r;${UUID_REGISTRY};g" \
   1.147 +    -e "s;%i;${UUID_INSTANCE};g" \
   1.148 +    -e "s;%p;${UUID_PLATFORM};g" \
   1.149 +    -e 's/\\n/^/g' | tr '^' '\012'
   1.150 +

mercurial