-
Notifications
You must be signed in to change notification settings - Fork 180
Expand file tree
/
Copy pathget-kernel-source.sh
More file actions
executable file
·78 lines (71 loc) · 2.31 KB
/
get-kernel-source.sh
File metadata and controls
executable file
·78 lines (71 loc) · 2.31 KB
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
#!/bin/bash
#
# Copyright (c) 2022 Zededa, Inc.
# SPDX-License-Identifier: Apache-2.0
#
# Collect EVE's kernel sources from the upstream.
#
# Needs to run in a workspace where it has access to pkg/kernel/Dockerfile.
# Example usage
# get-kernel-source.sh [-v] [-u urlfile] [-s outdir] [Dockerfile]
# With -u <urlfile> it dumps the source URLs into that file
# With -s <outdir> it dumps all the corresponding source in that directory
# Then outdir can be tarred together
verbose=
urlfile=
prefix=
outdir=/tmp/$$
dockerfile="pkg/kernel/Dockerfile"
while getopts vu:s:p: o
do case "$o" in
v) verbose=1;;
s) outdir=$OPTARG;;
u) urlfile=$OPTARG;;
p) prefix=$OPTARG;;
[?]) >&2 echo "Usage: $0 [-v] [-s <outdir>] [-u <urlfile>] [-p <prefix>] [<Dockerfile>]"
exit 1;;
esac
done
shift $((OPTIND-1))
if [ $# -gt 1 ]; then
>&2 echo "Can specify at most one Dockerfile"
>&2 echo "Usage: $0 [-v] [-s <outdir>] [-u <urlfile>] [-p <prefix>] [<Dockerfile>]"
exit 1
fi
if [ $# = 1 ]; then
dockerfile=$1
shift
fi
checkdir=$outdir
[ -n "$prefix" ] && checkdir="$outdir/$prefix"
if [ -d "$checkdir" ]; then
>&2 echo "$checkdir already exists"
exit 1
fi
mkdir -p "$checkdir"
tmpurlfile=/tmp/$$.url
# probably should pin to a version, but good enough for now
# in any case, this script is not actually used. We are just putting this here so we can
# remove dockerfile-add-scanner from the repo; this one should be removed shortly.
TOOLS_IMG=lfedge/eve-build-tools:main
if ! docker run --rm -v "${dockerfile}:/src/dockerfile:ro" ${TOOLS_IMG} dockerfile-add-scanner scan /src/dockerfile >"$tmpurlfile"; then
>&2 echo "dockerfile-add-scanner failed"
exit 2
fi
if [ -n "$urlfile" ]; then
(cd "$outdir" || exit; cp -p "$tmpurlfile" "$urlfile")
fi
[ -n "$verbose" ] && echo "downloading using $tmpurlfile" >&2
# shellcheck disable=SC2002
cat "$tmpurlfile" | while read -r url; do
basedest=$(echo "$url" | cut -d'/' -f3- | tr "/" _)
[ -n "$prefix" ] && basedest="$prefix/$basedest"
dest="$outdir/$basedest"
[ -n "$verbose" ] && echo "downloading: curl -sSLo $dest $url" >&2
if ! curl -sSLo "$dest" "$url"; then
>&2 echo "curl $dest $url failed"
exit 2
fi
echo "kernel,${url},,${basedest}"
done
rm -f "$tmpurlfile"