Make prepare-dep can specify output dir

Signed-off-by: Yu-Chen Lin <npes87184@gmail.com>
This commit is contained in:
Yu-Chen Lin 2020-10-18 11:02:42 +08:00
parent 83082406d3
commit 2f7f662b4a

View file

@ -25,15 +25,37 @@ get_file() {
checksum "$file" "$sum"
}
get_first_layer_dir_name() {
local file="$1"
if [[ "$file" == *.zip ]]
then
echo `unzip -Z -1 "$file" | head -n 1 | cut -d/ -f1`
elif [[ "$file" == *.tar.gz ]]
then
echo `tar tf "$file" | head -n 1 | cut -d/ -f1`
else
echo "Unsupported file: $file"
return 1
fi
}
extract() {
local file="$1"
local dir="$2"
mkdir -p "$dir"
echo "Extracting $file..."
if [[ "$file" == *.zip ]]
then
unzip -q "$file"
local folder_in_file=`get_first_layer_dir_name "$file"`
ln -s . "$dir"/"$folder_in_file"
unzip -q "$file" -d "$dir"
rm "$dir"/"$folder_in_file"
elif [[ "$file" == *.tar.gz ]]
then
tar xf "$file"
tar xf "$file" --strip 1 -C "$dir"
else
echo "Unsupported file: $file"
return 1
@ -51,7 +73,7 @@ get_dep() {
else
echo "$dir: not found"
get_file "$url" "$file" "$sum"
extract "$file"
extract "$file" "$dir"
fi
}