still-alive
prove the world you're still alive
usage
copy the html <still-alive>still alive</still-alive>
onto your website wherever you want the still-alive message to be shown.
then, change the variables in still-alive.sh as described in the first two
comments of the script.
to install, make still-alive.sh executable with chmod +x and copy or symlink it into
your desired bin directory, e.g. mv still-alive.sh ~/.local/bin/still-alive
if you find yourself being alive one day and want to show the world, run
still-alive without any arguments
which will update the still-alive message to the current ISO 8601 date :)
code
it's a single file and should be POSIX compliant.
still-alive.sh
#!/bin/sh
# You *must* change html_dir and html_file to your own paths:
html_dir=~/html/
html_file='index.html'
# You *can* change tmp_file and backup_name if you want:
tmp_file='.tmp.html'
backup_name=".backup-index.html"
util_name=$(basename "$0")
echo "${util_name}: hi ~${USER}, nice to see you :>"
if ! [ -d "$(realpath $html_dir)" ] ; then
echo "${util_name}: html_dir '$html_dir' does not exist." >&2
exit 1
fi
if ! cd "$html_dir"
then
echo "${util_name}: failed to cd to '$html_dir'" >&2
exit 1
fi
echo " -- changed directory to '$(pwd)'"
if ! [ -f "$html_file" ]; then
echo "${util_name}: html_file '$html_file' does not exist." >&2
exit 1
fi
echo " -- backing up '$html_file' to '$backup_name'..."
cp "$html_file" "$backup_name"
echo " -- updating still-alive-date in '$html_file' and writing to tmpfile '$tmp_file'..."
awk -P -v date="$(date --iso-8601)" 'BEGIN { date_str = "<still-alive>still alive: <em>" date "</em></still-alive>"; } { gsub(/<still-alive.*>[[:space:]]*still.?alive.*<\/still-alive>/, date_str); print $0; }' "$html_file" > "$tmp_file"
if [ $? -ne 0 ]; then
echo "${util_name}: html_file '$html_file' does not exist." >&2
exit 1
fi
echo " -- moving '$tmp_file' to '$html_file'..."
mv "$tmp_file" "$html_file"
if [ $? -ne 0 ]; then
echo "${util_name}: failed to move '$tmp_file' to '$html_file'" >&2
exit 1
fi
echo "${util_name}: Done! You are still alive :)"
this is public domain sofware published by kusoge softworks inc.