-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtutorial.sh
More file actions
executable file
·125 lines (106 loc) · 4.57 KB
/
Copy pathtutorial.sh
File metadata and controls
executable file
·125 lines (106 loc) · 4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env bash
set -euo pipefail
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m'
GO_MIN=1.24
GO_FULL=1.25.8 # version to download if go not installed or too old
WORKDIR="${KVWORKDIR:-$HOME/kvlang-tutorial}"
INSTALL_PREFIX="$HOME/.local"
say() { echo -e "${GREEN}==>${NC} $*"; }
warn() { echo -e "${YELLOW}[!]${NC} $*"; }
die() { echo -e "${RED}[X]${NC} $*" >&2; exit 1; }
# ── detect os ──
if ! grep -qi ubuntu /etc/os-release 2>/dev/null; then
die "this script targets ubuntu; $(cat /etc/os-release 2>/dev/null | head -1) detected"
fi
say "ubuntu detected"
# ── sudo check ──
sudo -v
# ═══════════════════════════════════════════════
# step 1: install dependencies
# ═══════════════════════════════════════════════
# ── go 1.24+ ──
need_go=0
if ! command -v go &>/dev/null; then
need_go=1
else
go_ver=$(go version | grep -oP 'go\K[0-9]+\.[0-9]+' | head -1)
if [ "$(printf '%s\n' "$GO_MIN" "$go_ver" | sort -V | head -1)" != "$GO_MIN" ]; then
warn "go $go_ver < $GO_MIN, will upgrade"
need_go=1
fi
fi
if [ "$need_go" -eq 1 ]; then
say "installing go $GO_MIN+"
GO_TAR="go${GO_FULL}.linux-amd64.tar.gz"
if [ ! -f "/tmp/$GO_TAR" ]; then
curl -fsSL "https://go.dev/dl/$GO_TAR" -o "/tmp/$GO_TAR"
fi
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf "/tmp/$GO_TAR"
if ! grep -q '/usr/local/go/bin' "$HOME/.profile" 2>/dev/null; then
echo 'export PATH=/usr/local/go/bin:$PATH' >> "$HOME/.profile"
fi
export PATH=/usr/local/go/bin:$PATH
fi
say "go $(go version | grep -oP 'go[0-9.]+')"
# ── redis-server ──
if ! command -v redis-server &>/dev/null; then
say "installing redis-server"
sudo apt-get update -qq
sudo apt-get install -y -qq redis-server
fi
say "redis-server $(redis-server --version | grep -oP 'v=[0-9.]+')"
# ── python3 ──
if ! command -v python3 &>/dev/null; then
say "installing python3"
sudo apt-get update -qq
sudo apt-get install -y -qq python3
fi
say "python3 $(python3 --version)"
# ═══════════════════════════════════════════════
# step 2: clone repos
# ═══════════════════════════════════════════════
mkdir -p "$WORKDIR"
cd "$WORKDIR"
# clone kvspace-go first (kvlang depends on it via go.mod replace)
if [ ! -d kvspace-go ]; then
say "cloning kvspace-go"
git clone --depth 1 [email protected]:array2d/kvspace-go.git
else
say "kvspace-go already exists, git pull"
git -C kvspace-go pull --ff-only
fi
if [ ! -d kvlang ]; then
say "cloning kvlang"
git clone --depth 1 [email protected]:array2d/kvlang.git
else
say "kvlang already exists, git pull"
git -C kvlang pull --ff-only
fi
# ═══════════════════════════════════════════════
# step 3: build (kvspace-go first, then kvlang)
# ═══════════════════════════════════════════════
say "building kvspace-go"
cd "$WORKDIR/kvspace-go"
GOPROXY="$GOPROXY" PREFIX="$INSTALL_PREFIX" make build
export PATH="$INSTALL_PREFIX/bin:$PATH"
say "building kvlang"
cd "$WORKDIR/kvlang"
GOPROXY="$GOPROXY" PREFIX="$INSTALL_PREFIX" make build
export PATH="$INSTALL_PREFIX/bin:$PATH"
# ═══════════════════════════════════════════════
# step 4: start redis
# ═══════════════════════════════════════════════
if ! redis-cli ping &>/dev/null; then
say "starting redis-server"
redis-server --daemonize yes --loglevel warning
sleep 1
fi
redis-cli ping &>/dev/null || die "redis-server failed to start"
say "redis is up"
# ═══════════════════════════════════════════════
# step 5: run tutorial tests
# ═══════════════════════════════════════════════
say "running tutorial/test.py"
cd "$WORKDIR/kvlang"
python3 tutorial/test.py