Add updater script

This commit is contained in:
JeremyStar™ 2023-12-13 20:03:46 +01:00
parent b362f1f2d9
commit 42e1eb09e2
4 changed files with 47 additions and 7 deletions

View file

@ -7,7 +7,14 @@ 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
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}"
@ -15,3 +22,8 @@ if [ ! "$(env PAGER= git log -n 1 --pretty=format:\"%H\")" == "$LATEST_COMMIT" ]
elif [ ! "${BASHRC}" == "true" ]; then
echo -e "${COLOR_BOLD}No update available"
fi
else
if [ "$UPDATE" == "true" ]; then
echo "$LATEST_COMMIT_MESSAGE"
fi
fi

26
bin/updater Executable file
View file

@ -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

View file

@ -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"

View file

@ -58,3 +58,4 @@ unlink ".config/dolphinrc"
# punktdateien scripts
unlink ".local/bin/dotfiles-updatechecker"
unlink ".local/bin/dotfiles-updater"