MilhouseVH 733bd0eba9 scripts/unpack: avoid calling scripts/extract for each tarball pattern
Each time scripts/extract is called it sources config/options which is an
expensive operation.

We call scripts/extract 8 times for each possible tarball pattern, and for
7 of those 8 calls scripts/extract does nothing but source config/options
and then exit.

This change is more efficient, while functionally equivalent.
2017-09-20 19:05:44 +01:00

75 lines
2.1 KiB
Bash
Executable File

#!/bin/bash
################################################################################
# This file is part of OpenELEC - http://www.openelec.tv
# Copyright (C) 2009-2016 Stephan Raue (stephan@openelec.tv)
#
# OpenELEC is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# OpenELEC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with OpenELEC. If not, see <http://www.gnu.org/licenses/>.
################################################################################
. config/options $1
if [ -z "$2" ]; then
echo "usage: $0 package_name target_dir"
exit 1
fi
[ -z "$PKG_URL" -o -z "$PKG_SOURCE_NAME" ] && exit 1
[ ! -d "$SOURCES/$1" -o ! -d "$2" ] && exit 1
for pattern in .tar.gz .tar.xz .tar.bz2 .tgz .txz .tbz .7z .zip; do
if [[ $PKG_SOURCE_NAME =~ ${pattern//./\\.}$ ]]; then
f="$SOURCES/$1/$PKG_SOURCE_NAME"
if [ ! -f $f ]; then
echo "error: File $PKG_SOURCE_NAME doesn't exist in package $1 sources directory"
echo "Have you called scripts/extract before scripts/get ?"
exit 1
fi
case $PKG_SOURCE_NAME in
*.tar)
tar xf $f -C $2
;;
*.tar.bz2 | *.tbz)
tar xjf $f -C $2
;;
*.tar.gz | *.tgz)
tar xzf $f -C $2
;;
*.tar.xz | *.txz)
tar xJf $f -C $2
;;
*.7z)
mkdir -p $2/$1
7z x -o$2/$1 $f
;;
*.zip)
unzip -q $f -d $2
;;
*.diff | *.patch)
cat $f | patch -d $2 -p1
;;
*.diff.bz2 | *.patch.bz2 | patch-*.bz2)
bzcat $f | patch -d $2 -p1
;;
*.diff.gz | *.patch.gz | patch-*.gz)
zcat $f | patch -d $2 -p1
;;
*)
cp -pPR $f $2
;;
esac
break
fi
done