Created
February 21, 2024 00:07
-
-
Save shmerl/0f2fb474ce99c204d51ee3ad5c26224a to your computer and use it in GitHub Desktop.
For convenient creation of zstd archives
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
source="$1" | |
keep_dir=${keep_dir:-false} | |
tar_wrap=${tar_wrap:-true} # for wrapping a single file | |
if [[ "$source" == "" ]]; then | |
echo "Error: No source provided!" | |
exit 1 | |
fi | |
if ! [[ -e "$source" ]]; then | |
echo "Error: ${source} doesn't exist!" | |
exit 2 | |
fi | |
if [[ "$2" == "" ]]; then | |
target=$(basename "$source") | |
else | |
target="$2" | |
fi | |
if [[ -d "$source" ]] && $keep_dir || ! [[ -d "$source" ]] && $tar_wrap; then | |
# keep outer directory in the archive or wrap a single file in tar | |
tar --create --verbose --use-compress-program "zstd --threads=$(nproc) -19 --verbose" --file "${target}.tar.zst" "${source}" | |
elif [[ -d "$source" ]]; then | |
# archive inside the directory without keeping it wrapping the files | |
tar --create --verbose --use-compress-program="zstd --threads=$(nproc) -19 --verbose" --file "${target}.tar.zst" --directory "${source}" . | |
else | |
zstd --threads=$(nproc) -19 "$source" -o "${target}.zst" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment