17 lines
435 B
Bash
Executable File
17 lines
435 B
Bash
Executable File
#!/bin/sh
|
|
for archive in "$@"; do
|
|
# count files in root dir
|
|
rootfiles=$(7z l -slt "${archive}" | grep -c 'Path = [^/]*$')
|
|
|
|
# add -o switch, if more than one file in root
|
|
# checks for >2, because path of the zip file itself is listed too
|
|
if [ $rootfiles -gt 2 ]; then
|
|
filename=${archive##*/}
|
|
rootname=${filename%.*}
|
|
opt="-o${rootname}"
|
|
fi
|
|
|
|
#unpack
|
|
7z x "${opt}" "${archive}"
|
|
done
|