From 42e1eb09e24e529c74e994728fbd04d4e511fc3a Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Wed, 13 Dec 2023 20:03:46 +0100 Subject: [PATCH] Add updater script --- bin/updatechecker | 26 +++++++++++++++++++------- bin/updater | 26 ++++++++++++++++++++++++++ install.sh | 1 + uninstall.sh | 1 + 4 files changed, 47 insertions(+), 7 deletions(-) create mode 100755 bin/updater diff --git a/bin/updatechecker b/bin/updatechecker index 26e9b2c4..e9eda9d4 100755 --- a/bin/updatechecker +++ b/bin/updatechecker @@ -7,11 +7,23 @@ export "COLOR_RESET=\e[0m" export "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')" export "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')" -if [ ! "$(env PAGER= git log -n 1 --pretty=format:\"%H\")" == "$LATEST_COMMIT" ]; then - echo -e "${COLOR_BOLD}An update for jstm's punkdateien is available." - echo -e "${COLOR_REGULAR}Latest commit: ${LATEST_COMMIT}" - echo -e "${COLOR_REGULAR} -> Message: ${LATEST_COMMIT_MESSAGE}" - echo -en "${COLOR_RESET}" -elif [ ! "${BASHRC}" == "true" ]; then - echo -e "${COLOR_BOLD}No update available" +if [ "$(env PAGER= git log -n 1 --pretty=format:\"%H\")" == "$LATEST_COMMIT" ]; then + export "UPDATE=false" +else + export "UPDATE=true" +fi + +if [ ! "$SCRIPTED" == "true" ]; then + if [ "$UPDATE" == "true" ]; then + echo -e "${COLOR_BOLD}An update for jstm's punkdateien is available." + echo -e "${COLOR_REGULAR}Latest commit: ${LATEST_COMMIT}" + echo -e "${COLOR_REGULAR} -> Message: ${LATEST_COMMIT_MESSAGE}" + echo -en "${COLOR_RESET}" + elif [ ! "${BASHRC}" == "true" ]; then + echo -e "${COLOR_BOLD}No update available" + fi +else + if [ "$UPDATE" == "true" ]; then + echo "$LATEST_COMMIT_MESSAGE" + fi fi diff --git a/bin/updater b/bin/updater new file mode 100755 index 00000000..755bc78b --- /dev/null +++ b/bin/updater @@ -0,0 +1,26 @@ +#!/bin/bash +export "UPDATER_VERSION=1" +if [ "$STAGE" == "1" ]; then + echo ":: Removing files (again)" + ./uninstall.sh + echo ":: Installing files" + ./install.sh + echo ":: Update complete." + rm -rf "$HOME/.config/.jstm_dotfiles_updater" +else + echo ":: Checking for updates" + if [ "$(env SCRIPTED=true dotfiles-updatechecker)" == "" ] && [ ! "$1" == "--force" ]; then + echo ":: No update is available. Use \"--force\" to update anyway." + exit 1 + fi + # Unused as of now, may be used in a later commit + echo ":: Writing info file" + echo "UPDATER_VERSION_OLD=${UPDATER_VERSION}" > "$HOME/.config/.jstm_dotfiles_updater" + echo ":: Removing files" + cd "$HOME/.dotfiles" + ./uninstall.sh + echo ":: Pulling updates" + git pull + echo ":: Running updater (stage 2)" + env STAGE=1 "$HOME/.dotfiles/bin/updater" +fi diff --git a/install.sh b/install.sh index f7d67322..4e292238 100755 --- a/install.sh +++ b/install.sh @@ -78,6 +78,7 @@ link "lone-files/dolphinrc" ".config/dolphinrc" # punktdateien scripts link "bin/updatechecker" ".local/bin/dotfiles-updatechecker" +link "bin/updater" ".local/bin/dotfiles-updater" # write install file echo "pls don't remove" > "$HOME/.config/.jstm_dotfiles" diff --git a/uninstall.sh b/uninstall.sh index e2a4c277..2cd717c6 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -58,3 +58,4 @@ unlink ".config/dolphinrc" # punktdateien scripts unlink ".local/bin/dotfiles-updatechecker" +unlink ".local/bin/dotfiles-updater"