Merge branch 'master' of ch1p.io:4in1_tools
This commit is contained in:
commit
f9a91073bd
@ -8,34 +8,24 @@ fatal() {
|
||||
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 <filename> en|ru"
|
||||
>&2 echo "usage: $0 <filename> en|ru <new_version_number>"
|
||||
}
|
||||
|
||||
[ $# -ne 2 ] && { usage; exit 1; }
|
||||
[ $# -ne 3 ] && { usage; exit 1; }
|
||||
|
||||
INPUT="$1"
|
||||
LANG="$2"
|
||||
VERSION="$3"
|
||||
|
||||
case $LANG in
|
||||
en|ru) : ;;
|
||||
*) fatal "invalid language" ;;
|
||||
esac
|
||||
|
||||
previous_version=$(( VERSION-1 ))
|
||||
target_file="$FILES_DIR/4in1-$LANG.pdf"
|
||||
old_date="$(get_modification_time "$INPUT")"
|
||||
archive_target_file="$ARCHIVE_DIR/4in1-$LANG-update$previous_version.pdf"
|
||||
|
||||
[ -d "$ARCHIVE_DIR" ] || {
|
||||
mkdir "$ARCHIVE_DIR"
|
||||
@ -43,7 +33,9 @@ old_date="$(get_modification_time "$INPUT")"
|
||||
chgrp www-data "$ARCHIVE_DIR"
|
||||
}
|
||||
|
||||
[ -e "$archive_target_file" ] && fatal "invalid version: file \"$archive_target_file\" already exists"
|
||||
|
||||
exiftool -author=idb "$INPUT"
|
||||
|
||||
mv "$target_file" "$ARCHIVE_DIR/4in1-$LANG-$old_date.pdf"
|
||||
mv "$target_file" "$archive_target_file"
|
||||
mv "$INPUT" "$target_file"
|
||||
|
Loading…
x
Reference in New Issue
Block a user