rc: tweak opnsense-version to return custom string combinations

This commit is contained in:
Franco Fichtner 2018-09-17 07:25:36 +02:00
parent b263fa7ee5
commit d7a6e9c8bb
3 changed files with 26 additions and 19 deletions

View File

@ -24,7 +24,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd Sep 16, 2018
.Dd Sep 17, 2018
.Dt OPNSENSE-VERSION 8
.Os
.Sh NAME
@ -48,6 +48,7 @@ It is similar to
.Sq Fl a
parameter, but not intended to handle operating system information.
.Pp
Multiple options can be specified to build a custom version string.
The options are as follows:
.Bl -tag -width ".Fl a" -offset indent
.It Fl a
@ -56,8 +57,6 @@ Return the firmware ABI string.
Return the product name.
.It Fl n
Return the release package name.
.It Fl V
Return the product name followed by its version.
.It Fl v
Return the release package version.
.El

View File

@ -56,7 +56,7 @@ abstract class Base
@unlink("{$file}.dec");
if (file_exists("{$file}.enc")) {
$version = trim(shell_exec('opnsense-version -V'));
$version = trim(shell_exec('opnsense-version -Nv'));
$result = "---- BEGIN {$tag} ----\n";
$result .= "Version: {$version}\n";
$result .= "Cipher: AES-256-CBC\n";

View File

@ -23,37 +23,41 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
PATTERN="s:[^\"]*\"\([^\"]*\)\"[^\"]*\"\([^\"]*\)\".*:\1=\2:"
VERSION="/usr/local/opnsense/version/opnsense"
OUTPUT=
if [ ! -f ${VERSION} ]; then
echo "Missing ${VERSION}" >&2
exit 1
fi
eval "$(grep -v '[{}]' ${VERSION} | sed 's/[^"]*"\([^"]*\)"[^"]*"\([^"]*\)".*/\1="\2"/')"
while getopts aNnVv OPT; do
case ${OPT} in
a)
echo ${product_abi}
exit 0
if [ -n "${OUTPUT}" ]; then
OUTPUT="${OUTPUT} "
fi
OUTPUT="${OUTPUT}\${product_abi}"
;;
N)
echo ${product_name}
exit 0
if [ -n "${OUTPUT}" ]; then
OUTPUT="${OUTPUT} "
fi
OUTPUT="${OUTPUT}\${product_name}"
;;
n)
echo ${product_id}
exit 0
;;
V)
# XXX replace with -Nv
echo "${product_name} ${product_version}"
exit 0
if [ -n "${OUTPUT}" ]; then
OUTPUT="${OUTPUT} "
fi
OUTPUT="${OUTPUT}\${product_id}"
;;
v)
echo ${product_version}
exit 0
if [ -n "${OUTPUT}" ]; then
OUTPUT="${OUTPUT} "
fi
OUTPUT="${OUTPUT}\${product_version}"
;;
*)
echo "Usage: man opnsense-version" >&2
@ -64,4 +68,8 @@ done
shift $((${OPTIND} - 1))
echo "${product_name} ${product_version} (${product_arch}/${product_flavour})"
if [ -z "${OUTPUT}" ]; then
OUTPUT="\${product_name} \${product_version} \(\${product_arch}/\${product_flavour}\)"
fi
eval echo ${OUTPUT}