-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy pathtermux_pkg_upgrade_version.sh
executable file
·167 lines (144 loc) · 5.33 KB
/
termux_pkg_upgrade_version.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
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
# shellcheck shell=bash
termux_pkg_upgrade_version() {
if [[ "$#" -lt 1 ]]; then
termux_error_exit <<-EndUsage
Usage: ${FUNCNAME[0]} LATEST_VERSION [--skip-version-check]
EndUsage
fi
local LATEST_VERSION="$1"
local SKIP_VERSION_CHECK="${2:-}"
local EPOCH
EPOCH="${TERMUX_PKG_VERSION%%:*}" # If there is no epoch, this will be the full version.
# Check if it isn't the full version and add ':'.
if [[ "${EPOCH}" != "${TERMUX_PKG_VERSION}" ]]; then
EPOCH="${EPOCH}:"
else
EPOCH=""
fi
# If needed, filter version numbers using grep regexp.
if [[ -n "${TERMUX_PKG_UPDATE_VERSION_REGEXP:-}" ]]; then
# Extract version numbers.
local OLD_LATEST_VERSION="${LATEST_VERSION}"
LATEST_VERSION="$(grep -oP "${TERMUX_PKG_UPDATE_VERSION_REGEXP}" <<< "${LATEST_VERSION}" || true)"
if [[ -z "${LATEST_VERSION:-}" ]]; then
termux_error_exit <<-EndOfError
ERROR: failed to filter version numbers using regexp '${TERMUX_PKG_UPDATE_VERSION_REGEXP}'.
Ensure that it works correctly with ${OLD_LATEST_VERSION}.
EndOfError
fi
unset OLD_LATEST_VERSION
fi
# If needed, filter version numbers using sed regexp.
if [[ -n "${TERMUX_PKG_UPDATE_VERSION_SED_REGEXP:-}" ]]; then
# Extract version numbers.
local OLD_LATEST_VERSION="${LATEST_VERSION}"
LATEST_VERSION="$(sed "${TERMUX_PKG_UPDATE_VERSION_SED_REGEXP}" <<< "${LATEST_VERSION}" || true)"
if [[ -z "${LATEST_VERSION:-}" ]]; then
termux_error_exit <<-EndOfError
ERROR: failed to filter version numbers using regexp '${TERMUX_PKG_UPDATE_VERSION_SED_REGEXP}'.
Ensure that it works correctly with ${OLD_LATEST_VERSION}.
EndOfError
fi
unset OLD_LATEST_VERSION
fi
# Translate "_" into ".": some packages use underscores to seperate
# version numbers, but we require them to be separated by dots.
LATEST_VERSION="${LATEST_VERSION//_/.}"
if [[ "${SKIP_VERSION_CHECK}" != "--skip-version-check" ]]; then
if ! termux_pkg_is_update_needed \
"${TERMUX_PKG_VERSION#*:}" "${LATEST_VERSION}"; then
echo "INFO: No update needed. Already at version '${LATEST_VERSION}'."
return 0
fi
fi
if [[ -n "${TERMUX_PKG_UPGRADE_VERSION_DRY_RUN:-}" ]]; then
return 1
fi
if [[ "${BUILD_PACKAGES}" == "false" ]]; then
echo "INFO: package needs to be updated to ${LATEST_VERSION}."
return
fi
echo "INFO: package being updated to ${LATEST_VERSION}."
sed \
-e "s/^\(TERMUX_PKG_VERSION=\)\(.*\)\$/\1\"${EPOCH}${LATEST_VERSION}\"/g" \
-e "/TERMUX_PKG_REVISION=/d" \
-i "${TERMUX_PKG_BUILDER_DIR}/build.sh"
# Update checksum
if [[ "${TERMUX_PKG_SHA256[*]}" != "SKIP_CHECKSUM" ]] && [[ "${TERMUX_PKG_SRCURL:0:4}" != "git+" ]]; then
echo n | "${TERMUX_SCRIPTDIR}/scripts/bin/update-checksum" "${TERMUX_PKG_NAME}" || {
git checkout -- "${TERMUX_PKG_BUILDER_DIR}"
git pull --rebase --autostash
termux_error_exit "ERROR: failed to update checksum."
}
fi
echo "INFO: Trying to build package."
for repo_path in $(jq --raw-output 'del(.pkg_format) | keys | .[]' ${TERMUX_SCRIPTDIR}/repo.json); do
_buildsh_path="${TERMUX_SCRIPTDIR}/${repo_path}/${TERMUX_PKG_NAME}/build.sh"
repo=$(jq --raw-output ".\"${repo_path}\".name" ${TERMUX_SCRIPTDIR}/repo.json)
repo=${repo#"termux-"}
if [[ -f "${_buildsh_path}" ]]; then
echo "INFO: Package ${TERMUX_PKG_NAME} exists in ${repo} repo."
unset _buildsh_path repo_path
break
fi
done
local force_cleanup="false"
local space_available
if [[ -d "/var/lib/docker" ]]; then
# Get available space in bytes
space_available="$(df "/var/lib/docker" | awk 'NR==2 { print $4 * 1024 }')"
if (( space_available <= TERMUX_CLEANUP_BUILT_PACKAGES_THRESHOLD )); then
force_cleanup="true"
fi
fi
local big_package=false
while IFS= read -r p; do
if [[ "${p}" == "${TERMUX_PKG_NAME}" ]]; then
big_package=true
break
fi
done < "${TERMUX_SCRIPTDIR}/scripts/big-pkgs.list"
if [[ "${big_package}" == "true" ]]; then
"${TERMUX_SCRIPTDIR}/scripts/run-docker.sh" ./clean.sh
fi
if ! "${TERMUX_SCRIPTDIR}/scripts/run-docker.sh" ./build-package.sh -C -a "${TERMUX_ARCH}" -i "${TERMUX_PKG_NAME}"; then
if [[ "${big_package}" == "true" ]]; then
"${TERMUX_SCRIPTDIR}/scripts/run-docker.sh" ./clean.sh
fi
git checkout -- "${TERMUX_PKG_BUILDER_DIR}"
termux_error_exit "ERROR: failed to build."
fi
if [[ "${big_package}" == "true" ]] || [[ "${force_cleanup}" == "true" ]]; then
"${TERMUX_SCRIPTDIR}/scripts/run-docker.sh" ./clean.sh
fi
if [[ "${GIT_COMMIT_PACKAGES}" == "true" ]]; then
echo "INFO: Committing package."
stderr="$(
git add "${TERMUX_PKG_BUILDER_DIR}" 2>&1 >/dev/null
git commit -m "bump(${repo}/${TERMUX_PKG_NAME}): ${LATEST_VERSION}" \
-m "This commit has been automatically submitted by Github Actions." 2>&1 >/dev/null
)" || {
git reset HEAD --hard
termux_error_exit <<-EndOfError
ERROR: git commit failed. See below for details.
${stderr}
EndOfError
}
fi
if [[ "${GIT_PUSH_PACKAGES}" == "true" ]]; then
echo "INFO: Pushing package."
stderr="$(
# Fetch and pull before attempting to push to avoid a situation
# where a long running auto update fails because a later faster
# autoupdate got committed first and now the git history is out of date.
git fetch 2>&1 >/dev/null
git pull --rebase --autostash 2>&1 >/dev/null
git push 2>&1 >/dev/null
)" || {
termux_error_exit <<-EndOfError
ERROR: git push failed. See below for details.
${stderr}
EndOfError
}
fi
}