projects/aports·blob v1.15 · refs

133 lines · 3.0 KiB

1#!/bin/sh
2
3program=${0##*/}
4
5aportsdir=${APORTSDIR:-$HOME/aports}
6repodir=${REPODIR:-$HOME/packages}
7
8
9usage() {
10 echo "usage: $program [-a APORTSDIR] [-d REPODIR] [-hp] [-l LOGPREFIX ]"
11 echo " [-r DEPREPO] REPOSITORY..."
12
13 echo "options:"
14 echo " -a Set the aports base dir to APORTSDIR instead of $aportsdir"
15 echo " -d Set destination repository base dir to REPODIR instead of $repodir"
16 echo " -h Show this help and exit"
17 echo " -l Send build to logfile, prefixed by LOGPREFIX"
18 echo " -p Purge obsolete packages from REPODIR after build"
19 echo " -r Dependencies are found in DEPREPO"
20 exit 1
21}
22
23
24listpackages() {
25 cd "$aportsdir/$1"
26 for i in */APKBUILD; do
27 APKBUILD=$i abuild listpkg
28 done
29}
30
31build() {
32 local repo="$1" i indexupdate needbuild
33
34 cd "$aportsdir/$repo" || return 1
35 mkdir -p "$repodir/$repo"
36 if ! [ -f "$repodir/$repo"/APK_INDEX.gz ]; then
37 indexupdate="APK_INDEX.gz"
38 fi
39
40 # first we try copy everything possible and find out which we need
41 # to rebuild. By doing this we might save us for rebuilding
42 # needed when running 'abuild -R'
43 for i in */APKBUILD; do
44 export REPODEST="$repodir"
45 cd "$aportsdir/$repo"/${i%/*} || return 1
46 if abuild -k -q up2date 2>/dev/null; then
47 continue
48 fi
49
50 # try link or copy the files if they are in the ports dir
51 pkgs=$(abuild listpkg)
52 if cp -p -l $pkgs "$repodir/$repo"/ 2>/dev/null \
53 || cp -p $pkgs "$repodir/$repo"/ 2>/dev/null; then
54 echo ">>> Copying " $pkgs
55 else
56 needbuild="$needbuild $i"
57 fi
58 indexupdate="$indexupdate $i"
59 done
60
61 # build the postponed packages if any
62 if [ -n "$needbuild" ]; then
63 for i in $needbuild; do
64 cd "$aportsdir/$repo"/${i%/*} || return 1
65 abuild -k -R || return 1
66 done
67 fi
68
69 # kill old packages in repo
70 if [ -n "$dopurge" ]; then
71 local tmp=$(mktemp /tmp/$program-XXXXXX)
72 local purgefiles
73 cd "$repodir/$1" || return 1
74 trap 'rm -f "$tmp"; exit 1' INT
75 ( listpackages "$1") >$tmp
76 purge=$(ls *.apk 2>/dev/null | grep -v -w -f $tmp)
77 if [ -n "$purge" ]; then
78 rm -f $purge
79 indexupdate="$indexupdate $purge"
80 fi
81 rm -f "$tmp"
82 fi
83
84 # check if we have any .apk newer than our index
85 cd "$repodir/$repo"
86 if [ -z "$indexupdate" ]; then
87 for i in *.apk; do
88 if [ $i -nt APK_INDEX.gz ]; then
89 indexupdate=1
90 break;
91 fi
92 done
93 fi
94
95 # generate the repository index if needed
96 if [ -z "$indexupdate" ]; then
97 echo ">>> Index for $repo is up-to-date"
98 else
99 echo ">>> Generating Index for $repo..."
100 if which apk >/dev/null; then
101 local deps
102 for i in $deprepo; do
103 deps="--repo $repodir/$i"
104 done
105 apk $deps index *.apk | gzip -9 > APK_INDEX.gz
106 fi
107 fi
108}
109
110while getopts "a:d:hl:pr:" opt; do
111 case "$opt" in
112 a) aportsdir=$OPTARG;;
113 d) repodir=$OPTARG;;
114 h) usage >&2;;
115 l) logprefix=$OPTARG;;
116 p) dopurge=1;;
117 r) deprepo="$deprepo $OPTARG";;
118 esac
119done
120shift $(($OPTIND - 1))
121
122[ $# -eq 0 ] && usage >&2
123
124while [ $# -gt 0 ]; do
125 if [ -n "$logprefix" ]; then
126 build $1 >$logprefix.$1.log 2>&1 || exit 1
127 else
128 build $1 || exit 1
129 fi
130 deprepo="$deprepo $1"
131 shift
132done
133