commit 3400f9f90fce3270b48d05f3f54d140331e23828 Author: E. S. Date: Sun Dec 31 23:40:28 2023 +0300 initial diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..757fee3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.idea \ No newline at end of file diff --git a/release-book.sh b/release-book.sh new file mode 100755 index 0000000..59081e2 --- /dev/null +++ b/release-book.sh @@ -0,0 +1,47 @@ +#!/bin/sh + +FILES_DIR="$HOME/files" +ARCHIVE_DIR="$FILES_DIR/4in1-old-versions" + +fatal() { + >&2 echo "error: $@" + exit 1 +} + +get_modification_time() { + file_path="$1" + + if [ ! -e "$file_path" ]; then + fatal "file not found: $file_path" + fi + + mod_time=$(stat -c "%Y" "$file_path") + formatted_mod_time=$(date -d "@$mod_time" "+%Y-%m-%d") + echo "$formatted_mod_time" +} + +usage() { + >&2 echo "usage: $0 en|ru" +} + +[ $# -ne 2 ] && { usage; exit 1; } + +INPUT="$1" +LANG="$2" + +case $LANG in + en|ru) : ;; + *) fatal "invalid language" ;; +esac + +target_file="$FILES_DIR/4in1-$LANG.pdf" +old_date="$(get_modification_time "$INPUT")" + +[ -d "$ARCHIVE_DIR" ] || { + mkdir "$ARCHIVE_DIR" + chmod 755 "$ARCHIVE_DIR" + chgrp www-data "$ARCHIVE_DIR" +} + +mv "$target_file" "$ARCHIVE_DIR/4in1-$LANG-$old_date.pdf" +mv "$INPUT" "$target_file" \ No newline at end of file