-
Notifications
You must be signed in to change notification settings - Fork 4
/
update-recipe-file.sh
executable file
·85 lines (73 loc) · 2 KB
/
update-recipe-file.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
#!/usr/bin/env bash
#
# update a recipe.sh file given:
# - recipe name
# - recipe version
# - (optionally) recipe file sha256sum
#
# XXX:
# - generalize as a verb?
# - "crosware update-recipe-file recipe 1.2.3 abcdef0123456789...."
# - add "crosware upgrade recipe"?
# - add git commit?
# - use arrays for ver/url figuring
#
set -eu
function failexit() {
echo "${1}"
exit 1
}
if [ "${#}" -lt 2 ] ; then
failexit "$(basename ${BASH_SOURCE[0]}) recipe version.dot.number [sha256]"
fi
rn="${1}"
rv="${2}"
rs=""
if [ "${#}" -ge 3 ] ; then
rs="${3}"
fi
td="$(cd $(dirname "${BASH_SOURCE[0]}")/.. && pwd)"
cw="${td}/bin/crosware"
test -e "${cw}" || {
failexit "could not find crosware top directory"
}
if [ "${rs}x" == "x" ] ; then
echo "no sha256sum passed, attempting to figure one out"
out="$(${cw} run-func cwver_${rn} cwurl_${rn} | paste -s -d'|' -)"
ov="${out%%|*}"
ru="${out#${ov}|}"
ru="${ru//${ov}/${rv}}"
rs="$(curl -kLs "${ru}" | sha256sum | awk '{print $1}')"
fi
if ! $(echo -n "${rs}" | wc -c | grep -q '^64$') ; then
failexit "${rs} doesn't look right..."
fi
rd="${td}/recipes"
echo "top directory is ${td}"
echo "recipe directory is ${rd}"
if ! $(find ${rd}/*/*.sh -name ${rn}.sh | wc -l | grep -q '^1$') ; then
failexit "ambiguous recipe name ${rn}; no such recipe ${rn} or multiple ${rn}.sh files found"
fi
rf="$(find ${rd}/*/*.sh -name ${rn}.sh)"
echo "recipe file is ${rf}"
for fe in rver rsha256 ; do
if ! $(grep -q "^${fe}=" "${rf}") ; then
failexit "no ${fe} line in ${rf}"
fi
cv="$(grep "^${fe}=" "${rf}" | cut -f2 -d= | tr -d '"')"
echo "current value of ${fe} in ${rf} is ${cv}"
done
echo "setting value of 'rver' in ${rf} to ${rv}"
sed -i "s#^rver=.*#rver=\"${rv}\"#" "${rf}"
echo "setting value of 'rsha256' in ${rf} to ${rs}"
sed -i "s#^rsha256=.*#rsha256=\"${rs}\"#" "${rf}"
if $(command -v git &>/dev/null) ; then
echo "git diff:"
echo
env PAGER=cat git diff
fi
echo
echo "git commit command:"
echo
echo " git commit -a -m '${rn}: update to ${rv}'"
echo