Skip to content

Commit 31a4d7c

Browse files
moulaeddi
andauthored
feat: add misc/install.sh oneline install script (#4284)
Allows `curl -sSL https://raw.githubusercontent.com/gnolang/gno/main/misc/install.sh | bash`. Currently, it already supports the `--uninstall` flag, which means we can expect to add more options, such as `--with-gnoland`, for additional binaries, etc. This is optional for some binaries where a simple `go install github.com/gnolang/gno/gnovm/cmd/gno@latest` works out of the box. However, it is necessary when the go.mod file contains `replace` directives, such as `gnodev`. Blocks gnolang/getting-started#2 --------- Signed-off-by: moul <94029+moul@users.noreply.github.com> Co-authored-by: aeddi <antoine.e.b@gmail.com>
1 parent 1bc1027 commit 31a4d7c

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed

misc/install.sh

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Usage: curl -sSL https://raw.githubusercontent.com/gnolang/gno/main/misc/install.sh | bash
5+
# Optional: GNO_DIR=/custom/path curl -sSL https://raw.githubusercontent.com/gnolang/gno/main/misc/install.sh | bash
6+
# Uninstall: curl -sSL https://raw.githubusercontent.com/gnolang/gno/main/misc/install.sh | bash -s -- --uninstall
7+
#
8+
# This script is temporarily located in misc/ as we expect more official installation
9+
# methods to emerge. It provides a convenient one-liner for installing gno, which is
10+
# particularly useful when working with go.mod files containing replace directives
11+
# that might conflict with direct `go install` commands.
12+
13+
# Colors for output
14+
RED='\033[0;31m'
15+
GREEN='\033[0;32m'
16+
YELLOW='\033[1;33m'
17+
NC='\033[0m' # No Color
18+
19+
# Function to print colored messages
20+
log() {
21+
echo -e "${GREEN}[gno-install]${NC} $1"
22+
}
23+
24+
error() {
25+
echo -e "${RED}[gno-install]${NC} $1" >&2
26+
}
27+
28+
warn() {
29+
echo -e "${YELLOW}[gno-install]${NC} $1"
30+
}
31+
32+
# Function to check if a command exists
33+
command_exists() {
34+
command -v "$1" >/dev/null 2>&1
35+
}
36+
37+
# Function to determine gno source directory
38+
get_gno_dir() {
39+
if [ -n "$GNO_DIR" ]; then
40+
echo "$GNO_DIR"
41+
elif [ -n "$HOME" ]; then
42+
echo "$HOME/.gno/src"
43+
else
44+
echo "/usr/local/share/gno"
45+
fi
46+
}
47+
48+
# Function to check Go installation
49+
check_go() {
50+
if ! command_exists go; then
51+
error "Go is not installed. Please install Go first:"
52+
echo " https://golang.org/doc/install"
53+
exit 1
54+
fi
55+
56+
# Check Go version
57+
GO_VERSION=$(go version | awk '{print $3}' | sed 's/go//')
58+
if [ "$(echo "$GO_VERSION 1.18" | awk '{print ($1 < $2)}')" -eq 1 ]; then
59+
error "Go version 1.18 or higher is required. Current version: $GO_VERSION"
60+
exit 1
61+
fi
62+
}
63+
64+
# Function to install gno
65+
install_gno() {
66+
local GNO_DIR
67+
GNO_DIR=$(get_gno_dir)
68+
69+
if ! command_exists git; then
70+
error "git is not installed. Please install git first."
71+
exit 1
72+
fi
73+
74+
log "Installing gno source to $GNO_DIR"
75+
76+
mkdir -p "$GNO_DIR"
77+
# Clone or update repository
78+
if [ -d "$GNO_DIR/.git" ]; then
79+
log "Updating existing gno repository..."
80+
cd "$GNO_DIR"
81+
git fetch --depth 1
82+
git reset --hard origin/master
83+
else
84+
log "Cloning gno repository..."
85+
git clone --depth 1 https://github.com/gnolang/gno.git "$GNO_DIR"
86+
cd "$GNO_DIR"
87+
fi
88+
89+
# Build and install
90+
log "Building gno..."
91+
make install
92+
93+
# Verify installation
94+
if ! command_exists gno; then
95+
error "Installation failed. gno command not found."
96+
log "Is $GOBIN set in your $PATH? See https://go.dev/doc/install/source#environment"
97+
exit 1
98+
fi
99+
100+
log "Installation successful! gno is now available."
101+
gno version
102+
}
103+
104+
# Function to uninstall gno
105+
uninstall_gno() {
106+
local GNO_DIR
107+
local GOPATH
108+
GNO_DIR=$(get_gno_dir)
109+
GOPATH=$(go env GOPATH)
110+
111+
log "Uninstalling gno binaries from $GOPATH/bin"
112+
rm -f "$GOPATH/bin/gno"
113+
rm -f "$GOPATH/bin/gnokey"
114+
rm -f "$GOPATH/bin/gnodev"
115+
116+
# Remove source directory
117+
log "Removing gno source from $GNO_DIR"
118+
rm -rf "$GNO_DIR"
119+
120+
log "Uninstallation complete."
121+
}
122+
123+
# Main script
124+
if [ "$1" = "--uninstall" ]; then
125+
uninstall_gno
126+
exit 0
127+
fi
128+
129+
# Check Go installation
130+
check_go
131+
132+
# Install gno
133+
install_gno

0 commit comments

Comments
 (0)