michael@13: #!@l_prefix@/lib/openpkg/bash michael@13: ## michael@13: ## release -- OpenPKG Release Determination Utility michael@428: ## Copyright (c) 2000-2012 OpenPKG GmbH michael@13: ## michael@428: ## This software is property of the OpenPKG GmbH, DE MUC HRB 160208. michael@428: ## All rights reserved. Licenses which grant limited permission to use, michael@428: ## copy, modify and distribute this software are available from the michael@428: ## OpenPKG GmbH. michael@13: ## michael@428: ## THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED michael@13: ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF michael@13: ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. michael@13: ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR michael@13: ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, michael@13: ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT michael@13: ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF michael@13: ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND michael@13: ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, michael@13: ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT michael@13: ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF michael@13: ## SUCH DAMAGE. michael@13: ## michael@13: michael@13: # configuration michael@13: prefix="@l_prefix@" michael@13: michael@13: # minimum command line parsing michael@13: opt_F="OpenPKG-%t %u" michael@13: opt_r="" michael@13: while [ $# -gt 0 ]; do michael@13: case "$1" in michael@13: -F ) opt_F="$2"; shift; shift ;; michael@13: --fmt ) opt_F="$2"; shift; shift ;; michael@13: -F* ) opt_F="`expr ".$1" : '.-F\(.*\)'`"; shift ;; michael@13: --fmt=* ) opt_F="`expr ".$1" : '.--fmt=\(.*\)'`"; shift ;; michael@13: -r ) opt_r="$2"; shift; shift ;; michael@13: --release ) opt_r="$2"; shift; shift ;; michael@13: -r* ) opt_r="`expr ".$1" : '.-r\(.*\)'`"; shift ;; michael@13: --release=* ) opt_r="`expr ".$1" : '.--release=\(.*\)'`"; shift ;; michael@13: * ) break ;; michael@13: esac michael@13: done michael@13: michael@13: # translate a release number to a release tag michael@13: number_to_tag () { michael@13: sed -e 's;^;X;' \ michael@13: -e 's;^X\([^.-][^.-]*\.[^.-][^.-]*\)\.[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*$;\1-SOLID;' \ michael@13: -e 's;^X\([^.-][^.-]*\.[^.-][^.-]*\)\.[^.-][^.-]*.*$;\1-RELEASE;' \ michael@13: -e 's;^X\([^.-][^.-]*\)\.[^.-][^.-]*.*$;\1-STABLE;' \ michael@13: -e 's;^X[^.-][^.-]*.*$;CURRENT;' \ michael@13: -e 's;^X.*$;UNKNOWN;' michael@13: } michael@13: michael@13: # sanity check a release tag michael@13: tag_sanity () { michael@13: sed -e 's;^;X;' \ michael@13: -e 's;^X[^.-][^.-]*\.[^.-][^.-]*-RELEASE$;OK;' \ michael@13: -e 's;^X[^.-][^.-]*\.[^.-][^.-]*-SOLID-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$;OK;' \ michael@13: -e 's;^X[^.-][^.-]*\.[^.-][^.-]*-SOLID$;OK;' \ michael@13: -e 's;^X[^.-][^.-]*-STABLE-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$;OK;' \ michael@13: -e 's;^X[^.-][^.-]*-STABLE$;OK;' \ michael@13: -e 's;^XCURRENT-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$;OK;' \ michael@13: -e 's;^XCURRENT$;OK;' \ michael@13: -e 's;^X.*$;ERROR;' michael@13: } michael@13: michael@13: # determine release michael@13: tag="" michael@13: if [ ".$opt_r" != . ]; then michael@13: tag=`echo ".$opt_r" | sed -e 's;^\.;;' | number_to_tag` michael@13: elif [ -f "$prefix/etc/openpkg/release" ]; then michael@13: tag=`(cat $prefix/etc/openpkg/release; echo "") | sed \ michael@13: -e 's;^;X;' \ michael@13: -e 's;^X *TAG *= *\([^ ][^ ]*\).*;\1;' \ michael@13: -e '/^X/d' | \ michael@13: sed -n -e '$p'` michael@428: fi michael@428: if [ ".$tag" = . ]; then michael@13: tag=`$prefix/bin/openpkg rpm \ michael@428: -q --qf '%{RELEASE}\n' openpkg | number_to_tag` michael@13: fi michael@13: if [ .`echo ".$tag" | sed -e 's;^\.;;' | tag_sanity` = .ERROR ]; then michael@13: echo "openpkg:release: WARNING: unable to determine OpenPKG release tag" 1>&2 michael@13: tag="UNKNOWN" michael@13: fi michael@13: michael@13: # determine distribution URL michael@13: url="" michael@13: if [ -f "$prefix/etc/openpkg/release" ]; then michael@13: url=`(cat $prefix/etc/openpkg/release; echo "") | sed \ michael@13: -e 's;^;X;' \ michael@13: -e 's;^X *URL *= *\([^ ][^ ]*\).*;\1;' \ michael@13: -e '/^X/d' | \ michael@13: sed -n -e '$p'` michael@13: fi michael@13: if [ ".$url" = . ]; then michael@428: url="http://download.openpkg.org/stacks/*" michael@13: fi michael@13: case ".$url" in michael@13: */\* ) michael@13: url=`echo ".$url" | sed -e 's;^\.;;' -e 's;/\*$;;'` michael@13: case "$tag" in michael@13: CURRENT ) michael@428: url="$url/current/" michael@13: ;; michael@13: CURRENT-* ) michael@13: version=`echo "$tag" | sed -e 's;^CURRENT-;;'` michael@13: url="$url/current/$version/" michael@13: ;; michael@13: *-STABLE ) michael@13: version=`echo "$tag" | sed -e 's;^\(.*\)-STABLE$;\1;'` michael@13: url="$url/stable/$version/" michael@13: ;; michael@13: *-STABLE-* ) michael@13: version=`echo "$tag" | sed -e 's;^\(.*\)-STABLE-\(.*\)$;\1.\2;'` michael@13: url="$url/stable/$version/" michael@13: ;; michael@13: *-SOLID ) michael@13: version=`echo "$tag" | sed -e 's;^\(.*\)-SOLID$;\1;'` michael@13: url="$url/solid/$version/" michael@13: ;; michael@13: *-SOLID-* ) michael@13: version=`echo "$tag" | sed -e 's;^\(.*\)-SOLID-\(.*\)$;\1.\2;'` michael@13: url="$url/solid/$version/" michael@13: ;; michael@13: *-RELEASE ) michael@13: version=`echo "$tag" | sed -e 's;^\(.*\)-RELEASE$;\1;'` michael@13: url="$url/release/$version/" michael@13: ;; michael@428: * ) michael@428: subdir=`echo "$tag" | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` michael@428: url="$url/$subdir/" michael@428: ;; michael@13: esac michael@13: ;; michael@13: esac michael@13: michael@13: # read uuid michael@13: [ -f "$prefix/etc/openpkg/uuid" ] && . "$prefix/etc/openpkg/uuid" michael@13: michael@13: # generate output michael@13: echo "X$opt_F" |\ michael@13: sed -e 's/^X//' \ michael@13: -e "s;%t;${tag};g" \ michael@13: -e "s;%u;${url};g" \ michael@13: -e "s;%r;${UUID_REGISTRY};g" \ michael@13: -e "s;%i;${UUID_INSTANCE};g" \ michael@13: -e "s;%p;${UUID_PLATFORM};g" \ michael@13: -e 's/\\n/^/g' | tr '^' '\012' michael@13: