-
Notifications
You must be signed in to change notification settings - Fork 0
/
pkg
executable file
·247 lines (235 loc) · 6.18 KB
/
pkg
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#!/bin/sh
UPDATE_CURRENT=false
pkg_usage() {
echo "Usage: `pkg *pkgname*` gets the source for *pkgname* and makes it the default build target";
echo "Usage: `pkg pull *packages...*` updates the sources for the current package";
echo " ` cleanup *packages...*` cleans intermediate files for *packages*";
echo " ` cleanout *packages...*` cleans intermediate and output files for *packages*";
echo " If no packages are provided for these commands, they are applied to all packages";
echo "Usage: pkg (*command* *packages...*)+";
echo " For each *command*, applies it to the specified *packages*, with 'all' indicating all packages";
echo " *command* can be:";
echo " + make: creates an OS package (e.g. rpm, deb, apk) from the current source"
echo " + require installs the latest package version, building it if needed"
echo " + install the latest *pkgname*, it if has been built"
echo "Usage: pkg *param*";
echo " outputs the build config parameter *param*";
echo "Usage: pkg *param*=*value*";
echo " sets the build config parameter *param* to *value*";
}
if [ $# -eq 0 ]; then
pkg_usage;
exit;
else case $1 in
help|usage)
pkg_usage;
exit;
;;
esac;
fi;
# Update the packaging directory at least once
if [ ! -f .updated ]; then
git pull && touch .updated;
exec $0 $*;
fi;
. ./packaging.sh
if [ -n "${SKIP}" ]; then
for pkg in ${SKIP}; do
if [ -d sources/${pkg} ]; then
touch sources/${pkg}/skip;
else
echo "Bad SKIP arg ${pkg}";
fi;
done;
fi;
pkg_op( ) {
local pkgop="$1";
local pkglist="$2";
if [ -n "${pkgop}" ] && [ -n "${pkglist}" ]; then
for pkg in ${pkglist}; do
logmsg "Applying ${pkgop} to ${pkg}";
./do_pkgop ${pkg} ${pkgop}
done;
fi;
}
get_all_pkgs( ) {
local all='libu8 kno';
local p='';
local nm='';
for p in sources/*; do
if [ -d "$p" ] && [ ! -f "$p/skip" ] && [ -d "$p/${PKGINFO}" ]; then
nm=$(basename ${p});
if ! ( [ "$nm" = "libu8" ] || [ "$nm" = "kno" ] ); then
all="${all} ${nm}"; fi;
fi;
done;
echo ${all};
}
handle_bundle( ) {
local op='';
local pkgs='';
local elt='';
local varname='';
local valstring='';
dbgmsg "Handle bundle $@";
for elt in $*; do
dbgmsg "Processing '${elt}' op=${op} pkgs=${pkgs}";
case ${elt} in
require|make|prep|package|create|build|install|push|latest|pushup)
pkg_op ${op} "${pkgs}";
op=${elt};
pkgs='';
;;
make+|make++|remake|remake+|remake++|rebuild|remake|pushup)
pkg_op ${op} "${pkgs}";
op=${elt};
pkgs='';
;;
all|forall)
if [ -n "${op}" ]; then
pkg_op ${op} "$(get_all_pkgs)"
pkgs=''
op=''
else pkgs=$(get_all_pkgs);
fi;
;;
*=*)
pkg_op ${op} "${pkgs}";
pkgs="";
varname=${elt%=*};
valstring=${elt#*=};
varname=$(echo ${varname} | tr [a-z] [A-Z]);
echo "Setting state ${varname} to ${valstring}";
echo ${valstring} > defaults/${varname};
;;
*)
if [ -d sources/${elt} ]; then
if [ -z "${pkgs}" ]; then
pkgs="${elt}";
else pkgs="${pkgs} ${elt}"; fi;
else
pkg_op ${op} "${pkgs}";
pkgs="";
upper=$(echo $1 | tr [a-z] [A-Z]);
if [ -f state/${upper} ]; then
cat state/${upper};
exit;
else
echo "Unknown state parameter ${upper}";
fi;
fi;
;;
esac;
done;
infomsg "pkg_op ${op} ${pkgs}";
pkg_op ${op} "${pkgs}";
}
case $1 in
start|source)
if [ -n "$2" ] && [ -f sources/$2/srcloc ]; then
./setsource $2;
rm -rf work/$2;
exit;
else
echo "Usage: pkg start *pkgname*";
exit;
fi;
;;
setup)
if [ $# -eq 1 ] || [ "$2" = "all" ]; then
for pkg in $(get_all_pkgs); do
./setsource ${pkg};
done;
else shift;
for pkg in $@; do
if [ -f "sources/${pkg}/srcloc" ]; then
./setsource ${pkg};
else echo "Not a known package: ${pkg}";
fi;
done;
fi;
exit;
;;
pull)
if [ $# -eq 1 ] || [ "$2" = "all" ]; then
for pkg in $(get_all_pkgs); do
./setsource ${pkg};
done;
else shift;
for pkg in $@; do
if [ -f "sources/${pkg}/srcloc" ]; then
./setsource ${pkg};
else echo "Not a known package: ${pkg}";
fi;
done;
fi;
exit;
;;
cleanup)
if [ $# -eq 1 ] || [ "$2" = "all" ]; then
for pkg in $(get_all_pkgs); do
rm -rvf work/${pkg} work/${pkg}.*;
done;
else shift;
for pkg in $@; do
if [ -f "sources/${pkg}/srcloc" ]; then
rm -rvf work/${pkg} work/${pkg}.*;
else echo "Not a known package: ${pkg}";
fi;
done;
fi;
exit;
;;
cleanout)
if [ $# -eq 1 ] || [ "$2" = "all" ]; then
for pkg in $(get_all_pkgs); do
echo "Removing work/${pkg}, etc";
rm -rf work/${pkg} work/${pkg}.*;
if [ -d "${PACKAGING_ROOT}/output/${pkg}" ]; then
echo "Removing contents of output/${pkg}";
( cd ${PACKAGING_ROOT}; ls -l output/${pkg}; rm -rf output/${pkg}/* );
fi;
done;
else shift;
for pkg in $@; do
if [ -f "sources/${pkg}/srcloc" ]; then
echo "Removing work/${pkg}, etc";
rm -rf work/${pkg} work/${pkg}.*;
echo "Removing contents of output/${pkg}";
if [ -d "${PACKAGING_ROOT}/output/${pkg}" ]; then
( cd ${PACKAGING_ROOT}; ls -l output/${pkg}; rm -rf output/${pkg}/* );
fi;
else echo "Not a known package: ${pkg}";
fi;
done;
fi;
exit;
;;
default)
arg=$2
if [ "${arg%=*}" = "${arg}" ]; then
arg=$(echo ${arg} | tr [a-z] [A-Z]);
if [ -f defaults/${arg} ]; then
cat defaults/${arg};
fi;
else
varname=${2%=*};
valstring=${2#*=};
varname=$(echo ${varname} | tr [a-z] [A-Z]);
echo "Setting default for ${varname} to ${valstring}";
echo ${valstring} > state/${varname};
exit;
fi;
;;
esac;
if [ $# -eq 1 ]; then
if [ -d sources/$1 ]; then
./setsource $1;
elif [ -z "${PKGNAME}" ]; then
echo "No current package";
exit;
else
./do_pkgop ${PKGNAME} $1
fi;
fi;
handle_bundle $@