#!/bin/bash # # cron.copy.today # jms1 2024-06-25 # # Copy my Obsidian Daily Note where others can see it # # https://jms1.info/obsidian/copy-daily.html # ############################################################################### # # The MIT License (MIT) # # Copyright (C) 2024 John Simpson # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. # ############################################################################### SRC_DIR="${HOME}/Documents/Obsidian/DAYJOB/Daily Notes" DST_DIR="/keybase/team/KEYBASE_TEAM_NAME/jms1-today.md" SUM_FILE="${0}.sum" ############################################################################### ############################################################################### ############################################################################### # # If KBFS isn't mounted, do nothing. if [[ ! -d "$DST_DIR" ]] then exit 1 fi ######################################## # Obsidian is configured with "Daily notes - Date format" `YYYY-MM-DD ddd` # This `date` command generates the same exact name, so the script can find # the correct file. TODAY="$( date '+%Y-%m-%d %a' )" ######################################## # I add the current time into the file created by the script, # so we can tell when it was copied. NOW="$( date -u '+%Y-%m-%d %H:%M:%S %Z' )" ######################################## # If today's Daily Notes file doesn't exist, do nothing. if [[ ! -f "$SRC_DIR/$TODAY.md" ]] then exit 1 fi ######################################## # Figure out if the file in the shared drive needs to be copied or not. # - If the checksum file exists # - and it contains today's filename # - and the checksum itself is correct, then do nothing. if [[ -f "$SUM_FILE" ]] then if grep -q "$TODAY.md" "$SUM_FILE" then if sha256sum --status -c "$SUM_FILE" then exit 0 fi fi fi ######################################## # Copy the file ( printf '# %s\ncopied `%s`\n\n' "$TODAY" "$NOW" cat "$SRC_DIR/$TODAY.md" ) > "$DST_DIR/today.md" ######################################## # Create/update checksum file for next time sha256sum "$SRC_DIR/$TODAY.md" > "$SUM_FILE"