rc: hello opnsense-version!

This commit is contained in:
Franco Fichtner 2018-09-16 23:07:21 +02:00
parent e194253186
commit 0cf4fe5e38
8 changed files with 77 additions and 11 deletions

View File

@ -34,8 +34,6 @@ rm -f /etc/rc.shutdown.bak
echo "Writing package metadata"
mkdir -p /usr/local/opnsense/version
echo "%%CORE_COMMIT%%" > /usr/local/opnsense/version/opnsense
echo "%%CORE_NAME%%" > /usr/local/opnsense/version/opnsense.name
echo "%%CORE_ABI%%" > /usr/local/opnsense/version/opnsense.abi
/usr/local/etc/rc.d/configd start

1
plist
View File

@ -1526,6 +1526,7 @@
/usr/local/sbin/opnsense-importer
/usr/local/sbin/opnsense-installer
/usr/local/sbin/opnsense-shell
/usr/local/sbin/opnsense-version
/usr/local/sbin/ping_hosts.sh
/usr/local/sbin/pluginctl
/usr/local/sbin/ppp-linkdown

View File

@ -7,7 +7,7 @@ RETRIES=5
COMMAND=${1}
CORE_ABI=$(cat /usr/local/opnsense/version/opnsense.abi)
CORE_ABI=$(opnsense-version -a)
SYS_ABI=$(opnsense-verify -a)
URL="https://pkg.opnsense.org/${SYS_ABI}/${CORE_ABI}/sets/bogons.txz"

View File

@ -713,8 +713,8 @@ class FirmwareController extends ApiControllerBase
$response = array();
/* allows us to select UI features based on product state */
$response['product_version'] = trim(file_get_contents('/usr/local/opnsense/version/opnsense'));
$response['product_name'] = trim(file_get_contents('/usr/local/opnsense/version/opnsense.name'));
$response['product_version'] = trim(shell_exec('opnsense-version -v'));
$response['product_name'] = trim(shell_exec('opnsense-version -n'));
$devel = explode('-', $response['product_name']);
$devel = count($devel) == 2 ? $devel[1] == 'devel' : false;
@ -790,7 +790,7 @@ class FirmwareController extends ApiControllerBase
if ($changelogs == null) {
$changelogs = array();
} else {
$version = trim(file_get_contents('/usr/local/opnsense/version/opnsense'));
$version = trim(shell_exec('opnsense-version -v'));
$devel = preg_match('/^\d+\.\d+\.[a-z]/i', $version) ? true : false;
foreach ($changelogs as $index => &$changelog) {

View File

@ -56,9 +56,9 @@ abstract class Base
@unlink("{$file}.dec");
if (file_exists("{$file}.enc")) {
$version = strtok(file_get_contents('/usr/local/opnsense/version/opnsense'), '-');
$version = trim(shell_exec('opnsense-version -V'));
$result = "---- BEGIN {$tag} ----\n";
$result .= "Version: OPNsense {$version}\n"; /* XXX hardcoded product name */
$result .= "Version: {$version}\n";
$result .= "Cipher: AES-256-CBC\n";
$result .= "Hash: MD5\n\n";
$result .= chunk_split(base64_encode(file_get_contents("{$file}.enc")), 76, "\n");

View File

@ -39,7 +39,7 @@ changelog_remove()
changelog_fetch()
{
CORE_ABI=$(cat /usr/local/opnsense/version/opnsense.abi)
CORE_ABI=$(opnsense-version -a)
SYS_ABI=$(opnsense-verify -a)
URL="https://pkg.opnsense.org/${SYS_ABI}/${CORE_ABI}/sets/changelog.txz"

View File

@ -334,8 +334,8 @@ if [ "$pkg_running" == "" ]; then
upgrade_major_message=$(cat /usr/local/opnsense/firmware-message 2> /dev/null | sed 's/"/\\&/g' | tr '\n' ' ')
upgrade_major_version=$(cat /usr/local/opnsense/firmware-upgrade 2> /dev/null)
product_version=$(cat /usr/local/opnsense/version/opnsense)
product_name=$(cat /usr/local/opnsense/version/opnsense.name)
product_version=$(opnsense-version -v)
product_name=$(opnsense-version -n)
os_version=$(uname -sr)
last_check=$(date)
else

67
src/sbin/opnsense-version Executable file
View File

@ -0,0 +1,67 @@
#!/bin/sh
# Copyright (c) 2018 Franco Fichtner <franco@opnsense.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
# OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# 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/firmware-product"
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
;;
N)
echo ${product_name}
exit 0
;;
n)
echo ${product_id}
exit 0
;;
V)
# XXX replace with -Nv
echo "${product_name} ${product_version}"
exit 0
;;
v)
echo ${product_version}
exit 0
;;
*)
echo "Usage: man opnsense-version" >&2
exit 1
;;
esac
done
shift $((${OPTIND} - 1))
echo "${product_name} ${product_version} (${product_arch}/${product_flavour})"