diff --git a/Makefile b/Makefile index 17bcf90..882ebac 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,10 @@ SHELL=/bin/bash +autoinstall: + ./install_helper.sh + + build: submodules resh-collect resh-daemon diff --git a/install.sh b/install.sh deleted file mode 100755 index 458df80..0000000 --- a/install.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env bash - -if ! go version &>/dev/null; then - echo "Please install Golang and rerun this script" - exit 1 -fi - -go_version=$(go version | cut -d' ' -f3) -go_version_major=$(echo "${go_version:2}" | cut -d'.' -f1) -go_version_minor=$(echo "${go_version:2}" | cut -d'.' -f2) - -# install_dep.sh installs to /tmp/gopath/bin -# add it to path just in case -PATH=/tmp/gopath/bin:$PATH - -if [ "$go_version_major" -gt 1 ]; then - # good to go - future proof ;) - echo "Building & installing ..." - make install -elif [ "$go_version_major" -eq 1 ] && [ "$go_version_minor" -ge 11 ]; then - # good to go - we have go modules - echo "Building & installing ..." - make install -elif dep version &>/dev/null; then - if ! dep init; then - echo "\`dep init\` failed - bootstraping GOPATH ..." - export GOPATH=$(mktemp /tmp/gopath-XXX) - project_path=$GOPATH/src/github.com/curusarn/resh - mkdir -p "$project_path" - cp -rf . "$project_path" - cd "$project_path" - if ! dep init; then - echo "Unexpected ERROR while running \`dep init\`!" - echo "Try running \`make install\`" - exit 3 - fi - echo "Succesfuly bootstraped GOPATH" - fi - echo "Building & installing ..." - make install -else - echo "Please update your Golang to version >= 1.11 OR install dep and rerun this script" - echo "If you have trouble installing dep you can run \`./install_dep.sh\` in this directory" - exit 2 -fi diff --git a/install_dep.sh b/install_dep.sh deleted file mode 100755 index 1fe9ed7..0000000 --- a/install_dep.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -export GOPATH=/tmp/gopath -mkdir $GOPATH/bin -curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh diff --git a/install_helper.sh b/install_helper.sh new file mode 100755 index 0000000..da28c2c --- /dev/null +++ b/install_helper.sh @@ -0,0 +1,83 @@ +#!/usr/bin/env bash + +if ! go version &>/dev/null; then + echo "Please INSTALL GOLANG and run this again" + exit 1 +fi + +go_version=$(go version | cut -d' ' -f3) +go_version_major=$(echo "${go_version:2}" | cut -d'.' -f1) +go_version_minor=$(echo "${go_version:2}" | cut -d'.' -f2) + +if [ "$go_version_major" -gt 1 ]; then + # good to go - future proof ;) + echo "Building & installing ..." + make install +elif [ "$go_version_major" -eq 1 ] && [ "$go_version_minor" -ge 11 ]; then + # good to go - we have go modules + echo "Building & installing ..." + make install +else + echo + echo "===========================================================================" + echo "Your Golang version is older than 1.11 - we can't use go modules for build!" + echo "I will try to build the project using dep. (I will let you review each step.)" + echo "Continue? (Any key to continue / Ctrl+C to cancel)" + read x + + take_care_of_gopath=0 + if [ -z "${GOPATH+x}" ]; then + echo + echo "===========================================================================" + echo "GOPATH env variable is unset!" + echo "I will take care of GOPATH. (I will create tmp GOPATH.)" + echo "Continue? (Any key to continue / Ctrl+C to cancel)" + read x + + GOPATH=$(mktemp -d /tmp/gopath-XXX) \ + && mkdir "$GOPATH/bin" \ + && echo "Created tmp GOPATH: $GOPATH" + export GOPATH + take_care_of_gopath=1 + fi + + echo "GOPATH=$GOPATH" + PATH=$GOPATH/bin:$PATH + + if ! dep version &>/dev/null; then + echo + echo "===========================================================================" + echo "It appears that you don't have dep installed!" + echo "I will install dep. (I will install it from GitHub.)" + echo "Continue? (Any key to continue / Ctrl+C to cancel)" + read x + + curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh + [ $? -eq 0 ] && echo "Installed dep." + fi + + project_path=$GOPATH/src/github.com/curusarn/resh + mkdir -p "$project_path" &>/dev/null + if [ "$project_path" != "$PWD" ]; then + if [ "$take_care_of_gopath" -eq 0 ]; then + echo + echo "===========================================================================" + echo "It seems that current directory is not in the GOPATH!" + echo "I will copy the project to appropriate GOPATH directory." + echo "Continue? (Any key to continue / Ctrl+C to cancel)" + read x + fi + cp -rf ./* "$project_path" && echo "Copied files to $project_path" + cd "$project_path" + fi + + echo "Running \`dep ensure\` ..." + if ! dep ensure; then + echo "Unexpected ERROR while running \`dep ensure\`!" + exit 2 + fi + echo + echo "===========================================================================" + echo "Building & installing ..." + make install +fi