scripts

Random scripts
git clone git://git.margiolis.net/scripts.git
Log | Files | Refs | README | LICENSE

extr (812B)


      1 #!/bin/sh
      2 
      3 usage()
      4 {
      5 	echo "usage: ${0##*/} [-d dir] file" 1>&2 && exit 1
      6 }
      7 
      8 while getopts "d:" arg; do
      9 case "${arg}" in
     10 	d) dir="${OPTARG}" ;;
     11 	*) usage ;;
     12 esac
     13 done
     14 shift "$(expr ${OPTIND} - 1)"
     15 
     16 archive="$(readlink -f ${1})"
     17 test -z "${archive}" && usage
     18 test -n "${dir}" && mkdir -p "${dir}" && cd "${dir}"
     19 
     20 case "${archive}" in
     21 	*.tar.bz2|*.tbz2)	tar xvjf "${archive}" ;;
     22 	*.tar.xz)		tar -xf "${archive}" ;;
     23 	*.tar.gz|*.tgz)		tar xvzf "${archive}" ;;
     24 	*.lzma)			unlzma "${archive}" ;;
     25 	*.bz2)			bunzip2 "${archive}" ;;
     26 	*.rar)			unrar x -ad "${archive}" ;;
     27 	*.gz)			gunzip "${archive}" ;;
     28 	*.tar)			tar xvf "${archive}" ;;
     29 	*.zip)			unzip "${archive}" ;;
     30 	*.Z)			uncompress "${archive}" ;;
     31 	*.7z)			7z x "${archive}" ;;
     32 	*.xz)			unxz "${archive}" ;;
     33 	*) echo "i don't know how to extract this" 1>&2 ;;
     34 esac