forked from leahneukirchen/xtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xupdate
executable file
·114 lines (87 loc) · 2.52 KB
/
xupdate
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
#!/bin/bash
XBPS_DISTDIR="$(xdistdir)" || exit 1
function usage() {
echo >&2 'Usage: xupdate [-f] [-H <hostdir>] <template>'
exit 1
}
while getopts fhH: opt; do
case "${opt}" in
f) flag_f="-f" ;;
H) flag_H="-H ${OPTARG}" ;;
h|?) usage ;;
esac
done
shift $(( OPTIND - 1 ))
if [[ -f "${1}" ]]; then
template="${1}"
elif [[ -f "$1/template" ]]; then
template="$1/template"
elif [[ -f "${XBPS_DISTDIR}/srcpkgs/$1/template" ]]; then
template="${XBPS_DISTDIR}/srcpkgs/$1/template"
else
usage
fi
template="$(readlink -f "${template}")"
# shellcheck source=template
source "${template}"
# Set error *after* sourcing template as sourcing the template can give errors
set -e
# Template not already in distdir?
if [[ -z "$(find "${XBPS_DISTDIR}/srcpkgs" -samefile "${template}" -print -quit)" ]]; then
# Copy template to distdir for fetching
pkgdir="${template%/*}"
xbps_pkgdir="${XBPS_DISTDIR}/srcpkgs/${pkgname}"
mkdir -p "${xbps_pkgdir}"
cp "${template}" "${xbps_pkgdir}"
[[ -f "${pkgdir}/update" ]] && cp "${pkgdir}/update" "${xbps_pkgdir}"
template="$xbps_pkgdir/template"
fi
function finish() {
[[ -z "${pkgdir}" ]] && return
cp "${template}" "${pkgdir}"
}
trap 'finish' EXIT
function msg() {
printf >&2 '%s: %s\n' "${0##*/}" "$@"
}
# Update hashes for *-git packages
function update_hash() {
local remote latest today
# Remote url is likely the first 4 or so components of the URL
remote="$(echo "${distfiles}" | cut -d/ -f1,2,3,4,5)"
latest="$(git ls-remote "${remote}" | grep '\sHEAD$' | cut -f1)"
[[ "${latest}" = "${_commit}" ]] && return
today="$(date -u +%Y%m%d)"
sed -i \
-e "s/^revision=.*/revision=1/" \
-e "s/^version=.*/version=${today}/" \
-e "s/^_commit=.*/_commit=${latest}/" "${template}"
echo "${today}"
}
function update_version() {
local latest_version
latest_version="$("${XBPS_DISTDIR}/xbps-src" $flag_H update-check "${pkgname}" \
| grep -e '->' \
| tail -n1 \
| sed -e "s/.* -> ${pkgname}-\(.*\)/\1/" \
| tr - .)"
[[ -z "${latest_version}" ]] && return
sed -i \
-e "s/^revision=.*/revision=1/" \
-e "s/^version=.*/version=${latest_version}/" "${template}"
echo "${latest_version}"
}
msg "Checking for ${pkgname} updates..."
new_version="$(case "${pkgname}" in
*-git) update_hash ;;
*) update_version ;;
esac)"
if [[ -z "${new_version}" ]]; then
msg "No ${pkgname} updates."
[[ -z "${flag_f}" ]] && exit 0
fi
msg "Generating checksum in '${template}'..."
xgensum -i $flag_f $flag_H "${template}" 1>&2
[[ -z "${new_version}" ]] && exit 0
msg "New version:"
echo "${new_version}"