Skip to content
This repository has been archived by the owner on Sep 24, 2024. It is now read-only.

Commit

Permalink
Fix file uncompression for Mac (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
dappnodedev authored Jul 23, 2024
1 parent 69802c3 commit f6d2ce4
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions charon-validator/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,26 @@ function extract_file_into_charon_dir() {
tmp_dir=$(mktemp -d)

# Extract the archive to the temporary directory
if [[ "${1}" == *.tar.gz ]]; then
tar -xzf "${1}" -C "${tmp_dir}" && echo "${INFO} Extraction to temp directory complete."
elif [[ "${1}" == *.tar.xz ]]; then
tar -xJf "${1}" -C "${tmp_dir}" && echo "${INFO} Extraction to temp directory complete."
if [[ "${1}" == *.tar.gz || "${1}" == *.tar.xz ]]; then
tar --exclude='._*' -xvf "${1}" -C "${tmp_dir}" && echo "${INFO} Extraction (.tar.gz or .tar.xz format) to temporary directory complete."
elif [[ "${1}" == *.zip ]]; then
unzip -o "${1}" -d "${tmp_dir}" && echo "${INFO} Extraction to temp directory complete."
unzip -o "${1}" -d "${tmp_dir}" && echo "${INFO} Extraction (.zip format) to temporary directory complete."
fi

# Read contents of the temp directory into an array using mapfile
mapfile -t contents < <(ls -A "${tmp_dir}")

echo "${INFO} Moving files from temporary directory to ${CHARON_ROOT_DIR}..."

if [[ ${#contents[@]} == 1 && -d "${tmp_dir}/${contents[0]}" ]]; then
echo "${INFO} Found exactly one directory in the archive: ${contents[0]}"

# If there is exactly one directory, move its contents to CHARON_ROOT_DIR
mv "${tmp_dir}/${contents[0]}"/* "${CHARON_ROOT_DIR}"
rmdir "${tmp_dir}/${contents[0]}" # Remove the now empty directory
else
echo "${INFO} Moving all files and directories from the temporary directory to ${CHARON_ROOT_DIR}"

# Move all files and directories from the temp directory directly to CHARON_ROOT_DIR
mv "${tmp_dir}"/* "${CHARON_ROOT_DIR}"
fi
Expand Down

0 comments on commit f6d2ce4

Please sign in to comment.