2022-05-17 19:52:57 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-07-30 13:19:15 +00:00
|
|
|
# Enable commit changes to git
|
2022-05-17 19:52:57 +00:00
|
|
|
: "${GIT_COMMIT_PACKAGES:=false}"
|
2022-07-30 13:19:15 +00:00
|
|
|
# Enable push changes to git
|
2022-05-17 19:52:57 +00:00
|
|
|
: "${GIT_PUSH_PACKAGES:=false}"
|
|
|
|
|
|
|
|
SCRIPT_DIR="$(realpath "$(dirname "$0")")"
|
2022-05-22 18:09:50 +00:00
|
|
|
SRC_DIR="$(realpath "$(dirname "${SCRIPT_DIR}")")"
|
2022-06-18 16:33:00 +00:00
|
|
|
TMP_DIR="$(mktemp -d -t medzik-aur-XXXX)"
|
|
|
|
|
|
|
|
mkdir "${TMP_DIR}/aur"
|
2022-05-17 19:52:57 +00:00
|
|
|
|
|
|
|
source "${SCRIPT_DIR}/lib/parse-conf.sh"
|
|
|
|
|
2022-05-24 19:45:26 +00:00
|
|
|
compare_version() {
|
|
|
|
if $(${SCRIPT_DIR}/compare-versions.py "${1}" "${2}")
|
|
|
|
then
|
|
|
|
return 0 # true - update needed
|
|
|
|
else
|
|
|
|
return 1 # false - update not needed
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-05-17 19:52:57 +00:00
|
|
|
update-package() {
|
|
|
|
local pkgdir="${1}"
|
|
|
|
local pkgname="$(basename ${pkgdir})"
|
|
|
|
|
2022-07-30 14:37:51 +00:00
|
|
|
trap 'echo "Error code $? occurred in package ${pkgname} on line ${LINENO}" 1>&2 ; return 1' ERR
|
2022-07-30 13:19:15 +00:00
|
|
|
|
2022-05-17 19:52:57 +00:00
|
|
|
if [ ! -f "${pkgdir}/built.conf" ]
|
|
|
|
then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
eval "$(parse-conf ${pkgdir})"
|
|
|
|
|
2022-05-22 18:09:50 +00:00
|
|
|
cd "${SRC_DIR}"
|
|
|
|
|
2022-05-17 19:52:57 +00:00
|
|
|
# check the package updates from AUR
|
|
|
|
if [ ! -f "${pkgdir}/PKGBUILD" ]
|
|
|
|
then
|
|
|
|
if [ -n "${AUR_NAME}" ]
|
|
|
|
then
|
2022-05-21 10:01:49 +00:00
|
|
|
if [ -n "${AUR_PKGBASE}" ]
|
|
|
|
then
|
|
|
|
local latest_version="latest"
|
|
|
|
local last_updated="$(git ls-remote --quiet https://aur.archlinux.org/${AUR_NAME}.git refs/heads/master | awk '{print $1}')"
|
|
|
|
else
|
|
|
|
local latest_version="$(curl --location --silent "https://aur.archlinux.org/rpc/?v=5&type=info&arg=${AUR_NAME}" | jq -r '.results[0].Version')"
|
|
|
|
local last_updated="$(curl --location --silent "https://aur.archlinux.org/rpc/?v=5&type=info&arg=${AUR_NAME}" | jq -r '.results[0].LastModified')"
|
|
|
|
fi
|
|
|
|
|
2022-05-18 19:05:19 +00:00
|
|
|
local version="${AUR_UPDATED}"
|
2022-05-17 19:52:57 +00:00
|
|
|
|
2022-05-21 07:59:11 +00:00
|
|
|
if [[ -z "${last_updated}" || "${last_updated}" = "null" ]]
|
|
|
|
then
|
|
|
|
echo "[!] Failed to get latest version of ${pkgname}"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2022-05-20 20:33:54 +00:00
|
|
|
if [ "${version}" = "${last_updated}" ]
|
2022-05-17 19:52:57 +00:00
|
|
|
then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2022-05-20 20:33:54 +00:00
|
|
|
sed -i "s|^\(AUR_UPDATED=\)\(.*\)\$|\1\"${last_updated}\"|g" "${pkgdir}/built.conf"
|
2022-05-17 19:52:57 +00:00
|
|
|
|
|
|
|
if [ "${GIT_COMMIT_PACKAGES}" = "true" ]
|
|
|
|
then
|
2022-05-19 14:07:09 +00:00
|
|
|
git add "${pkgdir}/built.conf"
|
2022-06-26 14:13:42 +00:00
|
|
|
git commit -m "upgpkg(${pkgname}): ${latest_version}"
|
2022-05-17 19:52:57 +00:00
|
|
|
fi
|
|
|
|
|
2022-05-18 20:53:04 +00:00
|
|
|
echo "[i] Updated '${pkgname}' to '${latest_version}'"
|
|
|
|
|
2022-05-17 19:52:57 +00:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f "${pkgdir}/built.conf" ]
|
|
|
|
then
|
|
|
|
# check the package updates from github
|
|
|
|
if [ -n "${GITHUB_REPO}" ]
|
|
|
|
then
|
|
|
|
# check latest version
|
|
|
|
if [ "${GITHUB_TAG}" = "true" ]
|
|
|
|
then
|
2022-05-20 20:33:54 +00:00
|
|
|
local latest_version="$(curl --location --silent -H "Authorization: token ${GITHUB_API_TOKEN}" "https://api.github.com/repos/${GITHUB_REPO}/tags" | jq -r '.[0].name')"
|
2022-05-17 19:52:57 +00:00
|
|
|
else
|
2022-05-20 14:23:00 +00:00
|
|
|
local latest_version="$(curl --silent --location -H "Authorization: token ${GITHUB_API_TOKEN}" "https://api.github.com/repos/${GITHUB_REPO}/releases/latest" | jq -r ".tag_name")"
|
|
|
|
fi
|
|
|
|
|
2022-05-20 20:11:17 +00:00
|
|
|
if [[ -z "${latest_version}" || "${latest_version}" = "null" ]]
|
2022-05-20 14:23:00 +00:00
|
|
|
then
|
|
|
|
echo "[!] Failed to get latest version of ${pkgname}"
|
|
|
|
return 1
|
2022-05-17 19:52:57 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
custom_vars=$(
|
|
|
|
. "${pkgdir}/PKGBUILD"
|
|
|
|
echo "local version=${pkgver}"
|
|
|
|
)
|
|
|
|
|
|
|
|
eval "${custom_vars}"
|
|
|
|
|
|
|
|
# Translate "_" into ".": some packages use underscores to seperate
|
|
|
|
# version numbers, but we require them to be separated by dots.
|
2022-05-20 14:23:00 +00:00
|
|
|
latest_version=${latest_version//_/.}
|
2022-05-17 19:52:57 +00:00
|
|
|
|
|
|
|
# Remove leading 'v' or 'r'
|
2022-05-20 14:23:00 +00:00
|
|
|
latest_version=${latest_version#[v,r]}
|
2022-05-17 19:52:57 +00:00
|
|
|
|
|
|
|
# Translate "-" into ".": pacman does not support - in pkgver
|
2022-05-20 14:23:00 +00:00
|
|
|
latest_version=${latest_version//-/.}
|
2022-05-17 19:52:57 +00:00
|
|
|
|
2022-05-24 19:45:26 +00:00
|
|
|
if ! $(compare_version "${version}" "${latest_version}")
|
2022-05-17 19:52:57 +00:00
|
|
|
then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
sed -i "s|^\(pkgver=\)\(.*\)\$|\1\"${latest_version}\"|g" "${pkgdir}/PKGBUILD"
|
2022-06-14 09:10:41 +00:00
|
|
|
sed -i "s|^\(pkgrel=\)\(.*\)\$|\11|g" "${pkgdir}/PKGBUILD"
|
2022-05-17 19:52:57 +00:00
|
|
|
|
|
|
|
# Update package checksums
|
2022-05-20 14:23:00 +00:00
|
|
|
cd "${pkgdir}"
|
2022-05-22 18:09:50 +00:00
|
|
|
chown -R build .
|
|
|
|
su -c 'updpkgsums' build
|
|
|
|
cd "${SRC_DIR}"
|
2022-05-17 19:52:57 +00:00
|
|
|
|
|
|
|
if [ "${GIT_COMMIT_PACKAGES}" = "true" ]
|
|
|
|
then
|
2022-05-19 14:07:09 +00:00
|
|
|
git add "${pkgdir}/PKGBUILD"
|
2022-06-26 14:13:42 +00:00
|
|
|
git commit -m "upgpkg(${pkgname}): ${latest_version}"
|
2022-05-17 19:52:57 +00:00
|
|
|
fi
|
|
|
|
|
2022-05-18 20:53:04 +00:00
|
|
|
echo "[i] Updated '${pkgname}' to '${latest_version}'"
|
|
|
|
|
2022-05-17 19:52:57 +00:00
|
|
|
return 0
|
|
|
|
fi
|
2022-05-21 10:15:23 +00:00
|
|
|
|
|
|
|
if [ -n "${NPM}" ]
|
|
|
|
then
|
|
|
|
local latest_version="$(curl --location --silent "https://unpkg.com/${NPM}/package.json" | jq -r ".version")"
|
|
|
|
|
|
|
|
if [[ -z "${latest_version}" || "${latest_version}" = "null" ]]
|
|
|
|
then
|
|
|
|
echo "[!] Failed to get latest version of ${pkgname}"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
custom_vars=$(
|
|
|
|
. "${pkgdir}/PKGBUILD"
|
|
|
|
echo "local version=${pkgver}"
|
|
|
|
)
|
|
|
|
|
|
|
|
eval "${custom_vars}"
|
|
|
|
|
2022-05-24 19:45:26 +00:00
|
|
|
if ! $(compare_version "${version}" "${latest_version}")
|
2022-05-21 10:15:23 +00:00
|
|
|
then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
sed -i "s|^\(pkgver=\)\(.*\)\$|\1\"${latest_version}\"|g" "${pkgdir}/PKGBUILD"
|
2022-06-14 09:10:41 +00:00
|
|
|
sed -i "s|^\(pkgrel=\)\(.*\)\$|\11|g" "${pkgdir}/PKGBUILD"
|
2022-05-21 10:15:23 +00:00
|
|
|
|
|
|
|
# Update package checksums
|
|
|
|
cd "${pkgdir}"
|
2022-05-22 18:09:50 +00:00
|
|
|
chown -R build .
|
|
|
|
su -c 'updpkgsums' build
|
|
|
|
cd "${SRC_DIR}"
|
2022-05-21 10:15:23 +00:00
|
|
|
|
|
|
|
if [ "${GIT_COMMIT_PACKAGES}" = "true" ]
|
|
|
|
then
|
|
|
|
git add "${pkgdir}/PKGBUILD"
|
2022-06-26 14:13:42 +00:00
|
|
|
git commit -m "upgpkg(${pkgname}): ${latest_version}"
|
2022-05-21 10:15:23 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "[i] Updated '${pkgname}' to '${latest_version}'"
|
|
|
|
|
|
|
|
return 0
|
|
|
|
fi
|
2022-05-17 19:52:57 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-05-24 19:27:33 +00:00
|
|
|
if [ -n "${1}" ]
|
|
|
|
then
|
|
|
|
update-package "./packages/${1}"
|
|
|
|
update-package "./long-built/${1}"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2022-05-23 19:15:15 +00:00
|
|
|
for pkgdir in ./packages/* ./long-built/*
|
2022-05-17 19:52:57 +00:00
|
|
|
do
|
|
|
|
update-package "${pkgdir}"
|
|
|
|
|
|
|
|
EXIT_CODE="${?}"
|
|
|
|
|
|
|
|
if ! (( ${EXIT_CODE} ))
|
|
|
|
then
|
|
|
|
if [ "${GIT_PUSH_PACKAGES}" = "true" ]
|
|
|
|
then
|
|
|
|
git pull --rebase &> /dev/null
|
|
|
|
git push &> /dev/null
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "[!] Failed to update package '$(basename ${pkgdir})'"
|
|
|
|
fi
|
|
|
|
done
|