diff --git a/Makefile b/Makefile index 1faf3b7..5a0a66b 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,47 @@ DATABASE_URL = "sqlite:farcaster.db" MIGRATIONS_DIR = "./lib/storage/migrations" +define install_package + if ! command -v $(1) >/dev/null 2>&1; then \ + echo "installing $(1)..."; \ + $(2); \ + fi +endef + +define install_rust + if ! command -v rustc >/dev/null 2>&1; then \ + echo "installing rust..."; \ + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y; \ + fi +endef + +define install_protobuf + if ! command -v protoc >/dev/null 2>&1; then \ + echo "installing protobufs compiler..."; \ + $(1); \ + fi +endef + +define install_prerequisites + case $$OSTYPE in \ + darwin*) \ + echo "detected macos"; \ + $(call install_package,brew,/bin/bash -c "$$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"); \ + $(call install_rust); \ + $(call install_protobuf,brew install protobuf); \ + ;; \ + linux*) \ + echo "detected linux"; \ + $(call install_rust); \ + $(call install_protobuf,sudo apt update && sudo apt install -y protobuf-compiler); \ + ;; \ + *) \ + echo "unsupported operating system"; \ + exit 1; \ + ;; \ + esac +endef + db-create: DATABASE_URL=$(DATABASE_URL) sqlx db create @@ -10,4 +51,12 @@ db-migrate: db-query-prepare: DATABASE_URL=$(DATABASE_URL) cargo sqlx prepare --workspace -.PHONY: db-create db-migrate db-query-prepare \ No newline at end of file +install: + @$(call install_prerequisites) + @if ! command -v sqlx >/dev/null 2>&1; then \ + echo "installing sqlx cli..."; \ + . $$HOME/.cargo/env && cargo install sqlx-cli; \ + fi + @echo "all prerequisites installed successfully!" + +.PHONY: db-create db-migrate db-query-prepare install diff --git a/README.md b/README.md index dd8cf4e..ca808a1 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ If you are new to Farcaster Hubs and/or Teleport - here's a quick video that doe Note that the codebase will outpace the video, and things mentioned `TODO` in the video might have been done now. - +[![Video](https://img.youtube.com/vi/YXu2DGMhIao/0.jpg)](https://www.youtube.com/watch?v=YXu2DGMhIao) ## Rough Features @@ -32,6 +32,12 @@ A lot is still left to do: ## Prerequisites +Run the following command to install all the prerequisites for you automatically and if it fails for any reason then simply manually install them. + +``` bash +make install +``` + - Rust - Protobufs Compiler (`brew install protobuf` or `apt install -y protobuf-compiler`) - SQLx CLI (`cargo install sqlx-cli`) @@ -42,7 +48,16 @@ Up until recently, there was a Protobuf incompatibility issue with using `prost` In a recent update the Protobuf schema was updated to add a new field that allows us to get by that issue by serializing the message differently. That hasn't been implemented yet in Teleport but technically we don't need to maintain a patched version of `prost` anymore. -## Database + +## Setup the Hub + +Copy the example .env file using the following command and then place both your farcaster private key and optimism l2 key. + +``` bash +cp env.example .env +``` + +### Setup the Database 1. create the database @@ -56,8 +71,9 @@ make db-create make db-migrate ``` -## Start the Hub + +### Start the hub ```bash -FARCASTER_PRIV_KEY= OPTIMISM_L2_RPC_URL= cargo run +cargo run ```