Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Feature/automate install script #667

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ To run the bot in simulation mode, try this command:

_Note for Windows Users: You should use a [Bash Shell][bash] to follow the steps below. This will give you a UNIX environment in which to run your commands and will enable the `./scripts/build.sh` bash script to work correctly._

To compile Kelp from source:
_Note for MacOS Users: Running [install-macos.sh][install-macos-script] should automate the steps below. (including cloning the Kelp repo to the correct Go folder) Remember, manual installation of PostgreSQL and Docker are additionally required._
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just noticed that your script does cloning of the repo too -- I remember we had discussed this last time and how we can take advantage of that. that's super cool.

Can you add to your note here that for MacOS you don't need to clone the directory but can download the automated install script from here and that it will also clone the GitHub repo in the correct location -- and link to the script they should run.


## Manual Installation Steps
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a section called "Automated Install for MacOS" above this section on "Manual Installation Steps"?
Then you can include the text you have in the note above as part of that section. That will give more importance to your automated script.


1. [Download][golang-download] and [setup][golang-setup] Golang _v1.13 or later_.
* Confirm that `$GOPATH` is set, and that `GOBIN=$GOPATH/bin`
Expand All @@ -131,7 +133,9 @@ To compile Kelp from source:
* `./scripts/build.sh`
8. Confirm one new binary file exists with version information.
* `./bin/kelp version`
9. Set up CCXT to use an expanded set of priceFeeds and orderbooks (see the [Using CCXT](#using-ccxt) section for details)
9. Run the GUI
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's swap step 9 and 10. we should run ccxt-rest before we run the GUI

* `./bin/kelp server`
10. Set up CCXT to use an expanded set of priceFeeds and orderbooks (see the [Using CCXT](#using-ccxt) section for details)
* `sudo docker run -p 3000:3000 -d franzsee/ccxt-rest:v0.0.4`

## Running Kelp
Expand Down Expand Up @@ -416,3 +420,4 @@ See the [Code of Conduct](CODE_OF_CONDUCT.md).
[github-bug-report]: https://github.com/stellar/kelp/issues/new?template=bug_report.md
[github-feature-request]: https://github.com/stellar/kelp/issues/new?template=feature_request.md
[github-new-issue]: https://github.com/stellar/kelp/issues/new
[install-macos-script]:https://github.com/stellar/kelp/blob/master/scripts/install-macos.sh
268 changes: 268 additions & 0 deletions scripts/install-macos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,268 @@
#!/bin/bash
# shellcheck disable=SC2016
set -e

# Set this machine's dependencies status(es) with the OK flag
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add to this comment that this variable is what we use as the return value from functions. we do so by updating the value of the OK variable before we return from the function and the calling code can read the OK variable.

OK=true;

# Dependency test functions begin here

function isNode() {
if node -v; then
OK=true;
else
OK=false;
fi
}

function isYarn() {
if yarn --version; then
OK=true;
else
OK=false;
fi
}

function isGit() {
if git --version; then
OK=true;
else
OK=false;
fi
}

function isGo() {
if go version; then
OK=true;
else
OK=false;
fi
}

function isGlide() {
if glide --version; then
OK=true;
else
OK=false;
fi
}

# Installation functions begin here

function installGo() {
echo 'Installing Golang on your machine.'
# Go install script based on https://github.com/canha/golang-tools-install-script
VERSION="1.15.7"

[ -z "$GOROOT" ] && GOROOT="$HOME/go/go-install-do-not-delete"
[ -z "$GOPATH" ] && GOPATH="$HOME/go"

OS="$(uname -s)"
ARCH="$(uname -m)"

case $OS in
"Linux")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this run on Linux too?

case $ARCH in
"x86_64")
ARCH=amd64\
;;
"aarch64")
ARCH=arm64
;;
"armv6" | "armv7l")
ARCH=armv6l
;;
"armv8")
ARCH=arm64
;;
.*386.*)
ARCH=386
;;
esac
PLATFORM="linux-$ARCH"
;;
"Darwin")
PLATFORM="darwin-amd64"
;;
esac

if [ -z "$PLATFORM" ]; then
echo "Your operating system is not supported by the script."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add the name of the OS that is unsupported?

echo "Your operating system '$OS' is not supported by the script."

exit 1
fi

if [ '/bin/bash' == `which bash` ]; then
shell_profile="$HOME/.bashrc"
echo "bash is installed"
else
echo "Kelp requires bash"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should exit from there if the user does not have bash. a simple exit 2 should work (keeping in mind that we're using different exit codes for different errors)

fi

{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can check if GOROOT is defined in the bashrc file before we do this -- so it doesn't repeat it in the bashrc file.

we can achieve this by doing a grep for "export GOROOT" on the $shell_profile and seeing if it retuned any result. you may need to do something like this to check that:

if [ `grep "export GOROOT" $shell_profile | wc -l` -eq 0 ]; # if equals 0 then we should append

we can reuse the condition check for -d "$GOROOT" that you already have below this append statement

echo '# GoLang'
echo "export GOROOT=${GOROOT}"
echo 'export PATH=$GOROOT/bin:$PATH'
echo "export GOPATH=$GOPATH"
echo 'export PATH=$GOPATH:$PATH'
} >> "$shell_profile"

if [ -d "$GOROOT" ]; then
echo "The Go install directory ($GOROOT) already exists."
fi

PACKAGE_NAME="go$VERSION.$PLATFORM.tar.gz"
TEMP_DIRECTORY=$(mktemp -d)

echo "Downloading $PACKAGE_NAME ..."
if hash wget 2>/dev/null; then
wget https://storage.googleapis.com/golang/$PACKAGE_NAME -O "$TEMP_DIRECTORY/go.tar.gz"
else
curl -o "$TEMP_DIRECTORY/go.tar.gz" https://storage.googleapis.com/golang/$PACKAGE_NAME
fi

if [ $? -ne 0 ]; then
echo "Download failed! Exiting."
exit 1
fi

echo "Extracting File..."

# sudo chown -R $USER: $HOME # https://github.com/golang/go/issues/27187
mkdir -p "$GOROOT"

tar -C "$GOROOT" --strip-components=1 -xzf "$TEMP_DIRECTORY/go.tar.gz"

# GOROOT=${GOROOT}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we dont need this commented out code then we can remove it

# PATH=$GOROOT/bin:$PATH
# GOPATH=$GOPATH
# PATH=$GOPATH:$PATH

mkdir -p "${GOPATH}/"{src,pkg,bin}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is pretty cool, didn't know you could do this!! 💯

echo -e "\nGo $VERSION was installed into $GOROOT.\nMake sure to relogin into your shell or run:"
echo -e "\n\ restart script to update your environment variables."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need them to restart the script to update the environment vars?

we can just do source ~/.bashrc to execute the .bashrc file instead

echo "Tip: Opening a new terminal window usually just works. :)"
rm -f "$TEMP_DIRECTORY/go.tar.gz"
}

# Once we have Golang; finish the install processes inside the development directory to avoid errors (Glide)
function cloneIntoDir() {
echo "Setting up Kelp folders in the Golang working directory"

# check github.com/stellar/kelp
if [ -d "$GOPATH/github.com/stellar/kelp" ]; then
echo "Kelp dir exists, no need to clone."
else
# pwd
mkdir -p $GOPATH/github.com/stellar/kelp
echo "Cloning Kelp into $GOPATH/src/github.com/stellar/kelp"
git clone https://github.com/stellar/kelp.git $GOPATH/src/github.com/stellar/kelp

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that /src needs to be removed since in the line 156 is not included in the path.

fi

cd $GOPATH/src/github.com/stellar/kelp
}

# After Golang install Glide
function installGlide() {
echo "Installing Glide."
if curl --version; then
curl https://glide.sh/get | sh
elif wget --version; then
wget https://glide.sh/get | sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this won't work because glide.sh doesn't work anymore. we will need to find an alternative way to install glide, maybe using homebrew?

else
echo "curl and wget are not available, install glide manually https://github.com/Masterminds/glide"
exit
fi

glide install
}

# After Glide install Astilectron
function installAstilectron() {
go get -u github.com/asticode/go-astilectron-bundler/...
go install github.com/asticode/go-astilectron-bundler/astilectron-bundler
}

function postGoInstall() {
cloneIntoDir
isGlide
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to invoke installGlide here if isGlide is false?

installAstilectron

checkDeps
echo "Remember, PostgreSQL must be running to store data."
echo "Remember, Docker and CCXT must be configured for the expanded set of priceFeeds and orderbooks."
echo "Run everything related to Kelp in BASH shell only."
echo "All dependencies successfully installed. Run build script from $GOPATH/src/github.com/stellar/kelp/scripts/build.sh"
}

# Utility function for checking dependency statuses
function checkDeps(){
isNode
if [ $OK ]; then
echo "Node `node -v` is installed"
else
echo "Node is not installed"
fi

isYarn
if [ $OK ]; then
echo "Yarn `yarn -v` is installed"
else
echo "Yarn is not installed"
fi

isGit
if [ $OK ]; then
echo "`git version` is installed"
else
echo "Git is not installed"
fi

isGo
if $OK; then
echo "`go version` is installed"
else
echo "Goland is not installed"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should say Golang instead of Goland -- Goland is a Go-specific IDE so this can be confusing

fi
}


#**********************
# Execute the functions
#**********************
cd
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a comment here why we are doing this cd -- IIRC it was to get to a deterministic starting working directory


isNode
if [ $OK ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can call checkDeps here. so it executes all of these checks and we don't need this duplicate code.
then we can reuse the $OK variable and if it is false we can simply to an exit 1.

Example:

#checkDeps will set the OK variable to false if at least 1 dependency is missing
checkDeps
if [ $OK ]; then
    # do nothing
else
    exit 1
fi

Since we don't want to exit in the case where Golang does not exist, we can inline the go check logic from the checkDeps function into postGoInstall() right after we call checkDeps (line 190)

echo "Node is installed on your machine."
else
echo "Node is not installed on your machine!"
exit 1
fi

isYarn
if [ $OK ]; then
echo "Yarn is installed on your machine."
else
echo "Yarn is not installed on your machine!"
exit 1
fi

isGit
if [ $OK ]; then
echo "Git is installed on your machine."
else
echo "Git is not installed on your machine!"
exit 1
fi

isGo
if $OK; then
echo "true for some reason"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this echo statement seems confusing. we don't need to echo anything here since we echo the go version below.

else
installGo
echo "Finished installing Golang, now sourcing from .bashrc"
source $HOME/.bashrc
fi

echo "Go version = $((go version))"
postGoInstall