-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunpack.sh
More file actions
executable file
·41 lines (33 loc) · 808 Bytes
/
unpack.sh
File metadata and controls
executable file
·41 lines (33 loc) · 808 Bytes
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
#!/bin/bash
set -e
get_base_name() {
filename="$1"
basename=$(basename "$filename")
basename="${basename%.tar.gz}"
basename="${basename%.tgz}"
basename="${basename%.tar.bz2}"
basename="${basename%.tar.xz}"
basename="${basename%.tar.zst}"
basename="${basename%.tar.lz}"
basename="${basename%.tar}"
echo "$basename"
}
if [[ $# -ne 2 ]]; then
echo "Usage: $0 <tarball> <output_dir>"
exit 1
fi
archive="$1"
output_dir="$2"
if [[ ! -f "$archive" ]]; then
echo "File not found: $archive"
exit 1
fi
if [[ ! -d "$output_dir" ]]; then
echo "Directory not found: $output_dir"
exit 1
fi
dirname=$(get_base_name "$archive")
target="$output_dir/$dirname"
mkdir -p "$target"
echo "Unpacking '$archive' into '$target'"
tar -xf "$archive" -C "$target"