Make extract a separate script

This commit is contained in:
2025-04-08 11:29:46 +01:00
parent 847a2d088d
commit 30bf096e81
2 changed files with 59 additions and 61 deletions

57
scripts/extract Executable file
View File

@@ -0,0 +1,57 @@
#! /bin/bash
extract() {
if [ -f "$1" ]; then
case "$1" in
*.tar.bz2)
command -v tar >/dev/null || sudo apt install -y tar
tar xjvf "$1"
;;
*.tar.gz)
command -v tar >/dev/null || sudo apt install -y tar
tar xzvf "$1"
;;
*.bz2)
command -v bunzip2 >/dev/null || sudo apt install -y bzip2
bunzip2 "$1"
;;
*.rar)
command -v unrar >/dev/null || sudo apt install -y unrar
unrar e "$1"
;;
*.gz)
command -v gunzip >/dev/null || sudo apt install -y gzip
gunzip "$1"
;;
*.tar)
command -v tar >/dev/null || sudo apt install -y tar
tar xf "$1"
;;
*.tbz2)
command -v tar >/dev/null || sudo apt install -y tar
tar xjf "$1"
;;
*.tgz)
command -v tar >/dev/null || sudo apt install -y tar
tar xzf "$1"
;;
*.zip)
command -v unzip >/dev/null || sudo apt install -y unzip
unzip "$1"
;;
*.Z)
command -v uncompress >/dev/null || sudo apt install -y ncompress
uncompress "$1"
;;
*.7z)
command -v 7z >/dev/null || sudo apt install -y p7zip
7z x "$1"
;;
*)
echo "'$1' cannot be extracted via extract()"
;;
esac
else
echo "'$1' is not a valid file"
fi
}