correctly export array to subscript
* fix shellcheck errors and warnings
This commit is contained in:
parent
0b79b461a6
commit
c190333fdf
3 changed files with 43 additions and 17 deletions
|
@ -17,9 +17,16 @@
|
|||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
YADM_DIRECTORY=$(dirname $YADM_HOOK_REPO)
|
||||
YADM_DIRECTORY=$(dirname "$YADM_HOOK_REPO")
|
||||
YADM_CHECKSUMS=$YADM_DIRECTORY/files.checksums
|
||||
|
||||
# unpack exported array; filenames including a newline character (\n)
|
||||
# are NOT supported
|
||||
OLD_IFS="$IFS"
|
||||
IFS=$'\n'
|
||||
YADM_ENCRYPT_INCLUDE_FILES=( $YADM_ENCRYPT_INCLUDE_FILES )
|
||||
IFS="$OLD_IFS"
|
||||
|
||||
CHECKSUM_ALGORITHM="512"
|
||||
CHECKSUM_ALGORITHM_NAME="SHA-512"
|
||||
WARNING_MESSAGE="No checksums were created."
|
||||
|
@ -35,7 +42,7 @@ function print_warning_and_exit {
|
|||
# reset output color
|
||||
echo -e "\033[0m"
|
||||
|
||||
exit $YADM_HOOK_EXIT
|
||||
exit "$YADM_HOOK_EXIT"
|
||||
}
|
||||
|
||||
|
||||
|
@ -50,7 +57,7 @@ function ensure_command {
|
|||
|
||||
|
||||
function ensure_algorithm {
|
||||
# check if "shasum" supports algorithm
|
||||
# check if "shasum" supports algorithm by hashing an empty string
|
||||
echo -n | shasum --algorithm "$CHECKSUM_ALGORITHM" &> /dev/null
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
|
@ -64,11 +71,11 @@ ensure_command shasum
|
|||
ensure_algorithm
|
||||
|
||||
# empty checksum file
|
||||
echo -n > $YADM_CHECKSUMS
|
||||
echo -n > "$YADM_CHECKSUMS"
|
||||
|
||||
# calculate checksums for encrypted files
|
||||
for included in "${YADM_ENCRYPT_INCLUDE_FILES[@]}"; do
|
||||
shasum --algorithm $CHECKSUM_ALGORITHM $included >> $YADM_CHECKSUMS
|
||||
for included in ${YADM_ENCRYPT_INCLUDE_FILES[*]}; do
|
||||
shasum --algorithm $CHECKSUM_ALGORITHM "$included" >> "$YADM_CHECKSUMS"
|
||||
|
||||
# signal errors
|
||||
if [ $? -ne 0 ]; then
|
||||
|
@ -79,4 +86,4 @@ done
|
|||
echo "Wrote checksums: $YADM_CHECKSUMS ($CHECKSUM_ALGORITHM_NAME)"
|
||||
|
||||
# return exit status of the yadm command
|
||||
exit $YADM_HOOK_EXIT
|
||||
exit "$YADM_HOOK_EXIT"
|
||||
|
|
|
@ -17,9 +17,16 @@
|
|||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
YADM_DIRECTORY=$(dirname $YADM_HOOK_REPO)
|
||||
YADM_DIRECTORY=$(dirname "$YADM_HOOK_REPO")
|
||||
YADM_CHECKSUMS=$YADM_DIRECTORY/files.checksums
|
||||
|
||||
# unpack exported array; filenames including a newline character (\n)
|
||||
# are NOT supported
|
||||
OLD_IFS="$IFS"
|
||||
IFS=$'\n'
|
||||
YADM_ENCRYPT_INCLUDE_FILES=( $YADM_ENCRYPT_INCLUDE_FILES )
|
||||
IFS="$OLD_IFS"
|
||||
|
||||
CHECKSUM_ALGORITHM="512"
|
||||
CHECKSUM_ALGORITHM_NAME="SHA-512"
|
||||
WARNING_MESSAGE="Checksums were not verified."
|
||||
|
@ -35,7 +42,7 @@ function print_warning_and_exit {
|
|||
# reset output color
|
||||
echo -e "\033[0m"
|
||||
|
||||
exit $YADM_HOOK_EXIT
|
||||
exit "$YADM_HOOK_EXIT"
|
||||
}
|
||||
|
||||
|
||||
|
@ -50,7 +57,7 @@ function ensure_command {
|
|||
|
||||
|
||||
function ensure_algorithm {
|
||||
# check if "shasum" supports algorithm
|
||||
# check if "shasum" supports algorithm by hashing an empty string
|
||||
echo -n | shasum --algorithm "$CHECKSUM_ALGORITHM" &> /dev/null
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
|
@ -60,9 +67,9 @@ function ensure_algorithm {
|
|||
|
||||
|
||||
# check whether file with checksums exists
|
||||
if [ ! -f $YADM_CHECKSUMS ]; then
|
||||
if [ ! -f "$YADM_CHECKSUMS" ]; then
|
||||
# return exit status of the yadm command
|
||||
exit $YADM_HOOK_EXIT
|
||||
exit "$YADM_HOOK_EXIT"
|
||||
fi
|
||||
|
||||
# check if "shasum" exists and supports algorithm
|
||||
|
@ -70,7 +77,7 @@ ensure_command shasum
|
|||
ensure_algorithm
|
||||
|
||||
# check encrypted files for differences and capture output
|
||||
YADM_CHECKSUM_OUTPUT=$(shasum --algorithm "$CHECKSUM_ALGORITHM" --check $YADM_CHECKSUMS 2> /dev/null)
|
||||
YADM_CHECKSUM_OUTPUT=$(shasum --algorithm "$CHECKSUM_ALGORITHM" --check "$YADM_CHECKSUMS" 2> /dev/null)
|
||||
ERROR_CODE=$?
|
||||
|
||||
# some checksums do not match
|
||||
|
@ -85,9 +92,9 @@ if [ $ERROR_CODE -ne 0 ]; then
|
|||
while IFS= read -r line; do
|
||||
# try to beautify output
|
||||
if command -v grep > /dev/null && command -v sed > /dev/null; then
|
||||
echo $line | grep -iv "\sok$" | sed 's/^/ / ; s/: FAILED$//'
|
||||
echo "$line" | grep -iv "\sok$" | sed 's/^/ / ; s/: FAILED$//'
|
||||
else
|
||||
echo $line
|
||||
echo "$line"
|
||||
fi
|
||||
done <<< "$YADM_CHECKSUM_OUTPUT"
|
||||
|
||||
|
|
16
yadm
16
yadm
|
@ -1577,7 +1577,11 @@ function invoke_hook() {
|
|||
YADM_HOOK_FULL_COMMAND=$FULL_COMMAND
|
||||
YADM_HOOK_REPO=$YADM_REPO
|
||||
YADM_HOOK_WORK=$YADM_WORK
|
||||
YADM_ENCRYPT_INCLUDE_FILES=${ENCRYPT_INCLUDE_FILES[@]}
|
||||
|
||||
# pack array to export it; filenames including a newline character (\n)
|
||||
# are NOT supported
|
||||
YADM_ENCRYPT_INCLUDE_FILES=$(join_string $'\n' "${ENCRYPT_INCLUDE_FILES[@]}")
|
||||
|
||||
export YADM_HOOK_COMMAND
|
||||
export YADM_HOOK_EXIT
|
||||
export YADM_HOOK_FULL_COMMAND
|
||||
|
@ -1821,6 +1825,13 @@ function auto_bootstrap() {
|
|||
|
||||
}
|
||||
|
||||
# ****** Helper Functions ******
|
||||
|
||||
function join_string {
|
||||
local IFS="$1"
|
||||
echo "${*:2}"
|
||||
}
|
||||
|
||||
# ****** Prerequisites Functions ******
|
||||
|
||||
function require_archive() {
|
||||
|
@ -1888,7 +1899,7 @@ function readlink_available() {
|
|||
return 1
|
||||
}
|
||||
|
||||
# ****** Directory tranlations ******
|
||||
# ****** Directory translations ******
|
||||
|
||||
function unix_path() {
|
||||
# for paths used by bash/yadm
|
||||
|
@ -1908,6 +1919,7 @@ function mixed_path() {
|
|||
}
|
||||
|
||||
# ****** echo replacements ******
|
||||
|
||||
function echo() {
|
||||
IFS=' '
|
||||
printf '%s\n' "$*"
|
||||
|
|
Loading…
Reference in a new issue