forked from void-linux/void-packages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy-xbps-src
executable file
·433 lines (377 loc) · 12.8 KB
/
my-xbps-src
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
#!/bin/bash
# vim: set ts=4 sw=4 et:
# -e exit on any error (work around with ||true)
# -u exit on unset variables, prevents here rm $masterdir/1/2/3 to be run as rm /1/2/3
set -eu
# Get cwd of this script
# https://stackoverflow.com/questions/59895/get-the-source-directory-of-a-bash-script-from-within-the-script-itself
XBPS_DISTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" 2>/dev/null
[[ $XBPS_DISTDIR ]] && cd $XBPS_DISTDIR
# Define paths
XBPS_SRCPKGDIR=srcpkgs
XBPS_UNOFFICIAL_SRCPKGDIR=my-srcpkgs
XBPS_DIFF_SRCPKGDIR=diff-srcpkgs
XBPS_MACHINE=$(xbps-uhelper -C /dev/null arch)
XBPS_MASTERDIR="$XBPS_DISTDIR/masterdir-$XBPS_MACHINE"
XBPS_HOSTDIR=hostdir
XBPS_SRCDISTDIR=$XBPS_HOSTDIR/sources
XBPS_DESTDIR=$XBPS_MASTERDIR/destdir
XBPS_BUILDDIR=$XBPS_MASTERDIR/builddir
XBPS_REPOSITORY=$XBPS_HOSTDIR/binpkgs
XBPS_UNOFFICIAL_REPOSITORY=my-binpkgs
l="------------------------------------------------------------------------------"
_chapter() {
echo $l
echo -e $@
echo $l
}
# Use with || continue
_chapter_question_build() {
[[ ${all:-} = true ]] && return 0
[[ ${all:-} = false ]] && return 1
echo $l
while true
do
echo -n "$@ [y,n,a,s,i,q,?]? "
read answer
unset skip all
case ${answer:0:1} in
# proceed
y ) echo $l ; return 0 ;;
n ) echo $l ; return 1 ;;
# proceed with special var
a ) all=true ; echo $l ; return 0 ;;
# proceed with special var
s ) skip=true ; echo $l ; return 0 ;;
# proceed with special var
q ) echo $l ; cd $cwd_before_main_script ; exit 0 ;;
* ) echo '
y - build now
n - do not build
s - skip version
q - quit
a - build all following updates
? - print help
'
;;
esac
done
}
# Use with || continue
_chapter_question_build_fail_continue() {
echo $l
while true
do
echo -n "$p: skip this version [y,n,q]? "
read answer
case ${answer:0:1} in
y )
# Skip
sed -i '/_my_field_skip_version/d' $template
sed -i "/^_my_field_repo=/a _my_field_skip_version=$upstream_rev" $template
echo $l
;;
n )
echo $l
;;
q )
echo $l
cd $cwd_before_main_script
exit 0
;;
* )
# Ask again
continue
;;
esac
break
done
}
_sync_my_pkgs() {
(
cd $XBPS_UNOFFICIAL_SRCPKGDIR
# Remove obsolete symlinks of custom packages
find ../$XBPS_SRCPKGDIR -maxdepth 1 -xtype l -exec rm -iv {} +
# TODO becomes replaced with rsync
# Remove obsolete symlinks among supplementary files
find . -xtype l -exec rm -iv {} +
# TODO becomes replaced with rsync
# Remove empty dirs among supplementary files
find . -type d -empty -exec rm -riv {} +
local custom_package
for custom_package in *
do
local relpath_custom=../$XBPS_UNOFFICIAL_SRCPKGDIR/$custom_package
local relpath_custom_link=../$XBPS_SRCPKGDIR/$custom_package
local relpath_original=../$XBPS_SRCPKGDIR/${custom_package%-git}
# Create symlinks of custom packages
ln -svn $relpath_custom $relpath_custom_link 2>/dev/null || true
if [[ -e $relpath_original && $relpath_original != $relpath_custom_link ]]
then
# TODO here it's when
# ~/void-packages/my-srcpkgs/vpm-git/patches
# becomes
# ~/void-packages/my-srcpkgs/vpm-git/patches-OBSOLETE
#
# Rsync supplementary files to custom packages
rsync -a --exclude template --delete $relpath_original/ $custom_package
fi
done
)
}
_update_void_packages() {
_chapter 'update void-packages'
git fetch --all --prune
# true if nothing to stash
[[ -z $(git status --untracked-files=no --porcelain) ]] || local do_stash=true
[[ ${do_stash:-} = true ]] && git stash push -m "$(date -R) automatic stash before rebase"
GIT_MERGE_AUTOEDIT=no git merge origin/master
if [[ ${do_stash:-} = true ]]
then
git stash pop --index
else
true
fi
}
_update_system() {
_update_void_packages
_sync_my_pkgs
_chapter 'update host pkgs'
sudo xbps-install -Suv
sudo xbps-remove -v -o
_chapter 'update build env'
./xbps-src bootstrap-update
}
# common/xbps-src/shutils/common.sh
# TODO not in use
_get_subpkgs() {
local f
for f in $(typeset -F)
do
case "$f" in
*_package ) echo "${f%_package}" ;;
esac
done
}
update_my_pkgs() {
if [[ $@ ]]
then
local force=true
local mypkgs=$@
else
cd $XBPS_UNOFFICIAL_SRCPKGDIR
# Omit symlinks
# -printf '%P\n' erases leftmost dir from output
local mypkgs=$(find . -maxdepth 1 -mindepth 1 ! -type l -printf '%P\n') || cd $XBPS_DISTDIR
cd $XBPS_DISTDIR
fi
rm -rf $XBPS_DESTDIR $XBPS_BUILDDIR
rm -rf $XBPS_REPOSITORY
mkdir -p $XBPS_REPOSITORY
# registering packages from my-binpkgs
cp -pv $XBPS_UNOFFICIAL_REPOSITORY/*.xbps $XBPS_REPOSITORY 2>/dev/null || true
xbps-rindex -a $XBPS_REPOSITORY/*.xbps 2>/dev/null || true
rm -f /tmp/my-xbps-log
mkdir -p $XBPS_MASTERDIR/repos/
_update_system
# Top priority for these pkgs, as they are dependencies
# TODO
# Improve by utilizing *depends fields from template themselves
# Now it's but a hardcode
case "$mypkgs" in
*wlroots-git* )
mypkgs=${mypkgs/wlroots-git/}
mypkgs="wlroots-git "$mypkgs
# Using ;;& in place of ;; causes the shell to test the next pattern
# list in the statement, if any, and execute any associated list on a
# successful match.
;;&
*tree-sitter-git* )
mypkgs=${mypkgs/tree-sitter-git/}
mypkgs="tree-sitter-git "$mypkgs
;;
esac
local p
for p in $mypkgs
do
template=$XBPS_SRCPKGDIR/$p/template
[[ -f $template ]] || { echo "=> ${0##*/}: expected $(pwd)/$template to be a file" ; return 1 ; }
unset _my_field_autoinstall _my_field_repo _my_field_repo_branch _my_field_repo_commit _my_field_skip_version
# workaround for some variables possible missing in templates
set +u
# FIXME 2>/dev/null || true - workaround for vopt_enable: command not found
source $template &>/dev/null || true
set -u
[[ -n ${_my_field_repo:-} ]] && local git=true
if [[ ${git:-} = true ]]
then
echo "=> ${0##*/}: checking updates $p"
if [ -z ${_my_field_repo_commit:-} ]
then
local upstream_rev_long=$( \
git ls-remote $_my_field_repo \
$(test ${_my_field_repo_branch:-} && echo -n $_my_field_repo_branch || echo -n HEAD) \
| awk '{print $1}' \
)
# digit expected in
# xbps-create: ERROR: invalid pkgver! got `foo-cabdcfb_1' expected `foo-1.0_1'
# increase temporarily :7 --> :14 to fix this
upstream_rev=${upstream_rev_long:0:7}
else
# and here
upstream_rev=${_my_field_repo_commit:0:7}
fi
else
upstream_rev=$version
fi
if [[ ${force:-} != true ]]
then
if [[ $upstream_rev = $version || $upstream_rev = ${_my_field_skip_version:-} ]]
then
continue
fi
fi
_chapter_question_build "build $p $upstream_rev" || continue
if [[ ${force:-} != true ]]
then
if [[ ${skip:-} = true ]]
then
sed -i '/_my_field_skip_version/d' $template
sed -i "/^_my_field_repo=/a _my_field_skip_version=$upstream_rev" $template
continue
fi
fi
cp $template /tmp/${p}_old
if [[ ${git:-} = true ]]
then
sed "0,/^version/{s/^version=.*/version=$upstream_rev/}" $template > /tmp/${p}_new
# FIXME this is not needed
else
cp $template /tmp/${p}_new
fi
# Put previous template on ctrl-c
trap "
mv /tmp/${p}_old $template 2>/dev/null || true
_chapter_question_build_fail_continue
continue
" SIGINT
mv /tmp/${p}_new $template
# TODO implement noautoinstall
#[[ $_my_field_autoinstall = false ]] && local noautoinstall[$p]=$p
# TODO store latest commit revision of each PKG in diff dir
# g log --pretty=short -n2 . << wip
# Define and check original template
local original_template=$XBPS_SRCPKGDIR/${p%-git}/template
if [[ -e $original_template && $original_template != $template ]]
then
diff --ignore-blank-lines --old-line-format=-%L --new-line-format=+%L --unchanged-line-format= \
<(grep -vE '^version|^revision|^distfiles|^checksum' $original_template) \
<(grep -vE '^version|^revision|^distfiles|^checksum' $template) \
> $XBPS_DIFF_SRCPKGDIR/$p.diff || true
fi
# Remove skip before build
sed -i '/_my_field_skip_version/d' $template
# Remove previously built versions of these packages
# Usually they come from my-binpkgs dir
local previous1=wlroots
local previous2=tree-sitter
case "$p" in
# Only e.g. wlroots* and tree-sitter* are removed, need to remove proper subpackages from template
$previous1* )
rm -f $XBPS_REPOSITORY/$previous1*
;;
$previous2* )
rm -f $XBPS_REPOSITORY/$previous2*
;;
esac
# Build
if ! ./xbps-src -C pkg $p
then
# Put previous template on build fail
mv /tmp/${p}_old $template 2>/dev/null || true
_chapter_question_build_fail_continue
continue
fi
local built=true
if [[ ${git:-} = true && -e $XBPS_BUILDDIR/$p-$upstream_rev ]]
then
(
cd $XBPS_BUILDDIR/$p-$upstream_rev
local log=$(git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --abbrev-commit $version..$upstream_rev 2>/dev/null || true)
if [[ $log ]]
then
echo -e "$p\n\n$log\n\n" >> /tmp/my-xbps-log
else
true
fi
)
fi
done
# Show log if not empty
[[ -e /tmp/my-xbps-log ]] && less /tmp/my-xbps-log
if [[ ${built:-} ]]
then
# TODO don't hardcode these rules, read them from a template
local to_install=$(find $XBPS_REPOSITORY \
'!' -name '*-dbg-*' \
'!' -name '*-devel-*' \
'!' -name 'libdrm-test-progs-*' \
'!' -name 'libdrm2-*' \
'!' -name 'meson-*' \
'!' -name 'ninja-*' \
'!' -name 'wayland-protocols-*' \
'!' -name 'wireplumber-elogind-*' \
-name '*.xbps' \
)
local command_to_install="sudo xdowngrade $to_install"
_chapter $command_to_install
eval $command_to_install
else
_chapter 'nothing to update'
fi
# Store non-required packages in the file
xbps-query -m | rev | cut -d - -f 2- | rev > ~/.xbps-manual-pkgs
# Store restricted packages (all: installed and not) in the file
grep -rl 'restricted=' srcpkgs/ | cut -d '/' -f2 > ~/.xbps-all-restricted-pkgs
}
cleanup() {
_update_void_packages
_chapter 'perform cleanup'
sudo xbps-remove -Oo
# line below might help if cleanup fails
#rm -rf $XBPS_MASTERDIR
./xbps-src clean
./xbps-src clean-repocache || { ./xbps-src binary-bootstrap && ./xbps-src clean-repocache ; }
./xbps-src remove-autodeps
./xbps-src zap
rm -rf $XBPS_SRCDISTDIR
./xbps-src binary-bootstrap
_chapter 'cleanup success'
}
#
# Main switch
#
cwd_before_main_script=$(pwd)
case ${1:-} in
up )
if [[ ${2:-} ]]
then
shift
update_my_pkgs $@
else
update_my_pkgs
fi
;;
cleanup )
cleanup
;;
* )
echo "${0##*/}: invalid parameter ${1:-}"
cd $cwd_before_main_script
exit 1
;;
esac
# TODO
# avoid writing git versions to templates, store them elsewhere
# use 'global' vars, and make 'local' by default
# first check for all updates, show them, let me choose what to build, then do system updates and build