~dricottone/my-utils

my-utils/archives/untar -rwxr-xr-x 1.6 KiB
ef6d4cd1Dominic Ricottone Incomplete work on hardware/media utils 4 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash

name="untar"
version="1.2"
help_message=$(/usr/bin/cat <<-EOF
	Unarchive utility
	Usage: untar TARGET [..] [OPTIONS]
	Options:
	 -h, --help                  print this message and exit
	 -d DIR, --to-directory DIR  unarchive to a directory
	 -p PASS, --passphrase PASS  passphrase for decryption
	 -q, --quiet                 suppress error messages
	 -v, --version               print version number and exit
EOF
)

source /usr/local/lib/mylib.bash
source /usr/local/lib/unarchive.bash

quiet=0
passphrase=""
positional=()
to_directory=""
verbose=0
while [[ $# -gt 0 ]]; do
  case $1 in

  -d|--to-directory)
    debug_msg "Setting to_directory option to '${2}' (was ${to_directory})"
    to_directory="$2"
    shift; shift
    ;;

  -h|--help)
    help_msg
    shift
    ;;

  -q|--quiet)
    debug_msg "Setting quiet option to 1 (was ${quiet})"
    quiet=1
    shift
    ;;

  -p|--passphrase)
    debug_msg "Setting passphrase option to '${2}' (was ${passphrase})"
    passphrase="$2"
    shift; shift
    ;;

  -v|--verbose)
    debug_msg "Setting verbose option to 1 (was ${verbose})"
    verbose=1
    shift
    ;;

  -V|--version)
    version_msg
    ;;

  *)
    debug_msg "Argument '${1}' added to positional array"
    positional+=("$1")
    shift
    ;;
  esac
done

code=0
for archive_fn in "${positional[@]}"; do
  archive_action="$(archive_extension "$archive_fn" | tee >(>&2 /usr/bin/head -n -1) | /usr/bin/tail -n 1)"
  if ! unarchive --archive=$archive_action "$archive_fn" ${passphrase:+--passphrase "$passphrase"} ${to_directory:+--directory "$to_directory"}; then
    code=1
  fi
done

exit "$code"