blog-pika/.src/gitupdate.sh
2024-06-22 09:34:19 +02:00

51 lines
1.8 KiB
Bash
Executable file

#!/bin/bash
# ──────────────────────────────────────< VARIABLES >────────────────────────────────────
# ─< define the git-directory >───────────────────────────────────────────────────────────
gitdir=$(pwd)
# ─< define the branch to be pulled >─────────────────────────────────────────────────────
branch="main"
# ─< define the format for the date >─────────────────────────────────────────────────────
date=$(date '+%d/%m/%Y %H:%M:%S')
# ─< log dir and file >───────────────────────────────────────────────────────────────────
l_dir="$HOME/logs/"
l_file="$HOME/logs/gitupdate.log"
# ────────────────────────────────────< VARIABLES END >──────────────────────────────────
g_pull ()
{
cd $gitdir
git pull origin $branch >>$l_file
echo "_____" >>$l_file
}
l_date ()
{
echo "
_____
$date
" >>$l_file
}
main ()
{
if ! command -v git >/dev/null 2>&1; then
echo "-- Error, git was not found --"
else
if [ -d $HOME/logs/ ]; then
l_date
g_pull
else
mkdir $l_dir
echo "--- Created logs folder under $l_dir ---"
sleep 1
l_date
g_pull
fi
fi
}
main