Add anoncvs gentoo-x86 example in documentation of repos.conf.
[portage.git] / bin / bashrc-functions.sh
1 #!/bin/bash
2 # Copyright 1999-2013 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4
5 portageq() {
6         PYTHONPATH=${PORTAGE_PYTHONPATH:-${PORTAGE_PYM_PATH}}\
7         "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}/portageq" "$@"
8 }
9
10 register_die_hook() {
11         local x
12         for x in $* ; do
13                 has $x $EBUILD_DEATH_HOOKS || \
14                         export EBUILD_DEATH_HOOKS="$EBUILD_DEATH_HOOKS $x"
15         done
16 }
17
18 register_success_hook() {
19         local x
20         for x in $* ; do
21                 has $x $EBUILD_SUCCESS_HOOKS || \
22                         export EBUILD_SUCCESS_HOOKS="$EBUILD_SUCCESS_HOOKS $x"
23         done
24 }
25
26 __strip_duplicate_slashes() {
27         if [[ -n $1 ]] ; then
28                 local removed=$1
29                 while [[ ${removed} == *//* ]] ; do
30                         removed=${removed//\/\///}
31                 done
32                 echo "${removed}"
33         fi
34 }
35
36 KV_major() {
37         [[ -z $1 ]] && return 1
38
39         local KV=$@
40         echo "${KV%%.*}"
41 }
42
43 KV_minor() {
44         [[ -z $1 ]] && return 1
45
46         local KV=$@
47         KV=${KV#*.}
48         echo "${KV%%.*}"
49 }
50
51 KV_micro() {
52         [[ -z $1 ]] && return 1
53
54         local KV=$@
55         KV=${KV#*.*.}
56         echo "${KV%%[^[:digit:]]*}"
57 }
58
59 KV_to_int() {
60         [[ -z $1 ]] && return 1
61
62         local KV_MAJOR=$(KV_major "$1")
63         local KV_MINOR=$(KV_minor "$1")
64         local KV_MICRO=$(KV_micro "$1")
65         local KV_int=$(( KV_MAJOR * 65536 + KV_MINOR * 256 + KV_MICRO ))
66
67         # We make version 2.2.0 the minimum version we will handle as
68         # a sanity check ... if its less, we fail ...
69         if [[ ${KV_int} -ge 131584 ]] ; then
70                 echo "${KV_int}"
71                 return 0
72         fi
73
74         return 1
75 }
76
77 _RC_GET_KV_CACHE=""
78 get_KV() {
79         [[ -z ${_RC_GET_KV_CACHE} ]] \
80                 && _RC_GET_KV_CACHE=$(uname -r)
81
82         echo $(KV_to_int "${_RC_GET_KV_CACHE}")
83
84         return $?
85 }