punktdateien/bin/updatechecker

47 lines
1.5 KiB
Text
Raw Permalink Normal View History

2024-06-03 22:40:52 +02:00
#!/usr/bin/env bash
2024-06-02 17:15:38 +02:00
cd "${HOME}/.dotfiles" || (
2024-06-03 20:10:39 +02:00
echo ":: Error: Can't cd into ${HOME}/.dotfiles"
exit 1
2024-06-02 17:15:38 +02:00
)
# Colors
COLOR="31"
COLOR_REGULAR="\e[0;${COLOR}m"
COLOR_BOLD="\e[1;${COLOR}m"
COLOR_RESET="\e[0m"
# Latest commit
if curl -qsI https://git.staropensource.de|head -1|grep " 200" &> /dev/null; then
2024-06-03 20:10:39 +02:00
COMMIT=$(env PAGER= git log -n 1 --pretty=format:\"%H\")
LATEST_COMMIT=$(curl -sX 'GET' 'https://git.staropensource.de/api/v1/repos/JeremyStarTM/punktdateien/branches/develop' -H 'accept: application/json'|jq --monochrome-output '.commit.id')
LATEST_COMMIT_MESSAGE=$(curl -sX 'GET' 'https://git.staropensource.de/api/v1/repos/JeremyStarTM/punktdateien/branches/develop' -H 'accept: application/json'|jq --monochrome-output '.commit.message'|sed 's/\\n//g')
2024-06-02 17:15:38 +02:00
else
2024-06-03 20:10:39 +02:00
[[ -z "${SCRIPTED}" ]] && echo -e "${COLOR_BOLD}https://git.staropensource.de is not reachable"
exit 1
2024-06-02 17:15:38 +02:00
fi
2023-12-13 19:32:24 +01:00
2024-06-02 17:19:06 +02:00
if [ "${COMMIT}" == "${LATEST_COMMIT}" ] || [ -z "${LATEST_COMMIT}" ]; then
2024-06-03 20:10:39 +02:00
UPDATE=
2023-12-13 20:03:46 +01:00
else
2024-06-03 20:10:39 +02:00
UPDATE=true
2023-12-13 20:03:46 +01:00
fi
2024-06-02 17:15:38 +02:00
if [ -z "${SCRIPTED}" ]; then
2024-06-03 20:10:39 +02:00
if [ -n "${UPDATE}" ]; then
echo -e "${COLOR_BOLD}An update for jstm's punktdateien is available."
echo -e "${COLOR_REGULAR}Latest commit: ${LATEST_COMMIT}"
echo " -> Message: ${LATEST_COMMIT_MESSAGE}"
echo ""
echo -e "${COLOR_BOLD}Update by executing \"dotfiles-updater\""
echo -en "${COLOR_RESET}"
exit 0
elif [ -z "${BASHRC}" ]; then
echo -e "${COLOR_BOLD}No update available"
exit 1
fi
2024-06-02 17:15:38 +02:00
else
2024-06-03 20:10:39 +02:00
if [ -n "${UPDATE}" ]; then
echo "${LATEST_COMMIT_MESSAGE}"
fi
2023-12-13 19:32:24 +01:00
fi