Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added bin/parse-appname-version with corresponding test
example usage:: appver="core-14.2-jessie-amd64" parsed_appname_version=$($BT/bin/parse-appname-version $appver) read appname appversion codename arch <<< "$parsed_appname_version" echo "appname: $appname" echo "appversion: $appversion" echo "codename: $codename" echo "arch: $arch"
- Loading branch information
1 parent
76a15fb
commit 57b1604
Showing
2 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/bin/bash -e | ||
# Copyright (c) 2011-2017 TurnKey GNU/Linux - http://www.turnkeylinux.org | ||
# | ||
# This file is part of buildtasks. | ||
# | ||
# Buildtasks is free software; you can redistribute it and/or modify it | ||
# under the terms of the GNU Affero General Public License as published by the | ||
# Free Software Foundation; either version 3 of the License, or (at your | ||
# option) any later version. | ||
|
||
|
||
fatal() { echo -e "FATAL [$(basename $0)]: $@" 1>&2; exit 1; } | ||
|
||
usage() { | ||
cat<<EOF | ||
Syntax: $0 appname-version | ||
Verify and parse appname-version | ||
Echoes space-delimeted if valid: appname appversion codename arch | ||
Arguments:: | ||
appname-version - appname-appversion-codename-arch | ||
e.g., core-14.2-jessie-amd64 | ||
EOF | ||
exit 1 | ||
} | ||
|
||
if [[ "$#" != "1" ]]; then | ||
usage | ||
fi | ||
|
||
if [[ $1 =~ ^([a-z0-9-]+)-([0-9\.]+)-([a-z]+)-([a-z0-9]+)$ ]]; then | ||
appname=${BASH_REMATCH[1]} | ||
appversion=${BASH_REMATCH[2]} | ||
codename=${BASH_REMATCH[3]} | ||
architecture=${BASH_REMATCH[4]} | ||
else | ||
syntax="Syntax: appname-appversion-codename-arch" | ||
fatal "appname-version incorrect syntax\n$syntax" | ||
fi | ||
|
||
case $codename in | ||
squeeze|wheezy|jessie|stretch) ;; | ||
*) fatal "unrecognized codename: $codename" ;; | ||
esac | ||
|
||
case $architecture in | ||
i386|amd64) ;; | ||
*) fatal "unrecognized architecture: $architecture" ;; | ||
esac | ||
|
||
echo $appname $appversion $codename $architecture | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/bash -e | ||
|
||
fatal() { echo "FATAL [$(basename $0)]: $@" 1>&2; exit 1; } | ||
info() { echo "INFO [$(basename $0)]: $@"; } | ||
|
||
usage() { | ||
cat<<EOF | ||
Syntax: $0 | ||
Test appname-version parsing | ||
EOF | ||
exit 1 | ||
} | ||
|
||
export BT=$(dirname $(dirname $(readlink -f $0))) | ||
|
||
appver="core-14.2-jessie-amd64" | ||
info "1: should pass ($appver)" | ||
parsed_appname_version=$($BT/bin/parse-appname-version $appver) | ||
read appname appversion codename arch <<< "$parsed_appname_version" | ||
[ "$appname" == "core" ] || fatal "appname failure: $appname" | ||
[ "$appversion" == "14.2" ] || fatal "appversion failure: $appversion" | ||
[ "$codename" == "jessie" ] || fatal "codename failure: $codename" | ||
[ "$arch" == "amd64" ] || fatal "arch failure: $arch" | ||
|
||
appver="nginx-php-fastcgi-13.0-wheezy-i386" | ||
info "2: should pass ($appver)" | ||
parsed_appname_version=$($BT/bin/parse-appname-version $appver) | ||
read appname appversion codename arch <<< "$parsed_appname_version" | ||
[ "$appname" == "nginx-php-fastcgi" ] || fatal "appname failure: $appname" | ||
[ "$appversion" == "13.0" ] || fatal "appversion failure: $appversion" | ||
[ "$codename" == "wheezy" ] || fatal "codename failure: $codename" | ||
[ "$arch" == "i386" ] || fatal "arch failure: $arch" | ||
|
||
appver="core-14.2" | ||
info "3: should fail ($appver)" | ||
$BT/bin/parse-appname-version $appver && fatal "should have failed" | ||
|
||
appver="core-14.2-xxxxxxx-amd64" | ||
info "4: should fail ($appver)" | ||
$BT/bin/parse-appname-version $appver && fatal "should have failed" | ||
|
||
appver="core-14.2-jessie-xxxxx" | ||
info "5: should fail ($appver)" | ||
$BT/bin/parse-appname-version $appver && fatal "should have failed" | ||
|
||
echo | ||
info "all tests passed" | ||
|