1- #! /bin/bash
1+ #! /usr/ bin/env bash
22
33# modified from https://github.com/foundry-rs/foundry/blob/master/foundryup/foundryup
44
55# obolup - Obol Stack Updater and Launcher
6- # Usage: obolup [update]
76
8- set -eo pipefail
7+ set -Eeuo pipefail
98
109
1110# Constants
12- OBOL_CLI_REPO=" https://github.com/obolnetwork/obol-cli"
13- KIND_VERSION=" v0.27.0"
14- OBOLUP_URL=" https://stack.obol.org/obolup"
15- STACK_NAME=" obol-stack"
16- STATUS_PORT=8080
11+ readonly OBOL_CLI_REPO=" https://github.com/obolnetwork/obol-cli"
12+ readonly KIND_VERSION=" v0.27.0"
13+ readonly OBOLUP_URL=" https://stack.obol.org/obolup"
14+ readonly STACK_NAME=" obol-stack"
15+ readonly STATUS_PORT=8080
16+
17+ # Colors for output
18+ readonly RED=' \033[0;31m'
19+ readonly GREEN=' \033[0;32m'
20+ readonly YELLOW=' \033[1;33m'
21+ readonly NC=' \033[0m' # No Color
22+
23+ # Network name to chain ID mapping
24+ declare -A -r SUPPORTED_NETWORKS=(
25+ [" hoodi" ]=" 560048"
26+ [" mainnet" ]=" 1"
27+ )
28+ # Supported sync types
29+ declare -A -r SUPPORTED_MODES=(
30+ [" light" ]=1
31+ [" full" ]=2
32+ )
33+
34+ readonly BASE_DIR=${XDG_CONFIG_HOME:- $HOME }
35+
36+
37+ tolower () {
38+ echo " $1 " | awk ' {print tolower($0)}'
39+ }
40+
41+ # Get platform + architecture
42+ readonly uname_s=$( uname -s)
43+ PLATFORM=$( tolower " ${OBOLUP_PLATFORM:- $uname_s } " )
1744ARCHITECTURE=unset
45+ EXT=" tar.gz"
46+ case $PLATFORM in
47+ linux) ;;
48+ darwin|mac* )
49+ PLATFORM=" darwin"
50+ ;;
51+ mingw* |win* )
52+ EXT=" zip"
53+ PLATFORM=" win32"
54+ ;;
55+ * )
56+ err " unsupported platform: $PLATFORM "
57+ ;;
58+ esac
59+
60+ readonly uname_m=$( uname -m)
61+ ARCHITECTURE=$( tolower " ${OBOLUP_ARCH:- $uname_m } " )
62+ if [ " ${ARCHITECTURE} " = " x86_64" ]; then
63+ # Redirect stderr to /dev/null to avoid printing errors if non Rosetta.
64+ if [ " $( sysctl -n sysctl.proc_translated 2> /dev/null) " = " 1" ]; then
65+ ARCHITECTURE=" arm64" # Rosetta.
66+ else
67+ ARCHITECTURE=" amd64" # Intel.
68+ fi
69+ elif [ " ${ARCHITECTURE} " = " arm64" ] || [ " ${ARCHITECTURE} " = " aarch64" ] ; then
70+ ARCHITECTURE=" arm64" # Arm.
71+ else
72+ ARCHITECTURE=" amd64" # Amd.
73+ fi
1874
19- BASE_DIR=${XDG_CONFIG_HOME:- $HOME }
2075
2176# Run a command that should never fail. If the command fails execution
2277# will immediately terminate with an error showing the failing command.
2378ensure () {
2479 if ! " $@ " ; then err " command failed: $* " ; fi
2580}
2681
27- tolower () {
28- echo " $1 " | awk ' {print tolower($0)}'
29- }
30-
3182# Downloads $1 into $2 or stdout
3283download () {
3384 if [ -n " $2 " ]; then
@@ -47,12 +98,35 @@ download() {
4798 fi
4899}
49100
101+ # Validate the network
102+ validate_network () {
103+ declare -n __network=" $1 "
50104
51- # Colors for output
52- RED=' \033[0;31m'
53- GREEN=' \033[0;32m'
54- YELLOW=' \033[1;33m'
55- NC=' \033[0m' # No Color
105+ if [[ -z " $__network " ]]; then
106+ log_info " Network name is empty. Defaulting to mainnet"
107+ __network=" mainnet"
108+ fi
109+
110+ if [[ -z " ${SUPPORTED_NETWORKS[$__network]:- } " ]]; then
111+ log_warn " Unrecognised network name: \" ${__network} \" .\n"
112+ help 1
113+ fi
114+ }
115+
116+ # Validate the sync mode
117+ validate_sync_mode () {
118+ declare -n __mode=" $1 "
119+
120+ if [[ -z " $__mode " ]]; then
121+ log_info " Sync mode is empty. Defaulting to light node sync mode."
122+ __mode=" light"
123+ fi
124+
125+ if [[ -z " ${SUPPORTED_MODES[$__mode]:- } " ]]; then
126+ log_warn " Unrecognised sync mode: \" ${__mode} \" .\n"
127+ help 1
128+ fi
129+ }
56130
57131# Log functions
58132log_info () { echo -e " ${GREEN} [INFO]${NC} $1 " ; }
@@ -64,39 +138,6 @@ command_exists() {
64138 command -v " $1 " > /dev/null 2>&1
65139}
66140
67- # Get platform + architecture
68- uname_s=$( uname -s)
69- PLATFORM=$( tolower " ${OBOLUP_PLATFORM:- $uname_s } " )
70- EXT=" tar.gz"
71- case $PLATFORM in
72- linux) ;;
73- darwin|mac* )
74- PLATFORM=" darwin"
75- ;;
76- mingw* |win* )
77- EXT=" zip"
78- PLATFORM=" win32"
79- ;;
80- * )
81- err " unsupported platform: $PLATFORM "
82- ;;
83- esac
84-
85- uname_m=$( uname -m)
86- ARCHITECTURE=$( tolower " ${OBOLUP_ARCH:- $uname_m } " )
87- if [ " ${ARCHITECTURE} " = " x86_64" ]; then
88- # Redirect stderr to /dev/null to avoid printing errors if non Rosetta.
89- if [ " $( sysctl -n sysctl.proc_translated 2> /dev/null) " = " 1" ]; then
90- ARCHITECTURE=" arm64" # Rosetta.
91- else
92- ARCHITECTURE=" amd64" # Intel.
93- fi
94- elif [ " ${ARCHITECTURE} " = " arm64" ] || [ " ${ARCHITECTURE} " = " aarch64" ] ; then
95- ARCHITECTURE=" arm64" # Arm.
96- else
97- ARCHITECTURE=" amd64" # Amd.
98- fi
99-
100141# Ensure Docker is running
101142start_docker () {
102143 log_info " Checking Docker..."
@@ -259,6 +300,9 @@ open_obol_agent_interface() {
259300
260301# Launch or update the Obol Stack
261302launch_stack () {
303+ declare -n __network=" $1 "
304+ declare -n __mode=" $2 "
305+
262306 log_info " Launching core Obol Stack services..."
263307 if ! kind get clusters | grep -q " $STACK_NAME " ; then
264308 log_info " Creating Kind cluster for Obol Stack..."
282326
283327 # Add the appropriate Helm repos (ethpandaops, Obol, kubernetes-dashboard)
284328 log_info " Adding default Obol Stack app stores..."
285- ensure helm repo add ethereum https://ethpandaops.github.io/ethereum-helm-charts
286- ensure helm repo add obol https://obolnetwork.github.io/helm-charts/
329+ ensure helm repo add ethereum https://ethpandaops.github.io/ethereum-helm-charts --force-update
330+ ensure helm repo add obol https://obolnetwork.github.io/helm-charts/ --force-update
287331 # ensure helm repo add kubernetes-dashboard https://kubernetes.github.io/dashboard/
288332
289333 # Update helm repos
@@ -292,12 +336,17 @@ EOF
292336 # Deploy a Helm Release named "kubernetes-dashboard" using the kubernetes-dashboard chart
293337 # helm upgrade --install kubernetes-dashboard kubernetes-dashboard/kubernetes-dashboard --create-namespace --namespace kubernetes-dashboard
294338
295- log_info " Configuring the Obol Stack Ethereum client..."
296- ensure helm upgrade --namespace l1 --create-namespace --hide-notes --install l1-light-client obol/helios
297- ensure helm upgrade --namespace l1 --create-namespace --install l1-rpc ethereum/erpc --values ../values/erpc.yaml
339+ log_info " Installing the Obol Stack Ethereum light client configured for $__network ..."
340+ ensure helm upgrade --namespace l1 --create-namespace --hide-notes --force --install l1-light-client obol/helios -f ../values/$__network /helios.yaml
341+
342+ # If mode="full", also sync an Erigon full node
343+ if [[" $__mode " = " full" ]]; then
344+ log_info " Installing an Ethereum Erigon full node client..."
345+ ensure helm upgrade --namespace l1 --create-namespace --install l1-erigon ethereum/erigon -f ../values/$__network /erigon.yaml
346+ fi
298347
299- # # Ensure Erigon later
300- # ensure helm upgrade --namespace l1 --create-namespace --install l1-erigon ethereum/erigon --values ../values/erigon .yaml
348+ log_info " Installing the Obol Stack Ethereum eRPC load balancer... "
349+ ensure helm upgrade --namespace l1 --create-namespace --force -- install l1-rpc ethereum/erpc -f ../values/erpc .yaml
301350
302351 # Todo(Oisin): EthpandaOps/ethereum-node not flexible enough just yet, installing clients directly with their dedicated chart
303352 # ensure helm upgrade --namespace l1 --create-namespace --install --set erigon.enabled=true l1-erigon ethereum/ethereum-node
@@ -321,28 +370,61 @@ EOF
321370
322371# Main logic
323372main () {
373+ # Instantiate
374+ local network=" "
375+ local mode=" "
376+ declare -i clean=0
377+
378+ # Parse the CLI flags
379+ while [[ $# -gt 0 ]]; do
380+ case " $1 " in
381+ --help) help 0 ;;
382+ --network)
383+ network=" $2 "
384+ shift 2
385+ ;;
386+ --mode)
387+ mode=" $2 "
388+ shift 2
389+ ;;
390+ --clean)
391+ clean=1
392+ shift 1
393+ ;;
394+ * )
395+ echo " Unknown option: $1 " >&2
396+ help
397+ ;;
398+ esac
399+ done
400+
324401 banner
402+
403+ # Parse network and sync mode
404+ validate_network network
405+ validate_sync_mode mode
406+
325407 log_info " Starting obolup..."
326408 log_info " Detected platform: $PLATFORM "
327409 log_info " Detected architecture: $ARCHITECTURE "
410+ log_info " Selected network: $network "
411+ log_info " Selected node type: $mode "
328412 # start_docker
329413 start_docker
330414 install_kubectl
331415 install_kind
332416 install_helm
333417 # install_obol_cli
334418 # check_obolup_update
335- if [[ " $1 " == " clean " ]]; then
419+ if [[ " $clean " -ne 0 ]]; then
336420 log_info " Clean command specified, deleting and recreating Obol Stack resources..."
337421 kind delete cluster --name " $STACK_NAME "
338422 fi
339423
340- launch_stack
424+ launch_stack network mode
341425
342426 log_info " Obol Stack is up and running!"
343-
344- # Open the obol-agent interface
345- open_obol_agent_interface
427+ exit 0
346428}
347429
348430
@@ -367,5 +449,19 @@ Docs : https://docs.obol.org/
367449'
368450}
369451
452+ # Displays help text
453+ help () {
454+ cat << EOF
455+ Usage: $0 [--help] [--network <network>] [--mode <mode>] [--clean]
456+
457+ Options:
458+ --help Display this help message
459+ --network <network> Specify the network (default: mainnet) [mainnet, hoodi]
460+ --mode <mode> Specify the type of sync mode (default: light) [light, full]
461+ --clean Deletes and recreates the Obol Stack
462+ EOF
463+ exit " ${1:- 1} "
464+ }
465+
370466# Run main
371467main " $@ "
0 commit comments