-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviebuild
executable file
·82 lines (62 loc) · 1.71 KB
/
viebuild
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
# Opens the ebuild file for the given package, with the
# installed version or the available stable version
source /etc/portage/make.conf
EDITOR=${EDITOR:-vi}
PORTDIR=${PORTDIR:-/usr/portage}
function installed_version() {
eix --format '<installedversions:NAMEVERSION>' --exact --pure-packages "$1"
}
function best_version() {
eix --format '<bestversion:NAMEVERSION>' --exact --pure-packages "$1"
}
function overlay_location() {
eix --format '<installedversions:NAMEVERSION>' --exact "$1" | awk '/^\[/{print $NF}'
}
function pkg_matches() {
eix --exact --only-names "$1"
}
PKG=$(pkg_matches $1)
if [[ $? != 0 ]]; then
echo "No match found."
exit 1
fi
PKG_ARRAY=( $PKG )
COUNT=${#PKG_ARRAY[@]}
if [[ $COUNT > 1 ]]; then
echo "More than 1 match found:"
for (( i=0; i<COUNT; i++ )); do
echo " $i - ${PKG_ARRAY[$i]}"
done
read -p "Which do you want? " n
PKG=${PKG_ARRAY[$n]}
[[ ! $n || ! $PKG ]] && exit 1
fi
PKGVER=$(installed_version $PKG)
if [[ $? != 0 ]]; then # Not installed package
PKGVER=$(best_version $PKG)
fi
FILENAME=${PKG}/${PKGVER#*/}.ebuild
FILEPATH="${PORTDIR}/${FILENAME}"
if [ ! -f "$FILEPATH" ]; then
# Try to find it in a overlay
PORTDIR="$(overlay_location "$PKG")"
FILEPATH="${PORTDIR}/${FILENAME}"
if [ ! -f "$FILEPATH" ]; then
# It could be a installed version that is gone from the repo
# So instead show the last version available
PKGVER=$(best_version $PKG)
FILENAME=${PKG}/${PKGVER#*/}.ebuild
FILEPATH="${PORTDIR}/${FILENAME}"
if [ ! -f "$FILEPATH" ]; then
echo "File '$FILEPATH' does not exists. Something went wrong..."
exit 1
fi
fi
fi
# Is the output to the terminal?
if [ -t 1 ]; then
$EDITOR $FILEPATH
else # Or probably a pipe
echo "$FILEPATH"
fi