use version numbers instead of dates
This commit is contained in:
parent
3400f9f90f
commit
b63c4da1ec
@ -8,34 +8,24 @@ fatal() {
|
|||||||
exit 1
|
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() {
|
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"
|
INPUT="$1"
|
||||||
LANG="$2"
|
LANG="$2"
|
||||||
|
VERSION="$3"
|
||||||
|
|
||||||
case $LANG in
|
case $LANG in
|
||||||
en|ru) : ;;
|
en|ru) : ;;
|
||||||
*) fatal "invalid language" ;;
|
*) fatal "invalid language" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
previous_version=$(( VERSION-1 ))
|
||||||
target_file="$FILES_DIR/4in1-$LANG.pdf"
|
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" ] || {
|
[ -d "$ARCHIVE_DIR" ] || {
|
||||||
mkdir "$ARCHIVE_DIR"
|
mkdir "$ARCHIVE_DIR"
|
||||||
@ -43,5 +33,7 @@ old_date="$(get_modification_time "$INPUT")"
|
|||||||
chgrp www-data "$ARCHIVE_DIR"
|
chgrp www-data "$ARCHIVE_DIR"
|
||||||
}
|
}
|
||||||
|
|
||||||
mv "$target_file" "$ARCHIVE_DIR/4in1-$LANG-$old_date.pdf"
|
[ -e "$archive_target_file" ] && fatal "invalid version: file \"$archive_target_file\" already exists"
|
||||||
|
|
||||||
|
mv "$target_file" "$archive_target_file"
|
||||||
mv "$INPUT" "$target_file"
|
mv "$INPUT" "$target_file"
|
Loading…
x
Reference in New Issue
Block a user