prepare.sh: fix directory handling

Allow spaces in path and fail early if `cd` target doesn't exist.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2021-11-12 11:47:56 +03:00 committed by Alex Vanin
parent 133cd011f0
commit 9798b03ba2

View file

@ -2,38 +2,38 @@
prefix=v2 prefix=v2
if [ -z "$1" ]; then if [ -z "$1" ]; then
echo "usage: ./prepare.sh path/to/neofs-api" echo "usage: ./prepare.sh path/to/neofs-api"
exit 1 exit 1
fi fi
API_GO_PATH=$(pwd) API_GO_PATH=$(pwd)
API_PATH=$1 API_PATH=$1
mkdir $API_GO_PATH/$prefix 2>/dev/null mkdir "$API_GO_PATH/$prefix" 2>/dev/null
# MOVE FILES FROM API REPO # MOVE FILES FROM API REPO
cd $API_PATH cd "$API_PATH" || exit 1
ARGS=$(find ./ -name '*.proto' -not -path './vendor/*') ARGS=$(find ./ -name '*.proto' -not -path './vendor/*')
for file in $ARGS; do for file in $ARGS; do
dir=$(dirname $file) dir=$(dirname "$file")
mkdir -p $API_GO_PATH/$prefix/$dir/grpc mkdir -p "$API_GO_PATH/$prefix/$dir/grpc"
cp -r $dir/* $API_GO_PATH/$prefix/$dir/grpc cp -r "$dir"/* "$API_GO_PATH/$prefix/$dir/grpc"
done done
# MODIFY FILES # MODIFY FILES
cd $API_GO_PATH/$prefix cd "$API_GO_PATH/$prefix" || exit 1
ARGS2=$(find ./ -name '*.proto') ARGS2=$(find ./ -name '*.proto')
for file in $ARGS2; do for file in $ARGS2; do
echo $file echo "$file"
sed -i "s/import\ \"\(.*\)\/\(.*\)\.proto\";/import\ \"$prefix\/\1\/grpc\/\2\.proto\";/" $file sed -i "s/import\ \"\(.*\)\/\(.*\)\.proto\";/import\ \"$prefix\/\1\/grpc\/\2\.proto\";/" $file
done done
cd $API_GO_PATH cd "$API_GO_PATH" || exit 1
# COMPILE # COMPILE
make protoc make protoc
# REMOVE PROTO DEFINITIONS # REMOVE PROTO DEFINITIONS
ARGS=$(find ./$prefix -name '*.proto' -not -path './vendor/*') ARGS=$(find ./$prefix -name '*.proto' -not -path './vendor/*')
for file in $ARGS; do for file in $ARGS; do
rm $file rm "$file"
done done