From 66adf1749086713a70d8a87031291e3fa02845e0 Mon Sep 17 00:00:00 2001 From: dsavvinov Date: Fri, 12 Aug 2016 18:59:17 +0300 Subject: [PATCH] Protobuf: prettified pre-build.sh. Now checking return codes of subroutines properly, exiting on errors. Returning error code properly --- proto/pre-build.sh | 107 ++++++++++++++++++++++++++++++--------------- 1 file changed, 72 insertions(+), 35 deletions(-) diff --git a/proto/pre-build.sh b/proto/pre-build.sh index 4902abd87fe..de1bcffe5d8 100755 --- a/proto/pre-build.sh +++ b/proto/pre-build.sh @@ -2,8 +2,11 @@ lprotoc="/usr/local/lib/libprotoc.so" lprotobuf="/usr/local/lib/libprotobuf.so" -ok=1 +srcdir='google_protobuf' +ok=0 missing="" +red='\033[0;31m' +nc='\033[0m' if [ ! -e "$lprotoc" ]; then ok=0 @@ -15,39 +18,73 @@ if [ ! -e "$lprotobuf" ]; then missing="$missing $lprotobuf" fi -if [ "$ok" == 0 ]; then - echo "$missing, required for building, is not found" \ -"You have to build and install latest Protobuf version from https://github.com/google/protobuf" \ -"Do you want to do it automatically? [y/n]" \ -"(Caution: this will take decent amount of time and internet traffic)" - response="n" - read response - if [ $response = "y" ]; then - echo "Creating directory for Protobuf sources" - mkdir protobuf_sources - cd protobuf_sources - - echo "Cloning repository" - git clone https://github.com/google/protobuf - cd protobuf - - echo "Resolving prerequisites to build Google Protobuf" - sudo apt-get install autoconf automake libtool curl make g++ unzip - - echo "Generating Makefiles and etc." - ./autogen.sh - ./configure - - echo "Building" - make - - echo "Installing" - sudo make install - - echo "Cleaning" - # cd ../.. - # rm -rf protobuf_sources - fi -else +if [ "$ok" == 1 ]; then echo "Prerequisites met, you can build library now via Makefile" + exit 0 fi + +echo "$missing, required for building, is not found" +echo "You have to build and install latest Protobuf version from https://github.com/google/protobuf" +echo "Do you want to do it automatically? [y/n]" +echo "(Caution: this will take decent amount of time and internet traffic)" +response="n" +read response +if [ $response = "n" ]; then + exit 1 +fi + +echo -e "${red}Creating directory for Protobuf sources${nc}" +mkdir $srcdir +if [ $? -ne 0 ]; then + echo -e "${red}Error creating directory protobuf_sources/ for cloning repository${nc}" + exit 1 +fi +cd $srcdir + +echo -e "${red}Cloning repository${nc}" +git clone https://github.com/google/protobuf +if [ $? -ne 0 ]; then + echo -e "${red}Error cloning https://github.com/google/protobuf${nc}" + exit 1 +fi + +cd protobuf + +echo -e "${red}Resolving prerequisites to build Google Protobuf${nc}" +sudo apt-get install autoconf automake libtool curl make g++ unzip +if [ $? -ne 0 ]; then + echo -e "${red}Error installing tools for building${nc}" + exit 1 +fi + +echo -e "${red}Generating Makefiles and etc.${nc}" +./autogen.sh +./configure +if [ $? -ne 0 ]; then + echo -e "${red}Error generating makefiles${nc}" + exit 1 +fi + +echo -e "${red}Building${nc}" +make +if [ $? -ne 0 ]; then + echo -e "${red}Error building protobuf via Make${nc}" + exit 1 +fi + +echo -e "${red}Installing${nc}" +sudo make install +if [ $? -ne 0 ]; then + echo -e "${red}Error installing protobuf${nc}" + exit 1 +fi + +echo -e "${red}Refreshing dynamic libraries bindings${nc}" +sudo ldconfig +if [ $? -ne 0 ]; then + echo -e "${red}Error refreshing dynamic libraries${nc}" + exit 1 +fi + +echo -e "${red}Installation finished succesfully. You can now build library using Makefile.${nc}" +exit 0