blob: ae88656f38abd539c9f54be3d72ea2d231c0f9b6 (
plain)
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
|
#!/bin/bash
set -o errexit -o nounset
print_usage() {
cat >&2 <<-EOF
Usage: ${0##*/} [-h] BRANCH [BOARD]
EOF
}
print_help() {
print_usage
cat >&2 <<-EOF
Use this script to checkout turris-build repository relative to branch on
repo.turris.cz. It not only checkouts exact commit in turris-build
repository, but it also modifies feeds.conf file so exactly same feeds are
used as they were used to build files on server.
BRANCH argument is required and is target publish branch (Do not mix this
with git branch of same name).
BOARD is optional argument used to specify different board. In default
'omnia' is used. This is available because sometimes versions for boards
are not in sync and can differ. It should be in most cases safe to use
default but if you encounter problems you can try setting appropriate
board.
Options:
-h, --help Print this help text
EOF
}
target=""
board=""
declare -A long2short=( ["help"]="h" )
dashdash="n"
while [ "$OPTIND" -le "$#" ]; do
argument="${!OPTIND}"
if [ "$dashdash" = "n" ] && getopts ":h" opt; then
if [ "${argument:0:2}" = "--" ]; then
longopt="${argument:2}"
if [ -v long2short["$longopt"] ]; then
opt="${long2short[$longopt]}"
else
OPTARG="$argument"
fi
fi
case "$opt" in
h)
print_help
exit 0
;;
\?)
echo "Illegal option: $OPTARG"
exit 1
;;
esac
continue
elif [ "$argument" == "--" -a "$dashdash" = "n" ]; then
dashdash="y"
continue
elif [ -z "$target" ]; then
target="$argument"
elif [ -z "$board" ]; then
board="$argument"
else
echo "Unexpected argument: $argument"
exit 1
fi
((OPTIND = OPTIND + 1))
done
[ -z "$target" ] && {
print_usage
exit 1
}
[ -z "$board" ] && board="omnia"
[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" != "true" ] && {
echo "Current working directory is not in git repository"
exit 1
}
toplevel="$(git rev-parse --show-toplevel)"
hashes="$(curl "https://repo.turris.cz/$target/$board/packages/git-hash" | \
tail -n +2 | grep -v '^$' | sed 's/^ \* //;s/: /:/')"
get_hash() {
awk -F: -vname="$1" '$1 == name { print $2 }' <<<"$hashes"
}
# Initaly checkout turris-build
git checkout "$(get_hash turris-build)"
# And secondly modify feeds so we are modifying appropriate version
while read -r tp name url vars; do
[ "$tp" = "#" ] && fullname="$name" || fullname="feeds/$name"
githash="$(get_hash "$fullname")"
[ -n "$githash" ] && url="$(sed "s/[;^].*$//;s/$/\^$githash/" <<<"$url")"
echo "$tp" "$name" "$url" "$vars"
done < "$toplevel/feeds.conf" >feeds.conf.new
mv feeds.conf.new feeds.conf
|