summaryrefslogtreecommitdiff
path: root/app-portage/showbuild/files/showbuild-0.9.1
blob: 2026dfc06c895233c3fff62d9033858d1153fea1 (plain)
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
#!/bin/bash

log="$(portageq envvar PORTAGE_TMPDIR)/portage/*/*/temp/build.log"
cmd="${SB:-tail -f}"
c=0

die() { echo -e "$*" >&2; exit 1; }

if [[ $1 = -h || $1 = --help ]]; then
  echo "Script to follow log of running portage builds"
  echo
  echo "Usage: ${0##*/}         # see running builds"
  echo "       ${0##*/} N       # follow build #N"
  echo "       ${0##*/} --fetch # follow emerge-fetch.log"
  echo "       ${0##*/} --help  # show this help"
  echo
  echo "Use environment variable SB to override the default cmd ($cmd)"
elif [[ $1 = -f || $1 = --fetch ]]; then
  log="$(portageq envvar EMERGE_LOG_DIR)"
  log="${log:=$(portageq envvar EPREFIX)/var/log}/emerge-fetch.log"
  [[ -f $log ]] || die "Could open '$log'"
  exec $cmd $log
elif [[ $(echo $log) = "$log" ]]; then
  echo "No running build found (try '${0##*/} --help')"
elif [[ ! $1 ]]; then
  echo "Running builds - use '${0##*/} NUMBER' to select"
  for i in $log; do
    [[ $i =~ ^${log%%\**}([^/]*)/([^/]*)${log##*\*}$ ]] || continue
    echo -e "$((++c))\t${BASH_REMATCH[2]}\t(${BASH_REMATCH[1]})"
  done
else
  [[ -z ${1//[0-9]} && $1 -gt 0 ]] || die "Argument should be a number greater 0"
  for i in $log; do
    [[ $i =~ ^${log%%\**}([^/]*)/([^/]*)${log##*\*}$ ]] || continue
    [[ $((++c)) -eq $((10#$1)) ]] || continue
    [[ -f ${i} ]] || die "Build number $1 was gone in the meanwhile"
    echo -ne "\033]0;Viewing: ${BASH_REMATCH[2]}\t(${BASH_REMATCH[1]})\007"
    exec $cmd $i
  done
  die "Build number $1 not found (there are only $((c--)) build(s) running)" 
fi