added nautilus scripts (needs nautilus-python package)
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Source the script 'common-functions.sh'.
|
||||
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
|
||||
ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR")
|
||||
source "$ROOT_DIR/common-functions.sh"
|
||||
|
||||
_main() {
|
||||
local input_files=""
|
||||
local output_dir=""
|
||||
|
||||
# Execute initial checks.
|
||||
_check_dependencies "command=rhash"
|
||||
_display_wait_box "2"
|
||||
input_files=$(_get_files "par_type=file; par_recursive=true")
|
||||
|
||||
# Execute the function '_main_task' for each file in parallel.
|
||||
_run_task_parallel "$input_files" "$output_dir"
|
||||
|
||||
local std_output=""
|
||||
std_output=$(_storage_text_read_all)
|
||||
std_output=$(_text_sort "$std_output")
|
||||
# shellcheck disable=SC2001
|
||||
std_output=$(sed "s|\(.*\)$FIELD_SEPARATOR\(.*\)|\2$FIELD_SEPARATOR\1|g" <<<"$std_output")
|
||||
|
||||
_display_list_box "$std_output" "--column=CRC32;--column=File"
|
||||
}
|
||||
|
||||
_main_task() {
|
||||
local input_file=$1
|
||||
local output_dir=$2
|
||||
local std_output=""
|
||||
local nl_escaped="\\\n"
|
||||
|
||||
# Run the main process.
|
||||
std_output=$(rhash --printf="%c %p\n" -- "$input_file" 2>/dev/null)
|
||||
std_output=$(_text_remove_pwd "$std_output")
|
||||
|
||||
# Convert filenames with '\n'.
|
||||
if [[ "$std_output" == *$'\n'* ]]; then
|
||||
std_output=$(sed -z "s|\n|$nl_escaped|g; s|$nl_escaped$||g" <<<"$std_output")
|
||||
std_output="\\$std_output"
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2001
|
||||
std_output=$(sed "s|\([^ ]*\)\s*\(.*\)|\2$FIELD_SEPARATOR\1|g" <<<"$std_output")
|
||||
|
||||
_storage_text_write_ln "$std_output"
|
||||
}
|
||||
|
||||
_main "$@"
|
||||
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Source the script 'common-functions.sh'.
|
||||
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
|
||||
ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR")
|
||||
source "$ROOT_DIR/common-functions.sh"
|
||||
|
||||
_main() {
|
||||
local input_files=""
|
||||
local output_dir=""
|
||||
|
||||
# Execute initial checks.
|
||||
_check_dependencies ""
|
||||
_display_wait_box "2"
|
||||
input_files=$(_get_files "par_type=file; par_recursive=true")
|
||||
|
||||
# Execute the function '_main_task' for each file in parallel.
|
||||
_run_task_parallel "$input_files" "$output_dir"
|
||||
|
||||
local std_output=""
|
||||
std_output=$(_storage_text_read_all)
|
||||
std_output=$(_text_sort "$std_output")
|
||||
# shellcheck disable=SC2001
|
||||
std_output=$(sed "s|\(.*\)$FIELD_SEPARATOR\(.*\)|\2$FIELD_SEPARATOR\1|g" <<<"$std_output")
|
||||
|
||||
_display_list_box "$std_output" "--column=MD5;--column=File"
|
||||
}
|
||||
|
||||
_main_task() {
|
||||
local input_file=$1
|
||||
local output_dir=$2
|
||||
local std_output=""
|
||||
|
||||
# Run the main process.
|
||||
std_output=$(md5sum -- "$input_file" 2>/dev/null)
|
||||
std_output=$(_text_remove_pwd "$std_output")
|
||||
|
||||
# shellcheck disable=SC2001
|
||||
std_output=$(sed "s|\([^ ]*\)\s*\(.*\)|\2$FIELD_SEPARATOR\1|g" <<<"$std_output")
|
||||
|
||||
_storage_text_write_ln "$std_output"
|
||||
}
|
||||
|
||||
_main "$@"
|
||||
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Source the script 'common-functions.sh'.
|
||||
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
|
||||
ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR")
|
||||
source "$ROOT_DIR/common-functions.sh"
|
||||
|
||||
_main() {
|
||||
local input_files=""
|
||||
local output_dir=""
|
||||
|
||||
# Execute initial checks.
|
||||
_check_dependencies ""
|
||||
_display_wait_box "2"
|
||||
input_files=$(_get_files "par_type=file; par_recursive=true")
|
||||
|
||||
# Execute the function '_main_task' for each file in parallel.
|
||||
_run_task_parallel "$input_files" "$output_dir"
|
||||
|
||||
local std_output=""
|
||||
std_output=$(_storage_text_read_all)
|
||||
std_output=$(_text_sort "$std_output")
|
||||
# shellcheck disable=SC2001
|
||||
std_output=$(sed "s|\(.*\)$FIELD_SEPARATOR\(.*\)|\2$FIELD_SEPARATOR\1|g" <<<"$std_output")
|
||||
|
||||
_display_list_box "$std_output" "--column=SHA-1;--column=File"
|
||||
}
|
||||
|
||||
_main_task() {
|
||||
local input_file=$1
|
||||
local output_dir=$2
|
||||
local std_output=""
|
||||
|
||||
# Run the main process.
|
||||
std_output=$(sha1sum -- "$input_file" 2>/dev/null)
|
||||
std_output=$(_text_remove_pwd "$std_output")
|
||||
|
||||
# shellcheck disable=SC2001
|
||||
std_output=$(sed "s|\([^ ]*\)\s*\(.*\)|\2$FIELD_SEPARATOR\1|g" <<<"$std_output")
|
||||
|
||||
_storage_text_write_ln "$std_output"
|
||||
}
|
||||
|
||||
_main "$@"
|
||||
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Source the script 'common-functions.sh'.
|
||||
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
|
||||
ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR")
|
||||
source "$ROOT_DIR/common-functions.sh"
|
||||
|
||||
_main() {
|
||||
local input_files=""
|
||||
local output_dir=""
|
||||
|
||||
# Execute initial checks.
|
||||
_check_dependencies ""
|
||||
_display_wait_box "2"
|
||||
input_files=$(_get_files "par_type=file; par_recursive=true")
|
||||
|
||||
# Execute the function '_main_task' for each file in parallel.
|
||||
_run_task_parallel "$input_files" "$output_dir"
|
||||
|
||||
local std_output=""
|
||||
std_output=$(_storage_text_read_all)
|
||||
std_output=$(_text_sort "$std_output")
|
||||
# shellcheck disable=SC2001
|
||||
std_output=$(sed "s|\(.*\)$FIELD_SEPARATOR\(.*\)|\2$FIELD_SEPARATOR\1|g" <<<"$std_output")
|
||||
|
||||
_display_list_box "$std_output" "--column=SHA-256;--column=File"
|
||||
}
|
||||
|
||||
_main_task() {
|
||||
local input_file=$1
|
||||
local output_dir=$2
|
||||
local std_output=""
|
||||
|
||||
# Run the main process.
|
||||
std_output=$(sha256sum -- "$input_file" 2>/dev/null)
|
||||
std_output=$(_text_remove_pwd "$std_output")
|
||||
|
||||
# shellcheck disable=SC2001
|
||||
std_output=$(sed "s|\([^ ]*\)\s*\(.*\)|\2$FIELD_SEPARATOR\1|g" <<<"$std_output")
|
||||
|
||||
_storage_text_write_ln "$std_output"
|
||||
}
|
||||
|
||||
_main "$@"
|
||||
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Source the script 'common-functions.sh'.
|
||||
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
|
||||
ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR")
|
||||
source "$ROOT_DIR/common-functions.sh"
|
||||
|
||||
_main() {
|
||||
local input_files=""
|
||||
local output_dir=""
|
||||
|
||||
# Execute initial checks.
|
||||
_check_dependencies ""
|
||||
_display_wait_box "2"
|
||||
input_files=$(_get_files "par_type=file; par_recursive=true")
|
||||
|
||||
# Execute the function '_main_task' for each file in parallel.
|
||||
_run_task_parallel "$input_files" "$output_dir"
|
||||
|
||||
local std_output=""
|
||||
std_output=$(_storage_text_read_all)
|
||||
std_output=$(_text_sort "$std_output")
|
||||
# shellcheck disable=SC2001
|
||||
std_output=$(sed "s|\(.*\)$FIELD_SEPARATOR\(.*\)|\2$FIELD_SEPARATOR\1|g" <<<"$std_output")
|
||||
|
||||
_display_list_box "$std_output" "--column=SHA-512;--column=File"
|
||||
}
|
||||
|
||||
_main_task() {
|
||||
local input_file=$1
|
||||
local output_dir=$2
|
||||
local std_output=""
|
||||
|
||||
# Run the main process.
|
||||
std_output=$(sha512sum -- "$input_file" 2>/dev/null)
|
||||
std_output=$(_text_remove_pwd "$std_output")
|
||||
|
||||
# shellcheck disable=SC2001
|
||||
std_output=$(sed "s|\([^ ]*\)\s*\(.*\)|\2$FIELD_SEPARATOR\1|g" <<<"$std_output")
|
||||
|
||||
_storage_text_write_ln "$std_output"
|
||||
}
|
||||
|
||||
_main "$@"
|
||||
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Source the script 'common-functions.sh'.
|
||||
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
|
||||
ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR")
|
||||
source "$ROOT_DIR/common-functions.sh"
|
||||
|
||||
_main() {
|
||||
local input_files=""
|
||||
local output_dir=""
|
||||
|
||||
# Execute initial checks.
|
||||
_check_dependencies "command=rhash"
|
||||
_display_wait_box "2"
|
||||
input_files=$(_get_files "par_type=file; par_recursive=true")
|
||||
|
||||
# Execute the function '_main_task' for each file in parallel.
|
||||
_run_task_parallel "$input_files" "$output_dir"
|
||||
|
||||
local std_output=""
|
||||
std_output=$(_storage_text_read_all)
|
||||
|
||||
_display_text_box "$std_output"
|
||||
}
|
||||
|
||||
_main_task() {
|
||||
local input_file=$1
|
||||
local output_dir=$2
|
||||
local std_output=""
|
||||
|
||||
# Run the main process.
|
||||
std_output=$(rhash --printf="%p:\nCRC32: %c\nMD5: %m\nSHA-1: %h\nSHA-224: %{sha-224}\nSHA-256: %{sha-256}\nSHA-384: %{sha-384}\nSHA-512: %{sha-512}\n " -- "$input_file" 2>/dev/null)
|
||||
std_output=$(_text_remove_pwd "$std_output")
|
||||
|
||||
_storage_text_write_ln "$std_output"
|
||||
}
|
||||
|
||||
_main "$@"
|
||||
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Source the script 'common-functions.sh'.
|
||||
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
|
||||
ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR")
|
||||
source "$ROOT_DIR/common-functions.sh"
|
||||
|
||||
_main() {
|
||||
local input_files=""
|
||||
local output_dir=""
|
||||
|
||||
# Execute initial checks.
|
||||
_check_dependencies ""
|
||||
_display_wait_box "2"
|
||||
input_files=$(_get_files "par_type=file; par_recursive=true")
|
||||
output_dir=$(_get_output_dir "par_use_same_dir=true")
|
||||
|
||||
# Execute the function '_main_task' for each file in parallel.
|
||||
_run_task_parallel "$input_files" "$output_dir"
|
||||
|
||||
local output_file=""
|
||||
output_file=$(_get_output_filename "md5sum.txt" "$output_dir" "par_extension_opt=preserve")
|
||||
|
||||
local std_output=""
|
||||
std_output=$(_storage_text_read_all)
|
||||
std_output=$(_text_sort "$std_output")
|
||||
# shellcheck disable=SC2001
|
||||
std_output=$(sed "s|\(.*\)$FIELD_SEPARATOR\(.*\)|\2 \1|g" <<<"$std_output")
|
||||
printf "%s" "$std_output" >"$output_file"
|
||||
|
||||
_display_result_box "$output_dir"
|
||||
}
|
||||
|
||||
_main_task() {
|
||||
local input_file=$1
|
||||
local output_dir=$2
|
||||
local std_output=""
|
||||
|
||||
# Run the main process.
|
||||
std_output=$(md5sum -- "$input_file" 2>/dev/null)
|
||||
std_output=$(_text_remove_pwd "$std_output")
|
||||
|
||||
# shellcheck disable=SC2001
|
||||
std_output=$(sed "s|\([^ ]*\)\s*\(.*\)|\2$FIELD_SEPARATOR\1|g" <<<"$std_output")
|
||||
|
||||
_storage_text_write_ln "$std_output"
|
||||
}
|
||||
|
||||
_main "$@"
|
||||
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Source the script 'common-functions.sh'.
|
||||
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
|
||||
ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR")
|
||||
source "$ROOT_DIR/common-functions.sh"
|
||||
|
||||
_main() {
|
||||
local input_files=""
|
||||
local output_dir=""
|
||||
|
||||
# Execute initial checks.
|
||||
_check_dependencies ""
|
||||
_display_wait_box "2"
|
||||
input_files=$(_get_files "par_type=file; par_recursive=true")
|
||||
output_dir=$(_get_output_dir "par_use_same_dir=true")
|
||||
|
||||
# Execute the function '_main_task' for each file in parallel.
|
||||
_run_task_parallel "$input_files" "$output_dir"
|
||||
|
||||
local output_file=""
|
||||
output_file=$(_get_output_filename "sha1sum.txt" "$output_dir" "par_extension_opt=preserve")
|
||||
|
||||
local std_output=""
|
||||
std_output=$(_storage_text_read_all)
|
||||
std_output=$(_text_sort "$std_output")
|
||||
# shellcheck disable=SC2001
|
||||
std_output=$(sed "s|\(.*\)$FIELD_SEPARATOR\(.*\)|\2 \1|g" <<<"$std_output")
|
||||
printf "%s" "$std_output" >"$output_file"
|
||||
|
||||
_display_result_box "$output_dir"
|
||||
}
|
||||
|
||||
_main_task() {
|
||||
local input_file=$1
|
||||
local output_dir=$2
|
||||
local std_output=""
|
||||
|
||||
# Run the main process.
|
||||
std_output=$(sha1sum -- "$input_file" 2>/dev/null)
|
||||
std_output=$(_text_remove_pwd "$std_output")
|
||||
|
||||
# shellcheck disable=SC2001
|
||||
std_output=$(sed "s|\([^ ]*\)\s*\(.*\)|\2$FIELD_SEPARATOR\1|g" <<<"$std_output")
|
||||
|
||||
_storage_text_write_ln "$std_output"
|
||||
}
|
||||
|
||||
_main "$@"
|
||||
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Source the script 'common-functions.sh'.
|
||||
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
|
||||
ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR")
|
||||
source "$ROOT_DIR/common-functions.sh"
|
||||
|
||||
_main() {
|
||||
local input_files=""
|
||||
local output_dir=""
|
||||
|
||||
# Execute initial checks.
|
||||
_check_dependencies ""
|
||||
_display_wait_box "2"
|
||||
input_files=$(_get_files "par_type=file; par_recursive=true")
|
||||
output_dir=$(_get_output_dir "par_use_same_dir=true")
|
||||
|
||||
# Execute the function '_main_task' for each file in parallel.
|
||||
_run_task_parallel "$input_files" "$output_dir"
|
||||
|
||||
local output_file=""
|
||||
output_file=$(_get_output_filename "sha256sum.txt" "$output_dir" "par_extension_opt=preserve")
|
||||
|
||||
local std_output=""
|
||||
std_output=$(_storage_text_read_all)
|
||||
std_output=$(_text_sort "$std_output")
|
||||
# shellcheck disable=SC2001
|
||||
std_output=$(sed "s|\(.*\)$FIELD_SEPARATOR\(.*\)|\2 \1|g" <<<"$std_output")
|
||||
printf "%s" "$std_output" >"$output_file"
|
||||
|
||||
_display_result_box "$output_dir"
|
||||
}
|
||||
|
||||
_main_task() {
|
||||
local input_file=$1
|
||||
local output_dir=$2
|
||||
local std_output=""
|
||||
|
||||
# Run the main process.
|
||||
std_output=$(sha256sum -- "$input_file" 2>/dev/null)
|
||||
std_output=$(_text_remove_pwd "$std_output")
|
||||
|
||||
# shellcheck disable=SC2001
|
||||
std_output=$(sed "s|\([^ ]*\)\s*\(.*\)|\2$FIELD_SEPARATOR\1|g" <<<"$std_output")
|
||||
|
||||
_storage_text_write_ln "$std_output"
|
||||
}
|
||||
|
||||
_main "$@"
|
||||
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Source the script 'common-functions.sh'.
|
||||
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
|
||||
ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR")
|
||||
source "$ROOT_DIR/common-functions.sh"
|
||||
|
||||
_main() {
|
||||
local input_files=""
|
||||
local output_dir=""
|
||||
|
||||
# Execute initial checks.
|
||||
_check_dependencies ""
|
||||
_display_wait_box "2"
|
||||
input_files=$(_get_files "par_type=file; par_recursive=true")
|
||||
output_dir=$(_get_output_dir "par_use_same_dir=true")
|
||||
|
||||
# Execute the function '_main_task' for each file in parallel.
|
||||
_run_task_parallel "$input_files" "$output_dir"
|
||||
|
||||
local output_file=""
|
||||
output_file=$(_get_output_filename "sha512sum.txt" "$output_dir" "par_extension_opt=preserve")
|
||||
|
||||
local std_output=""
|
||||
std_output=$(_storage_text_read_all)
|
||||
std_output=$(_text_sort "$std_output")
|
||||
# shellcheck disable=SC2001
|
||||
std_output=$(sed "s|\(.*\)$FIELD_SEPARATOR\(.*\)|\2 \1|g" <<<"$std_output")
|
||||
printf "%s" "$std_output" >"$output_file"
|
||||
|
||||
_display_result_box "$output_dir"
|
||||
}
|
||||
|
||||
_main_task() {
|
||||
local input_file=$1
|
||||
local output_dir=$2
|
||||
local std_output=""
|
||||
|
||||
# Run the main process.
|
||||
std_output=$(sha512sum -- "$input_file" 2>/dev/null)
|
||||
std_output=$(_text_remove_pwd "$std_output")
|
||||
|
||||
# shellcheck disable=SC2001
|
||||
std_output=$(sed "s|\([^ ]*\)\s*\(.*\)|\2$FIELD_SEPARATOR\1|g" <<<"$std_output")
|
||||
|
||||
_storage_text_write_ln "$std_output"
|
||||
}
|
||||
|
||||
_main "$@"
|
||||
@@ -0,0 +1,81 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Source the script 'common-functions.sh'.
|
||||
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
|
||||
ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR")
|
||||
source "$ROOT_DIR/common-functions.sh"
|
||||
|
||||
_main() {
|
||||
local input_files=""
|
||||
|
||||
# Execute initial checks.
|
||||
_check_dependencies ""
|
||||
_display_wait_box "2"
|
||||
input_files=$(_get_files "par_type=file; par_max_items=1; par_select_mime=text/plain")
|
||||
|
||||
# Allows the symbol "'" in filenames (inside 'xargs').
|
||||
checksum_file=$(sed -z "s|'|'\\\''|g" <"$input_files")
|
||||
|
||||
# Export variables to be used inside new shells (when using 'xargs').
|
||||
export TEMP_DIR_STORAGE_TEXT
|
||||
|
||||
# Export functions to be used inside new shells (when using 'xargs').
|
||||
export -f \
|
||||
_storage_text_write \
|
||||
_storage_text_write_ln \
|
||||
_verify_checksum
|
||||
|
||||
printf "%s" "$checksum_file" | xargs \
|
||||
--no-run-if-empty \
|
||||
--delimiter=$'\n' \
|
||||
--max-procs="$(_get_max_procs)" \
|
||||
--replace="{}" \
|
||||
bash -c "_verify_checksum '{}'"
|
||||
|
||||
local std_output=""
|
||||
std_output=$(_storage_text_read_all)
|
||||
std_output=$(_text_sort "$std_output")
|
||||
|
||||
if [[ -z "$std_output" ]]; then
|
||||
std_output="No errors found."
|
||||
fi
|
||||
|
||||
_display_text_box "$std_output"
|
||||
}
|
||||
|
||||
_verify_checksum() {
|
||||
local line=$1
|
||||
local saved_checksum=""
|
||||
local saved_file=""
|
||||
local current_output=""
|
||||
local current_checksum=""
|
||||
|
||||
saved_checksum=$(printf "%s" "$line" | cut -d " " -f1)
|
||||
saved_file=$(printf "%s" "$line" | cut -d " " -f3-)
|
||||
|
||||
# Replace % to %% with the 'printf' command.
|
||||
saved_file=${saved_file//%/%%}
|
||||
|
||||
# Some checksums start with '\', for filenames with '\n' or '\'.
|
||||
# shellcheck disable=SC2059
|
||||
saved_file_decoded=$(printf "$saved_file")
|
||||
|
||||
# If the file does not exist, report and skip the check.
|
||||
if [[ ! -e "$saved_file_decoded" ]]; then
|
||||
_storage_text_write_ln "[ERROR] No such file: $saved_file"
|
||||
return 1
|
||||
fi
|
||||
|
||||
current_output=$(md5sum -- "$saved_file_decoded" 2>/dev/null)
|
||||
current_checksum=$(printf "%s" "$current_output" | cut -d " " -f1)
|
||||
|
||||
# Compare the checksum.
|
||||
if [[ "$saved_checksum" != "$current_checksum" ]]; then
|
||||
_storage_text_write_ln "[ERROR] Mismatch checksum for the file: $saved_file. Saved: $saved_checksum. Current: $current_checksum."
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
_main "$@"
|
||||
@@ -0,0 +1,81 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Source the script 'common-functions.sh'.
|
||||
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
|
||||
ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR")
|
||||
source "$ROOT_DIR/common-functions.sh"
|
||||
|
||||
_main() {
|
||||
local input_files=""
|
||||
|
||||
# Execute initial checks.
|
||||
_check_dependencies ""
|
||||
_display_wait_box "2"
|
||||
input_files=$(_get_files "par_type=file; par_max_items=1; par_select_mime=text/plain")
|
||||
|
||||
# Allows the symbol "'" in filenames (inside 'xargs').
|
||||
checksum_file=$(sed -z "s|'|'\\\''|g" <"$input_files")
|
||||
|
||||
# Export variables to be used inside new shells (when using 'xargs').
|
||||
export TEMP_DIR_STORAGE_TEXT
|
||||
|
||||
# Export functions to be used inside new shells (when using 'xargs').
|
||||
export -f \
|
||||
_storage_text_write \
|
||||
_storage_text_write_ln \
|
||||
_verify_checksum
|
||||
|
||||
printf "%s" "$checksum_file" | xargs \
|
||||
--no-run-if-empty \
|
||||
--delimiter=$'\n' \
|
||||
--max-procs="$(_get_max_procs)" \
|
||||
--replace="{}" \
|
||||
bash -c "_verify_checksum '{}'"
|
||||
|
||||
local std_output=""
|
||||
std_output=$(_storage_text_read_all)
|
||||
std_output=$(_text_sort "$std_output")
|
||||
|
||||
if [[ -z "$std_output" ]]; then
|
||||
std_output="No errors found."
|
||||
fi
|
||||
|
||||
_display_text_box "$std_output"
|
||||
}
|
||||
|
||||
_verify_checksum() {
|
||||
local line=$1
|
||||
local saved_checksum=""
|
||||
local saved_file=""
|
||||
local current_output=""
|
||||
local current_checksum=""
|
||||
|
||||
saved_checksum=$(printf "%s" "$line" | cut -d " " -f1)
|
||||
saved_file=$(printf "%s" "$line" | cut -d " " -f3-)
|
||||
|
||||
# Replace % to %% with the 'printf' command.
|
||||
saved_file=${saved_file//%/%%}
|
||||
|
||||
# Some checksums start with '\', for filenames with '\n' or '\'.
|
||||
# shellcheck disable=SC2059
|
||||
saved_file_decoded=$(printf "$saved_file")
|
||||
|
||||
# If the file does not exist, report and skip the check.
|
||||
if [[ ! -e "$saved_file_decoded" ]]; then
|
||||
_storage_text_write_ln "[ERROR] No such file: $saved_file"
|
||||
return 1
|
||||
fi
|
||||
|
||||
current_output=$(sha1sum -- "$saved_file_decoded" 2>/dev/null)
|
||||
current_checksum=$(printf "%s" "$current_output" | cut -d " " -f1)
|
||||
|
||||
# Compare the checksum.
|
||||
if [[ "$saved_checksum" != "$current_checksum" ]]; then
|
||||
_storage_text_write_ln "[ERROR] Mismatch checksum for the file: $saved_file. Saved: $saved_checksum. Current: $current_checksum."
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
_main "$@"
|
||||
@@ -0,0 +1,81 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Source the script 'common-functions.sh'.
|
||||
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
|
||||
ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR")
|
||||
source "$ROOT_DIR/common-functions.sh"
|
||||
|
||||
_main() {
|
||||
local input_files=""
|
||||
|
||||
# Execute initial checks.
|
||||
_check_dependencies ""
|
||||
_display_wait_box "2"
|
||||
input_files=$(_get_files "par_type=file; par_max_items=1; par_select_mime=text/plain")
|
||||
|
||||
# Allows the symbol "'" in filenames (inside 'xargs').
|
||||
checksum_file=$(sed -z "s|'|'\\\''|g" <"$input_files")
|
||||
|
||||
# Export variables to be used inside new shells (when using 'xargs').
|
||||
export TEMP_DIR_STORAGE_TEXT
|
||||
|
||||
# Export functions to be used inside new shells (when using 'xargs').
|
||||
export -f \
|
||||
_storage_text_write \
|
||||
_storage_text_write_ln \
|
||||
_verify_checksum
|
||||
|
||||
printf "%s" "$checksum_file" | xargs \
|
||||
--no-run-if-empty \
|
||||
--delimiter=$'\n' \
|
||||
--max-procs="$(_get_max_procs)" \
|
||||
--replace="{}" \
|
||||
bash -c "_verify_checksum '{}'"
|
||||
|
||||
local std_output=""
|
||||
std_output=$(_storage_text_read_all)
|
||||
std_output=$(_text_sort "$std_output")
|
||||
|
||||
if [[ -z "$std_output" ]]; then
|
||||
std_output="No errors found."
|
||||
fi
|
||||
|
||||
_display_text_box "$std_output"
|
||||
}
|
||||
|
||||
_verify_checksum() {
|
||||
local line=$1
|
||||
local saved_checksum=""
|
||||
local saved_file=""
|
||||
local current_output=""
|
||||
local current_checksum=""
|
||||
|
||||
saved_checksum=$(printf "%s" "$line" | cut -d " " -f1)
|
||||
saved_file=$(printf "%s" "$line" | cut -d " " -f3-)
|
||||
|
||||
# Replace % to %% with the 'printf' command.
|
||||
saved_file=${saved_file//%/%%}
|
||||
|
||||
# Some checksums start with '\', for filenames with '\n' or '\'.
|
||||
# shellcheck disable=SC2059
|
||||
saved_file_decoded=$(printf "$saved_file")
|
||||
|
||||
# If the file does not exist, report and skip the check.
|
||||
if [[ ! -e "$saved_file_decoded" ]]; then
|
||||
_storage_text_write_ln "[ERROR] No such file: $saved_file"
|
||||
return 1
|
||||
fi
|
||||
|
||||
current_output=$(sha256sum -- "$saved_file_decoded" 2>/dev/null)
|
||||
current_checksum=$(printf "%s" "$current_output" | cut -d " " -f1)
|
||||
|
||||
# Compare the checksum.
|
||||
if [[ "$saved_checksum" != "$current_checksum" ]]; then
|
||||
_storage_text_write_ln "[ERROR] Mismatch checksum for the file: $saved_file. Saved: $saved_checksum. Current: $current_checksum."
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
_main "$@"
|
||||
@@ -0,0 +1,81 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Source the script 'common-functions.sh'.
|
||||
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
|
||||
ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR")
|
||||
source "$ROOT_DIR/common-functions.sh"
|
||||
|
||||
_main() {
|
||||
local input_files=""
|
||||
|
||||
# Execute initial checks.
|
||||
_check_dependencies ""
|
||||
_display_wait_box "2"
|
||||
input_files=$(_get_files "par_type=file; par_max_items=1; par_select_mime=text/plain")
|
||||
|
||||
# Allows the symbol "'" in filenames (inside 'xargs').
|
||||
checksum_file=$(sed -z "s|'|'\\\''|g" <"$input_files")
|
||||
|
||||
# Export variables to be used inside new shells (when using 'xargs').
|
||||
export TEMP_DIR_STORAGE_TEXT
|
||||
|
||||
# Export functions to be used inside new shells (when using 'xargs').
|
||||
export -f \
|
||||
_storage_text_write \
|
||||
_storage_text_write_ln \
|
||||
_verify_checksum
|
||||
|
||||
printf "%s" "$checksum_file" | xargs \
|
||||
--no-run-if-empty \
|
||||
--delimiter=$'\n' \
|
||||
--max-procs="$(_get_max_procs)" \
|
||||
--replace="{}" \
|
||||
bash -c "_verify_checksum '{}'"
|
||||
|
||||
local std_output=""
|
||||
std_output=$(_storage_text_read_all)
|
||||
std_output=$(_text_sort "$std_output")
|
||||
|
||||
if [[ -z "$std_output" ]]; then
|
||||
std_output="No errors found."
|
||||
fi
|
||||
|
||||
_display_text_box "$std_output"
|
||||
}
|
||||
|
||||
_verify_checksum() {
|
||||
local line=$1
|
||||
local saved_checksum=""
|
||||
local saved_file=""
|
||||
local current_output=""
|
||||
local current_checksum=""
|
||||
|
||||
saved_checksum=$(printf "%s" "$line" | cut -d " " -f1)
|
||||
saved_file=$(printf "%s" "$line" | cut -d " " -f3-)
|
||||
|
||||
# Replace % to %% with the 'printf' command.
|
||||
saved_file=${saved_file//%/%%}
|
||||
|
||||
# Some checksums start with '\', for filenames with '\n' or '\'.
|
||||
# shellcheck disable=SC2059
|
||||
saved_file_decoded=$(printf "$saved_file")
|
||||
|
||||
# If the file does not exist, report and skip the check.
|
||||
if [[ ! -e "$saved_file_decoded" ]]; then
|
||||
_storage_text_write_ln "[ERROR] No such file: $saved_file"
|
||||
return 1
|
||||
fi
|
||||
|
||||
current_output=$(sha512sum -- "$saved_file_decoded" 2>/dev/null)
|
||||
current_checksum=$(printf "%s" "$current_output" | cut -d " " -f1)
|
||||
|
||||
# Compare the checksum.
|
||||
if [[ "$saved_checksum" != "$current_checksum" ]]; then
|
||||
_storage_text_write_ln "[ERROR] Mismatch checksum for the file: $saved_file. Saved: $saved_checksum. Current: $current_checksum."
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
_main "$@"
|
||||
Reference in New Issue
Block a user