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
commit 2f7f662b4a

View file

@ -25,15 +25,37 @@ get_file() {
checksum "$file" "$sum" 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() { extract() {
local file="$1" local file="$1"
local dir="$2"
mkdir -p "$dir"
echo "Extracting $file..." echo "Extracting $file..."
if [[ "$file" == *.zip ]] if [[ "$file" == *.zip ]]
then 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 ]] elif [[ "$file" == *.tar.gz ]]
then then
tar xf "$file" tar xf "$file" --strip 1 -C "$dir"
else else
echo "Unsupported file: $file" echo "Unsupported file: $file"
return 1 return 1
@ -51,7 +73,7 @@ get_dep() {
else else
echo "$dir: not found" echo "$dir: not found"
get_file "$url" "$file" "$sum" get_file "$url" "$file" "$sum"
extract "$file" extract "$file" "$dir"
fi fi
} }