-
Notifications
You must be signed in to change notification settings - Fork 23
/
update-packages
executable file
·91 lines (71 loc) · 2.93 KB
/
update-packages
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
#!/usr/bin/env bash
set -euxo pipefail
function update_package_version {
local package
local new_version
local download_url
local package_json
local preinstall
package="$1"
new_version="$2"
download_url="$3"
package_json="${package}/package.json"
preinstall="${package}/preinstall"
# package.json
jq ".version = \"${new_version}\"" "${package_json}" > version-update.json
mv version-update.json "${package_json}"
# preinstall
sed -i "/wget/s|https://[^\"]*|${download_url}|" "${preinstall}"
}
function git_push() {
local gh_token
gh_token="$1"
if [ -z "${gh_token}" ]; then
>&2 echo "Please set GH_TOKEN"
exit 1
fi
git remote set-url origin "https://${gh_token}@github.com/jonasgroeger/jetbrains-ppa.git" > /dev/null 2>&1
git push --quiet --set-upstream origin master
}
COMMIT_FILE=commit.txt
rm -f "$COMMIT_FILE"
find packages -maxdepth 1 -mindepth 1 -type d -print0 | while read -d $'\0' PACKAGE_DIR
do
PACKAGE_JSON="${PACKAGE_DIR}/package.json"
# Default for released applications
VERSION_FIELD="version"
RELEASE_TYPE="release"
# Handle EAP packages
EAP="$(jq --raw-output ".eap // false" "${PACKAGE_JSON}")"
if [[ "${EAP}" == "true" ]]; then
VERSION_FIELD="build" # EAP have duplicates for the version, so we need to use build instead
RELEASE_TYPE="eap"
fi
CODE="$(jq --raw-output --exit-status ".code" "${PACKAGE_JSON}")"
if [ -z "${CODE}" ]; then
>&2 echo "[E] Cannot find 'code' key within ${PACKAGE_JSON}"
continue
fi
RELEASES_JSON="releases-${CODE}.json"
if [ ! -f "${PACKAGE_JSON}" ]; then
>&2 echo "[E] Cannot find ${PACKAGE_JSON}"
continue
fi
curl -sfLo "${RELEASES_JSON}" "https://data.services.jetbrains.com/products/releases?code=${CODE}&latest=true&type=${RELEASE_TYPE}"
LOCAL_VERSION="$(jq --raw-output --exit-status ".version" "${PACKAGE_JSON}")" # still use .version locally
REMOTE_VERSION="$(jq --raw-output --exit-status ".${CODE}[0].${VERSION_FIELD}" "${RELEASES_JSON}")"
DOWNLOAD_URL="$(jq --raw-output --exit-status ".${CODE}[0].downloads.linux.link" "${RELEASES_JSON}")"
rm -f "${RELEASES_JSON}"
if [ -z "${LOCAL_VERSION}" ] || [ -z "${REMOTE_VERSION}" ]; then
>&2 echo "[E] Both 'LOCAL_VERSION' and 'REMOTE_VERSION' must be set. Probably a curl / jq error."
continue
fi
if [ "${LOCAL_VERSION}" == "${REMOTE_VERSION}" ]; then
>&2 printf "%3s: Local (%10s) == Remote (%10s) -> Not updating.\n" "${CODE}" "${LOCAL_VERSION}" "${REMOTE_VERSION}"
continue
fi
printf "%3s: Local (%10s) != Remote (%10s) -> Updating.\n" "${CODE}" "${LOCAL_VERSION}" "${REMOTE_VERSION}"
update_package_version "${PACKAGE_DIR}" "${REMOTE_VERSION}" "${DOWNLOAD_URL}"
./build-single-deb "${PACKAGE_DIR}"
echo "Upgrade ${CODE}: ${LOCAL_VERSION} -> ${REMOTE_VERSION}" >> "$COMMIT_FILE"
done