From 2f7f662b4ae8748584ebe119b987ca391819498b Mon Sep 17 00:00:00 2001 From: Yu-Chen Lin Date: Sun, 18 Oct 2020 11:02:42 +0800 Subject: [PATCH] Make prepare-dep can specify output dir Signed-off-by: Yu-Chen Lin --- prebuilt-deps/prepare-dep | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/prebuilt-deps/prepare-dep b/prebuilt-deps/prepare-dep index f152e6cf..f155c1ff 100755 --- a/prebuilt-deps/prepare-dep +++ b/prebuilt-deps/prepare-dep @@ -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 }