modern_lisp-machine/misc/scripts/decompress_7z.sh

43 lines
1.2 KiB
Bash
Raw Normal View History

2024-06-01 05:00:40 +00:00
EXEC_SHELL_PATH=$(command -v bash)
2024-03-02 21:22:03 +00:00
2024-06-01 05:00:40 +00:00
# Ensure that 7z and unrar are installed
if ! command -v 7z >/dev/null 2>&1 || ! command -v unrar >/dev/null 2>&1; then
echo "Error: 7z or unrar not found. Please install 7z and unrar before running this script."
2024-03-02 21:22:03 +00:00
exit 1
fi
# Function to create directory with Unicode compatibility and strip file extension
create_directory() {
2024-06-01 05:00:40 +00:00
directory_name=$(basename "$1" | sed -E 's/\.(7z|zip|rar)$//' | iconv -t utf-8)
2024-03-02 21:22:03 +00:00
mkdir -p "$directory_name"
}
2024-06-01 05:00:40 +00:00
# Function to extract 7z and zip files
extract_7z_zip() {
7z x "$1" -o"$PWD/$directory_name"
}
# Function to extract rar files
extract_rar() {
unrar x "$1" "$PWD/$directory_name"
}
2024-03-02 21:22:03 +00:00
# Loop through each compressed file in the current folder
2024-06-01 05:00:40 +00:00
for compressed_file in *.7z *.zip *.rar; do
2024-03-02 21:22:03 +00:00
# Create a directory for the compressed file
create_directory "$compressed_file"
2024-06-01 05:00:40 +00:00
# Determine which extraction function to call based on file extension
case "$compressed_file" in
*.7z | *.zip)
extract_7z_zip "$compressed_file"
;;
*.rar)
extract_rar "$compressed_file"
;;
esac
2024-03-02 21:22:03 +00:00
done
echo "Extraction completed successfully."