mirror of
https://github.com/ivuorinen/dotfiles.git
synced 2026-01-26 11:14:08 +00:00
feat(tools): sha256-matcher, cheat script tweaks
This commit is contained in:
@@ -35,8 +35,10 @@ for f in ${PBB_CHAPTERS[@]}; do
|
||||
HEADER=$(grep -e '^[#] ' "$f" | head -1 | awk '{print tolower($2)}')
|
||||
CHEAT_FILE="$CHEAT_DEST/${HEADER}"
|
||||
|
||||
if [ ! -f "$CHEAT_FILE" ]; then
|
||||
cp "$f" "$CHEAT_FILE" && msg_run "$CHEAT_FILE"
|
||||
replacable "$f" "$CHEAT_FILE"
|
||||
override=$?
|
||||
if [ "$override" -ne 1 ]; then
|
||||
cp "$f" "$CHEAT_FILE" && msg_run "Updated: $CHEAT_FILE"
|
||||
fi
|
||||
|
||||
LC_ALL=C perl -pi.bak -e 's/\<\!-- CHAPTER END --\>//' "$CHEAT_FILE"
|
||||
|
||||
@@ -51,8 +51,10 @@ for d in "$TLDR_TEMP_DIR"/pages/*; do
|
||||
TLDR_FILE="$SECTION_DIR/${FILENAME}"
|
||||
# echo "-> dest: $TLDR_FILE"
|
||||
|
||||
if [ ! -f "$TLDR_FILE" ]; then
|
||||
cp "$FILE" "$TLDR_FILE" && msg_run "$TLDR_FILE"
|
||||
replacable "$FILE" "$TLDR_FILE"
|
||||
override=$?
|
||||
if [ "$override" -ne 1 ]; then
|
||||
cp "$FILE" "$TLDR_FILE" && msg_run "Updated: $TLDR_FILE"
|
||||
fi
|
||||
|
||||
if [ -f "$TLDR_FILE" ] && [ '---' != "$(head -1 < "$TLDR_FILE")" ]; then
|
||||
|
||||
@@ -230,3 +230,42 @@ rnd()
|
||||
{
|
||||
echo $RANDOM | md5sum | head -c 20
|
||||
}
|
||||
|
||||
# return sha256sum for file
|
||||
# $1 - filename (string)
|
||||
function get_sha256sum()
|
||||
{
|
||||
sha256sum "$1" | head -c 64
|
||||
}
|
||||
|
||||
# Replacable file
|
||||
#
|
||||
# $1 - filename (string)
|
||||
# $2 - filename (string)
|
||||
#
|
||||
# Returns 1 when replacable, 0 when not replacable.
|
||||
function replacable()
|
||||
{
|
||||
FILE1="$1"
|
||||
FILE2="$2"
|
||||
|
||||
[[ ! -r "$FILE1" ]] && { msg_err "File 1 ($FILE1) does not exist" && return 1; }
|
||||
[[ ! -r "$FILE2" ]] && { msg_err "File 2 ($FILE2) does not exist" && return 1; }
|
||||
|
||||
FILE1_HASH=$(get_sha256sum "$FILE1")
|
||||
FILE2_HASH=$(get_sha256sum "$FILE2")
|
||||
|
||||
[[ $FILE1_HASH = "" ]] && {
|
||||
msg_err "Could not get hash for file 1 ($FILE1)" && return 1;
|
||||
}
|
||||
[[ $FILE2_HASH = "" ]] && {
|
||||
msg_err "Could not get hash for file 2 ($FILE2)" && return 1;
|
||||
}
|
||||
|
||||
[[ "$FILE1_HASH" == "$FILE2_HASH" ]] && {
|
||||
msg_ok "Files match, not replacable" && return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user