@@ -4,7 +4,7 @@ set -euo pipefail
44# Syndicate CLI Installer
55# Usage:
66# curl -L https://raw.githubusercontent.com/SyndicateProtocol/syndicate-appchains/main/synd-cli/install.sh | bash
7- # curl -L https://raw.githubusercontent.com/SyndicateProtocol/syndicate-appchains/main/synd-cli/install.sh | SYND_VERSION=synd-cli-v1 .0.0 bash
7+ # curl -L https://raw.githubusercontent.com/SyndicateProtocol/syndicate-appchains/main/synd-cli/install.sh | SYND_VERSION=1 .0.0 bash
88
99REPO=" SyndicateProtocol/syndicate-appchains"
1010INSTALL_DIR=" ${SYND_INSTALL_DIR:- $HOME / .synd/ bin} "
@@ -25,7 +25,7 @@ warn() {
2525}
2626
2727error () {
28- printf " ${RED} error${NC} : %s\n" " $1 "
28+ printf " ${RED} error${NC} : %s\n" " $1 " >&2
2929 exit 1
3030}
3131
@@ -51,15 +51,16 @@ detect_platform() {
5151
5252get_latest_version () {
5353 local latest
54- # Find the latest synd-cli release (tags starting with "synd-cli-")
54+ # Find the latest stable synd-cli release (X.Y.Z without pre-release suffix)
55+ # The "|| true" prevents pipefail from exiting the script when no version is found
5556 latest=$( curl -fsSL " https://api.github.com/repos/${REPO} /releases" | \
5657 grep ' "tag_name"' | \
5758 sed -E ' s/.*"([^"]+)".*/\1/' | \
58- grep ' ^synd-cli-' | \
59- head -n 1)
59+ grep -E ' ^synd-cli-v[0-9]+\.[0-9]+\.[0-9]+$ ' | \
60+ head -n 1 || true )
6061
6162 if [[ -z " $latest " ]]; then
62- error " Failed to fetch latest synd-cli version. Please check your internet connection or specify a version with SYND_VERSION=synd-cli-vX .Y.Z"
63+ error " Failed to fetch latest synd-cli version. Please check your internet connection or specify a version with SYND_VERSION=X .Y.Z"
6364 fi
6465
6566 echo " $latest "
@@ -73,7 +74,7 @@ download_binary() {
7374
7475 tmp_file=$( mktemp)
7576
76- info " Downloading synd-cli ${version} for ${platform} ..."
77+ info " Downloading synd-cli ${version} for ${platform} ..." >&2
7778
7879 if ! curl -fsSL " $url " -o " $tmp_file " ; then
7980 rm -f " $tmp_file "
@@ -119,20 +120,60 @@ setup_path_instructions() {
119120 # Check if already in PATH
120121 if [[ " :$PATH :" == * " :$INSTALL_DIR :" * ]]; then
121122 info " synd-cli is ready to use!"
123+ return
124+ fi
125+
126+ echo " "
127+ printf " ${YELLOW} synd-cli is not in your PATH.${NC} \n"
128+ echo " "
129+ printf " Would you like to add it automatically? [Y/n] "
130+
131+ # Read user input (handle piped input by reading from /dev/tty)
132+ local response
133+ if [[ -t 0 ]]; then
134+ read -r response
122135 else
123- echo " "
124- warn " Add synd-cli to your PATH by running:"
125- echo " "
126- if [[ " $shell_name " == " fish" ]]; then
127- printf " fish_add_path %s\n" " $INSTALL_DIR "
128- else
129- printf " echo 'export PATH=\" %s:\$ PATH\" ' >> %s\n" " $INSTALL_DIR " " $rc_file "
130- fi
131- echo " "
132- printf " Then restart your shell or run:\n"
133- printf " source %s\n" " $rc_file "
134- echo " "
136+ read -r response < /dev/tty
135137 fi
138+
139+ case " $response " in
140+ [Yy]|" " )
141+ # Add to PATH
142+ if [[ " $shell_name " == " fish" ]]; then
143+ echo " fish_add_path $INSTALL_DIR " >> " $rc_file "
144+ else
145+ echo " export PATH=\" $INSTALL_DIR :\$ PATH\" " >> " $rc_file "
146+ fi
147+ info " Added synd-cli to PATH in ${rc_file} "
148+ echo " "
149+ warn " Restart your terminal or run: source ${rc_file} "
150+ echo " "
151+ ;;
152+ [Nn])
153+ echo " "
154+ printf " ${YELLOW} ========================================${NC} \n"
155+ warn " ACTION REQUIRED: Add synd-cli to your PATH"
156+ printf " ${YELLOW} ========================================${NC} \n"
157+ echo " "
158+ printf " Run this command to add synd-cli to your PATH:\n"
159+ echo " "
160+ if [[ " $shell_name " == " fish" ]]; then
161+ printf " ${GREEN} fish_add_path %s${NC} \n" " $INSTALL_DIR "
162+ else
163+ printf " ${GREEN} echo 'export PATH=\" %s:\$ PATH\" ' >> %s${NC} \n" " $INSTALL_DIR " " $rc_file "
164+ fi
165+ echo " "
166+ printf " Then restart your terminal or run:\n"
167+ echo " "
168+ printf " ${GREEN} source %s${NC} \n" " $rc_file "
169+ echo " "
170+ printf " ${YELLOW} ========================================${NC} \n"
171+ echo " "
172+ ;;
173+ * )
174+ warn " Invalid response. Please manually add ${INSTALL_DIR} to your PATH."
175+ ;;
176+ esac
136177}
137178
138179main () {
@@ -150,6 +191,9 @@ main() {
150191 if [[ -z " $version " ]]; then
151192 info " Fetching latest version..."
152193 version=$( get_latest_version)
194+ else
195+ # User provided version - add the synd-cli-v prefix
196+ version=" synd-cli-v${version} "
153197 fi
154198 info " Version: ${version} "
155199
0 commit comments