added colors

This commit is contained in:
Tim Schubert 2022-05-21 13:18:21 +02:00
parent bc7ce3fe60
commit 3614accd76
Signed by: dadada
GPG key ID: EEB8D1CE62C4DFEA

21
update
View file

@ -1,43 +1,44 @@
#!/bin/sh #!/usr/bin/bash
update() { update() {
url="$1" url="$1"
pad="$(basename "$url").txt" pad="$(basename "$url").txt"
dst="$pad" dst="$gitdir/$pad"
gitdir="$(dirname "$dst")"
curl --silent -k -o "${dst}" "${url}/export/txt" curl --silent -k -o "${dst}" "${url}/export/txt"
status="$?" status="$?"
if [ ${status} -ne 0 ]; then if [ ${status} -ne 0 ]; then
echo "Failed to get pad at ${url}" echo -e "\e[1;31mFailed to get pad at ${url}\e[0m"
return return
fi fi
newlength="$(wc -l < "${dst}")" newlength="$(wc -l < "${dst}")"
if [ "$newlength" -lt 3 ] if [ "$newlength" -lt 3 ]
then then
echo "Skipping update of ${url}, because pad has likely been removed" echo -e "\e[1;33mSkipping update of ${url}, because pad has likely been removed\e[0m"
return return
fi fi
git -C "${gitdir}" add "${dst}" git -C "${gitdir}" add "${dst}"
changes=$(git -C "${gitdir}" diff --cached | wc -l) changes=$(git -C "${gitdir}" diff --cached | wc -l)
if [ "$changes" -lt 1 ]; then if [ "$changes" -lt 1 ]; then
echo "Nothing changed for ${url}" echo -e "\e[1;34mNothing changed for ${url}\e[0m"
return return
fi fi
git -C "${gitdir}" commit -m "Updated: ${dst} from ${url}" git -C "${gitdir}" commit -m "Updated: ${dst} from ${url}" > /dev/null
echo "\e[1;32mUpdated ${dst} from ${url}\e[0m"
} }
if ! git rev-parse --is-inside-work-tree if ! git rev-parse --is-inside-work-tree > /dev/null
then then
echo "Not a working directory" echo -e "\e[1;31mNot a working directory\e[0m"
exit 1 exit 1
fi fi
gitdir="$(realpath ${1:-$PWD})"
while read -r pad while read -r pad
do do
update "$pad" update "$pad"
git -C "${gitdir}" reset --hard HEAD git -C "${gitdir}" reset --hard HEAD > /dev/null
done done