aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Stephen P. Bennett <spb@exherbo.org> 2006-05-19 01:52:03 +0000
committerAvatar Stephen P. Bennett <spb@exherbo.org> 2006-05-19 01:52:03 +0000
commitbde8feef86a3c410c869cbed7a1154eac2b72db5 (patch)
tree66623c04ff90d79abd413c49ff26bb5eb0aa8b9d
parent7754324e6e65b14635eb5459b24e8593a25abda3 (diff)
downloadpaludis-bde8feef86a3c410c869cbed7a1154eac2b72db5.tar.gz
paludis-bde8feef86a3c410c869cbed7a1154eac2b72db5.tar.xz
Add KV_* functions.
-rw-r--r--ebuild/Makefile.am3
-rwxr-xr-xebuild/ebuild.bash1
-rw-r--r--ebuild/kernel_functions.bash60
-rw-r--r--ebuild/kernel_functions_TEST.bash42
4 files changed, 105 insertions, 1 deletions
diff --git a/ebuild/Makefile.am b/ebuild/Makefile.am
index 25e7ce5..9c0fec4 100644
--- a/ebuild/Makefile.am
+++ b/ebuild/Makefile.am
@@ -15,6 +15,7 @@ libexecprog_SCRIPTS = \
builtin_unmerge.bash \
ebuild.bash \
echo_functions.bash \
+ kernel_functions.bash \
eclass_functions.bash \
install_functions.bash \
list_functions.bash \
@@ -40,7 +41,7 @@ TESTS_ENVIRONMENT = env \
TEST_SCRIPT_DIR="$(srcdir)/" \
bash $(top_srcdir)/ebuild/run_test.bash
-TESTS = echo_functions_TEST.bash list_functions_TEST.bash
+TESTS = echo_functions_TEST.bash list_functions_TEST.bash kernel_functions_TEST.bash
EXTRA_DIST = $(libexecprog_SCRIPTS) run_test.bash $(TESTS)
check_SCRIPTS = run_test.bash $(TESTS)
diff --git a/ebuild/ebuild.bash b/ebuild/ebuild.bash
index 1e7edbb..73d5eb8 100755
--- a/ebuild/ebuild.bash
+++ b/ebuild/ebuild.bash
@@ -65,6 +65,7 @@ ebuild_load_module()
}
ebuild_load_module echo_functions
+ebuild_load_module kernel_functions
ebuild_load_module sandbox
ebuild_load_module portage_stubs
ebuild_load_module list_functions
diff --git a/ebuild/kernel_functions.bash b/ebuild/kernel_functions.bash
new file mode 100644
index 0000000..554df65
--- /dev/null
+++ b/ebuild/kernel_functions.bash
@@ -0,0 +1,60 @@
+#!/bin/bash
+# vim: set sw=4 sts=4 et :
+
+# Copyright (c) 2006 Stephen Bennett <spb@gentoo.org>
+#
+# Based in part upon functions.sh from Baselayout, which is Copyright 1995-2005
+# Gentoo Foundation and distributed under the terms of the GNU General
+# Public License v2.
+#
+# This file is part of the Paludis package manager. Paludis is free software;
+# you can redistribute it and/or modify it under the terms of the GNU General
+# Public License as published by the Free Software Foundation; either version
+# 2 of the License, or (at your option) any later version.
+#
+# Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+# Place, Suite 330, Boston, MA 02111-1307 USA
+
+KV_major()
+{
+ [[ -z $1 ]] && return 1
+ local KV=$@
+ echo ${KV%%.*}
+}
+
+KV_minor()
+{
+ [[ -z $1 ]] && return 1
+ local KV=$@
+ KV=${KV#*.}
+ echo ${KV%%.*}
+}
+
+KV_micro()
+{
+ [[ -z $1 ]] && return 1
+ local KV=$@
+ KV=${KV#*.*.}
+ echo ${KV%%[^[:digit:]]*}
+}
+
+KV_to_int()
+{
+ [[ -z $1 ]] && return 1
+
+ local major=$(KV_major "$1")
+ local minor=$(KV_minor "$1")
+ local micro=$(KV_micro "$1")
+ echo $(( major * 65536 + minor * 256 + micro ))
+}
+
+get_KV()
+{
+ echo $(KV_to_int "$(uname -r)")
+}
diff --git a/ebuild/kernel_functions_TEST.bash b/ebuild/kernel_functions_TEST.bash
new file mode 100644
index 0000000..de3a74f
--- /dev/null
+++ b/ebuild/kernel_functions_TEST.bash
@@ -0,0 +1,42 @@
+#!/bin/bash
+# vim: set sw=4 sts=4 et :
+
+# Copyright (c) 2006 Stephen Bennett <spb@gentoo.org>
+#
+# This file is part of the Paludis package manager. Paludis is free software;
+# you can redistribute it and/or modify it under the terms of the GNU General
+# Public License as published by the Free Software Foundation; either version
+# 2 of the License, or (at your option) any later version.
+#
+# Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+# Place, Suite 330, Boston, MA 02111-1307 USA
+
+KV_major_TEST()
+{
+ test_equality "$(KV_major 2.4.6)" "2"
+}
+
+KV_minor_TEST()
+{
+ test_equality "$(KV_minor 2.6.16)" "6"
+ test_equality "$(KV_minor 2.6.7-gentoo-r1)" "6"
+ test_equality "$(KV_minor 2.4.18-rc1)" "4"
+}
+
+KV_micro_TEST()
+{
+ test_equality "$(KV_micro 2.6.0)" "0"
+ test_equality "$(KV_micro 2.5.63-mm8)" "63"
+ test_equality "$(KV_micro 2.2.0-foo1)" "0"
+}
+
+KV_to_int_TEST()
+{
+ test_equality "$(KV_to_int 2.6.16)" "132624"
+}