Created
July 29, 2022 22:49
-
-
Save bodziek666/764c98cc2d1fdc98a15fb901298848db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
WEECHAT_LOGDIR="${HOME}/.weechat/logs" | |
archive_last_year() { | |
local LAST_YEAR=$(date -d "now - 1 year" +"%Y") | |
find "${WEECHAT_LOGDIR}/${LAST_YEAR}" -type f -iname "*.weechatlog" -exec xz {} \; | |
} | |
archive_last_month() { | |
local LAST_MONTH=$(date -d "now - 1 month" +"%Y/%m") | |
find "${WEECHAT_LOGDIR}/${LAST_MONTH}" -type f -iname "*.weechatlog" -exec xz {} \; | |
} | |
display_help() { | |
echo "Archive WeeChat logs with xz" | |
echo "Usage:" | |
echo -e "\t$0 -m \t\tArchive last month" | |
echo -e "\t$0 -y \t\tArchive last year" | |
echo -e "\t$0 -h \t\tDisplay this message" | |
} | |
if [ $# -lt 1 ]; then | |
echo "Argument required" | |
display_help | |
exit 0 | |
fi | |
while getopts "myh" OPTIONS | |
do | |
case "${OPTIONS}" in | |
m) | |
archive_last_month | |
;; | |
y) | |
archive_last_year | |
;; | |
h) | |
display_help | |
exit 0 | |
;; | |
# exit if argument is ommited | |
:) | |
display_help | |
exit 1 | |
;; | |
# exit if illegal/unknown option is used | |
*) | |
display_help | |
exit 1 | |
;; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment