particle-os-modules/modules/files/files.sh
Nick Saika 17bacbe3da
fix: Fix flag ordering in set calls in scripts (#99)
The README for scripts has an incorrect use of the `set`. Where it says
to use:

	set -oue pipefail

it should be:

	set -euo pipefail

since `pipefail` is an option consumed by `set -o`.

More information: https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
2024-01-16 06:12:08 +00:00

33 lines
955 B
Bash

#!/usr/bin/env bash
# Tell build process to exit if there are any errors.
set -euo pipefail
get_yaml_array FILES '.files[]' "$1"
cd "$CONFIG_DIRECTORY/files"
if [[ ${#FILES[@]} -gt 0 ]]; then
echo "Adding files to image"
for pair in "${FILES[@]}"; do
FILE="$PWD/$(echo $pair | yq 'to_entries | .[0].key')"
DEST=$(echo $pair | yq 'to_entries | .[0].value')
if [ -d "$FILE" ]; then
if [ ! -d "$DEST" ]; then
mkdir -p "$DEST"
fi
echo "Copying $FILE to $DEST"
cp -r "$FILE"/* $DEST
elif [ -f "$FILE" ]; then
DEST_DIR=$(dirname "$DEST")
if [ ! -d "$DEST_DIR" ]; then
mkdir -p "$DEST_DIR"
fi
echo "Copying $FILE to $DEST"
cp $FILE $DEST
else
echo "File or Directory $FILE Does Not Exist in $CONFIG_DIRECTORY/files"
exit 1
fi
done
fi