summaryrefslogtreecommitdiff
blob: a8010883f505ca278b83961a7d4c5935b1a41071 (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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/sh

# description:
#
# ROOT is the root all packages are installed to
#
# if CHECK=yes then skip an already installed package
# if CHECK=package then skip a package if its tbz2 already exists
#
# ERRQUIT=no causes the script to keep trying to build packages even
# when one has failed.
#

C_NORMAL=$'\033[0m'
C_HILITE=$'\e[36;01m'
C_END=$'\e[A\e[68G'
C_OK=$'\e[32m'
C_NO=$'\e[31m'
#eval `/usr/lib/portage/bin/import-settings PORTDIR PKGDIR`
PORTDIR=/usr/portage
LOGDIR=${ROOT}/tmp/portage-log
PKGDIR=/usr/portage/packages
[ -z "$CHECK" ] && CHECK="yes"
[ -z "$STEPS" ] && STEPS="check fetch clean compile install qmerge clean"
[ -z "$ERRQUIT" ] && ERRQUIT="no"

do_step() {

    local tmpd
    tmpd=`pwd`
    echo "$C_END $C_HILITE          "
    echo "$C_END $C_HILITE [$1]$C_NORMAL  "
    cd `dirname $myd`
    ebuild $myf $1 &> $myl/$1
    mye=$?
    cd $tmpd

    if [ -f $LOGDIR/$1 ]
    then
      cp $LOGDIR/$1 /tmp/failed
      grep -v "$i" /tmp/failed > $LOGDIR/$1
    fi

    if [ $mye -ne 0 ]
    then	
      echo "$C_END $C_HILITE          "
      echo "$C_END $C_NO [$1]$C_NORMAL  "
      echo $i >> $LOGDIR/$1
      [ "${ERRQUIT}" = "yes" ] && exit 1
    fi
    return $mye
}

if [ -z "${ROOT}" ]
then
	echo "ROOT not set !"
	exit 1
fi

mylist=${PORTDIR}/current-packages

if [ -f "${1}" ]
then
  mylist=${1}
fi

mypackages="`grep -v "\#.*" $mylist`"

install -m1777 -d $ROOT/tmp/portage-log

echo "$C_HILITE>>>$C_NORMAL Building from ${mylist}..."
for i in $mypackages
do
  source /etc/profile
  # full path
  myd=${i/.\//$PORTDIR\/}

  # file name
  myf="`basename $myd`"

  # category
  myc="`echo $i | sed -e "s:^\(.*\).*/.*/.*$:\1:"`"

  # package name
  myp=${myf%*.ebuild}

  # debugging
#  echo $myp

  if [ -f "$myd" ]
  then

    # Check if installed
    if [ "$CHECK" = "yes" ]
    then
        if [ -d ${ROOT}/var/db/pkg/$myc/$myp ]
        then
            continue
        fi
    else
        if [ "$CHECK" = "package" ]
        then
            if [ -f ${PKGDIR}/All/$myp.tbz2 ]
            then
                continue
            fi
        fi
    fi

    echo "$C_NORMAL$myp ($myc)"

    myl="$LOGDIR/$myc/$myp/"
    mkdir -p $myl

    for j in ${STEPS}
    do
      mye=0
      do_step $j
      if [ $mye -ne 0 ]
      then
	break
      fi
    done
    if [ $mye -eq 0 ]
    then
      echo "$C_END $C_OK [OK]$C_NORMAL     "
      echo $i >> ${LOGDIR}/ok
    fi

  else
    echo "!!! $myd does not exists !"
  fi
  env-update &>/dev/null

done