-
Notifications
You must be signed in to change notification settings - Fork 15
/
sparse-ports-checkout.sh
executable file
·215 lines (202 loc) · 7.73 KB
/
sparse-ports-checkout.sh
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/bin/sh
#
# SPDX-License-Identifier: BSD-2-Clause
# License-Filename: LICENSES/BSD-2-Clause.tcberner.adridg
#
### USAGE
#
# Checkout a shallow copy of the FreeBSD ports tree with only the
# ports given as arguments filled in. Also checks out .arcconfig
# (for convenient reviews) and Mk/ (so that there's a chance of using
# the checked-out ports tree to build something) and other ports-
# infrastructure. For a single port, that's still about 7MB.
#
# Usage:
# sparse-ports-checkout <-n name|-a name> [-w] [-R path] <ports-spec> ...
#
# Usage:
# -n <name> is for checking out a new sparse tree
# -a <name> is for working on an existing tree
# -w writable checkout (svn+ssh) instead of read-only (https)
# -R <repopath> provide a repo-path to use
# -h show this help
# Ports-spec names ports to check out:
# -p <cat/port> names a port to check out
# -f <portlist> names a file to read a list of ports from
# -d <diffnum> checks out paths named in differential revision <diffnum>
# <cat/port> (no option) names a port to check out
#
# Example:
# # Ports in several categories, all named
# sparse-ports-checkout.sh -n ports-amarok \
# -p audio/amarok-kde4 \
# -p audio/libofa \
# -p devel/qtscriptgenerator
# # Ports from a review, and devel/cmake too
# sparse-ports-checkout.sh -n ports-kgraph \
# -w -d 12530 devel/cmake
#
### END USAGE
### LICENSES/BSD-2-Clause.tcberner.adridg
#
# Copyright 2017 Tobias C. Berner <[email protected]>
# Copyright 2017 Adriaan de Groot <[email protected]>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
### END LICENSES
# Writable vs non-writable SVN base
REP_w=svn+ssh://repo.freebsd.org/ports/head
REP=https://svn.FreeBSD.org/ports/head
unique_line ()
{
echo `echo "$*" | tr ' ' '\n' | sort -u | tr ' ' '\n'`
}
category_makefiles ()
{
echo `echo "$*" | awk 'BEGIN{RS=" "; OFS="/"}{print $1,"Makefile"}'`
}
main ()
{
local tree=""
local categories=""
local ports=""
while getopts "ha:n:p:f:wR:d:" opt ; do
case $opt in
h|\?)
sed -e '1,/USAGE/d' -e '/END.USAGE/,$d' < "$0"
return 0
;;
w)
REP="${REP_w}"
;;
R)
REP="${OPTARG}"
;;
d)
diffnum="${OPTARG}"
# Digits come before char 'D', extend 12296 to D12296
if test 'D' '>' "${diffnum}" ; then
diffnum="D${diffnum}"
fi
echo "Loading differential revision ${diffnum}"
tmplist=/tmp/$$.portlist
fetch -o - "https://reviews.freebsd.org/${diffnum}?download=true" | egrep '^[+-]{3} [^/]' | cut -d' ' -f2 | cut -d/ -f1,2 | sort -u > ${tmplist}
category=`awk -F '/' '($1 && $2){print $1}' < ${tmplist} | sort | uniq`
port=`awk -F '/' '($1 && $2){print $1"/"$2}' < ${tmplist} | sort | uniq`
categories="${category} ${categories}"
ports="${port} ${ports}"
echo " .. loaded" `wc -l < ${tmplist}` "ports from differential revision ${diffnum}"
rm -f $$.portlist
;;
n)
if [ "x${tree}y" == "xy" ] ; then
tree="${OPTARG}"
if [ -e "${tree}" ] ; then
echo "argument -n '${tree}' already exists in working directory"
return 1
fi
else
echo "multiple -n or -a arguments given: ${tree}, ${OPTARG}"
return 1
fi
;;
a)
if [ "x${tree}y" == "xy" ] ; then
tree="${OPTARG}"
if [ ! -d "${tree}" ] ; then
echo "argument to -a '${tree}' does not exist in working directory, you need -n"
return 1
fi
else
echo "multiple -n or -a arguments given: ${tree}, ${OPTARG}"
return 1
fi
;;
p)
category=`echo "${OPTARG}" | awk -F '/' '{print $1}'`
port=`echo "${OPTARG}" | awk -F '/' '{print $2}'`
if [ "x${category}y" != "xy" -a "x${port}y" != "xy" ] ; then
categories="${category} ${categories}"
ports="${category}/${port} ${ports}"
else
echo "could not understand -p argument '${OPTARG}'"
return 1
fi
;;
f)
if [ -f "${OPTARG}" ] ; then
category=`cat "${OPTARG}" | awk -F '/' '($1 && $2){print $1}' | sort | uniq`
port=`cat "${OPTARG}" | awk -F '/' '($1 && $2){print $1"/"$2}' | sort | uniq`
categories="${category} ${categories}"
ports="${port} ${ports}"
else
echo "could not read ports list from -f file '${OPTARG}'"
return 1
fi
;;
esac
done
if [ "x${tree}y" == "xy" ] ; then
echo "Need a tree argument -a, or -n"
return 1
fi
_used_opt=`expr "$OPTIND" - 1`
if [ "$_used_opt" -lt "$#" ] ; then
shift "$_used_opt"
for OPTARG in "$@" ; do
category=`echo "${OPTARG}" | awk -F '/' '{print $1}'`
port=`echo "${OPTARG}" | awk -F '/' '{print $2}'`
if [ "x${category}y" != "xy" -a "x${port}y" != "xy" ] ; then
categories="${category} ${categories}"
ports="${category}/${port} ${ports}"
else
echo "could not understand argument '${OPTARG}'"
return 1
fi
done
fi
if [ ! -d ${tree} ] ; then
svn co --depth empty "${REP}" "${tree}"
else
svn up "${tree}"
fi
categories=`unique_line "${categories}"`
category_mfs=`category_makefiles "${categories}"`
ports=`unique_line "${ports}"`
echo -e "Checking out cats: \033[33m${categories}\033[0m"
echo -e "Checking out catms: \033[33m${category_mfs}\033[0m"
echo -e "Chekcout out ports: \033[33m${ports}\033[0m"
if [ -d ${tree} ] ; then
cd ${tree}
echo -e "\033[32mChecking out CATEGORIES\033[0m"
svn update --set-depth=empty ${categories}
echo -e "\033[32mCheckout out CATEGORY Makefile\033[0m"
svn update --set-depth=infinity ${category_mfs}
echo -e "\033[32mChecking out PORTS\033[0m"
svn update --set-depth=infinity ${ports}
echo -e "\033[32mChecking out Mk\033[0m"
svn update --set-depth=infinity Mk Keywords Templates .arcconfig MOVED UPDATING
fi
}
main $*