2025-06-17 15:23:35 +07:00

43 lines
1.4 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# Функция для распаковки архивов
unpack() {
if [ $# -eq 0 ]; then
echo -e "\033[1;31mОшибка:\033[0m Укажите имя архива"
echo "Использование: unpack <архив>"
return 1
fi
if [ ! -f "$1" ]; then
echo -e "\033[1;31mОшибка:\033[0m Файл '$1' не существует"
return 1
fi
case "$1" in
*.tar.bz2|*.tbz2) tar xjf "$1" ;;
*.tar.gz|*.tgz) tar xzf "$1" ;;
*.tar.xz) tar xf "$1" ;;
*.tar) tar xf "$1" ;;
*.bz2) bunzip2 "$1" ;;
*.rar) unrar x "$1" ;;
*.gz) gunzip "$1" ;;
*.zip) unzip "$1" ;;
*.Z) uncompress "$1" ;;
*.7z) 7z x "$1" ;;
*)
echo -e "\033[1;31mОшибка:\033[0m Неподдерживаемый формат архива: '$1'"
echo -e "Поддерживаемые форматы: .tar.bz2, .tar.gz, .tar.xz, .tar, .bz2, .rar, .gz, .zip, .Z, .7z"
return 1
;;
esac
if [ $? -eq 0 ]; then
echo -e "\033[1;32mУспех:\033[0m Архив '$1' распакован"
fi
}
# Если скрипт вызван напрямую (а не через source), выполняем unpack
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
unpack "$@"
fi