extract.sh (908B)
1 #!/bin/sh 2 # TODO implement [dest_dir] functionality 3 # Currently extracts to the current directory 4 # Iterate over each arguments 5 # Treat last argument as dest folder? or use -d 6 # Allow extraction of multple archives in the order 7 test $# -lt 1 && { printf "Usage: $(basename $0) <archive>\n"; exit 1; } 8 test -f $1 || { printf "$0: $1: No such file \n"; exit 1; } 9 case $1 in 10 *.a) ar x "$1" ;; 11 *.z) 7z x "$1" ;; 12 *.rar) unrar x "$1" ;; 13 *.tar|*.tar.xz|*.tar.gz) tar -xvf "$1" ;; 14 *.tar.bz2) tar -xzvf "$1" ;; 15 *.bz2) bzip2 -d "$1" ;; 16 *.bz) bzip2 -d "$1" ;; 17 *.gz) gunzip -d "$1" ;; 18 *.tgz) tar -zxvf "$1" ;; 19 *.zip) unzip "$1" ;; 20 *.mp4) 21 audio_codec=$(ffprobe -show_streams -select_streams a "$1" | grep codec_name | cut -f2 -d "=") 22 ffmpeg -i "$1" -c:a copy $(basename $1).${audio_codec} 23 ;; 24 25 *) printf "'$1' Error. Unsupported filetype.\n" >&2 ;; 26 esac