mirror of
https://github.com/ivuorinen/dotfiles.git
synced 2026-01-26 11:14:08 +00:00
fix(scripts): install-cheat-tldr now updates files
This commit is contained in:
@@ -51,14 +51,15 @@ for d in "$TLDR_TEMP_DIR"/pages/*; do
|
||||
TLDR_FILE="$SECTION_DIR/${FILENAME}"
|
||||
# echo "-> dest: $TLDR_FILE"
|
||||
|
||||
replacable "$FILE" "$TLDR_FILE"
|
||||
override=$?
|
||||
if [ "$override" -ne 1 ]; then
|
||||
cp "$FILE" "$TLDR_FILE" && msg_run "Updated: $TLDR_FILE"
|
||||
# Update the original file for making the replacable value comparable
|
||||
if [ -f "$FILE" ] && [ '---' != "$(head -1 < "$FILE")" ]; then
|
||||
echo -e "---\n$TLDR_SYNTAX\n$TLDR_TAGS\n$TLDR_SOURCE\n---\n$(cat "$FILE")" > "$FILE"
|
||||
fi
|
||||
|
||||
if [ -f "$TLDR_FILE" ] && [ '---' != "$(head -1 < "$TLDR_FILE")" ]; then
|
||||
echo -e "---\n$TLDR_SYNTAX\n$TLDR_TAGS\n$TLDR_SOURCE\n---\n$(cat "$TLDR_FILE")" > "$TLDR_FILE"
|
||||
replacable "$FILE" "$TLDR_FILE"
|
||||
override=$?
|
||||
if [ "$override" -ne 0 ]; then
|
||||
cp "$FILE" "$TLDR_FILE" && msg_run "Updated: $TLDR_FILE"
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
#
|
||||
# Shared bash functions and helpers
|
||||
# that can be sourced to other scripts.
|
||||
#
|
||||
|
||||
# Helper env variables. Use like this: VERBOSE=1 ./script.sh
|
||||
: "${VERBOSE:=0}"
|
||||
|
||||
|
||||
# -- Colors -- #
|
||||
CLR_RED="\033[1;31m"
|
||||
@@ -249,23 +252,34 @@ 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, replacable" && return 1; }
|
||||
[[ ! -r "$FILE1" ]] && {
|
||||
[[ $VERBOSE -eq 1 ]] && msg_err "File 1 ($FILE1) does not exist"
|
||||
return 0;
|
||||
}
|
||||
[[ ! -r "$FILE2" ]] && {
|
||||
[[ $VERBOSE -eq 1 ]] && msg_err "File 2 ($FILE2) does not exist, replacable"
|
||||
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;
|
||||
[[ $VERBOSE -eq 1 ]] && msg_err "Could not get hash for file 1 ($FILE1)"
|
||||
return 0;
|
||||
}
|
||||
[[ $FILE2_HASH = "" ]] && {
|
||||
msg_err "Could not get hash for file 2 ($FILE2), replacable" && return 1;
|
||||
[[ $VERBOSE -eq 1 ]] && msg_err "Could not get hash for file 2 ($FILE2), replacable"
|
||||
return 1;
|
||||
}
|
||||
|
||||
[[ "$FILE1_HASH" == "$FILE2_HASH" ]] && {
|
||||
msg_ok "Files match, not replacable" && return 0;
|
||||
[[ $VERBOSE -eq 1 ]] && msg_ok "Files match, not replacable: $FILE1"
|
||||
return 0;
|
||||
}
|
||||
|
||||
[[ $VERBOSE -eq 1 ]] && msg_warn "Files do not match ($FILE1_HASH != $FILE2_HASH), replacable"
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user