holiday/update
2025-02-22 13:01:06 +09:00

46 lines
1.0 KiB
Bash
Executable File

#!/bin/sh
# Settings
CSV_URL="https://www8.cao.go.jp/chosei/shukujitsu/syukujitsu.csv"
# Internal configuration settings
LOCK_DIR="lock"
TMP_CSV_FILE="holidays-jp-tmp.csv"
RAW_CSV_FILE="holidays-jp-raw.csv"
CSV_FILE="holidays-jp.csv"
EXIT_SUCCESS=0
EXIT_FAILURE=1
# Verify the required runtime environment
if ! command -v curl >/dev/null; then
echo "This script requires \"curl\" to be installed. Please install it and try again."
exit $EXIT_FAILURE
fi
if ! command -v nkf >/dev/null; then
echo "This script requires \"nkf\" to be installed. Please install it and try again."
exit $EXIT_FAILURE
fi
# Acquire the lock or exit
if ! mkdir "$LOCK_DIR" 2>/dev/null; then
echo "Another process is holding the lock. Exiting."
exit $EXIT_FAILURE
fi
# Run
curl -sS -L -o $TMP_CSV_FILE $CSV_URL
if ! diff -q $RAW_CSV_FILE $TMP_CSV_FILE >/dev/null 2>&1; then
mv $TMP_CSV_FILE $RAW_CSV_FILE
nkf -w $RAW_CSV_FILE >$CSV_FILE
else
rm $TMP_CSV_FILE
fi
# Release the lock
rmdir "$LOCK_DIR"
# Exit
exit $EXIT_SUCCESS