Skip to content

Commit 8a998b1

Browse files
committed
Simplify installer PATH setup - auto-detect shell configs instead of prompting
Replaced interactive PATH selection menu with automatic detection logic. The installer now auto-adds PATH export to ~/.bashrc and ~/.zshrc if they exist and don't already contain the install directory. This makes the installer fully non-interactive when piped from curl or run with --non-interactive flag, while reducing code complexity (147 lines → 29).
1 parent 3f2adf5 commit 8a998b1

1 file changed

Lines changed: 76 additions & 130 deletions

File tree

build-dist.sh

Lines changed: 76 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ if [ ! -f "$0" ] || [ "$(basename "$0")" = "bash" ] || [ "$(basename "$0")" = "s
7777
exit 1
7878
fi
7979
80-
bash "$SELF_TEMP" "$@"
80+
bash "$SELF_TEMP" --non-interactive "$@"
8181
EXIT_CODE=$?
8282
rm -f "$SELF_TEMP"
8383
exit $EXIT_CODE
@@ -93,6 +93,14 @@ NC='\033[0m'
9393
VERSION="1.1.1"
9494
INSTALL_DIR="$HOME/.shipnode"
9595
96+
# Parse flags
97+
NON_INTERACTIVE=false
98+
for arg in "$@"; do
99+
if [ "$arg" = "--non-interactive" ]; then
100+
NON_INTERACTIVE=true
101+
fi
102+
done
103+
96104
echo -e "${BLUE}╔════════════════════════════════════╗${NC}"
97105
echo -e "${BLUE}║ ShipNode Installer v${VERSION} ║${NC}"
98106
echo -e "${BLUE}╚════════════════════════════════════╝${NC}"
@@ -142,41 +150,48 @@ fi
142150
echo -e "${GREEN}✓${NC} Extracted successfully"
143151
144152
# Choose installation location
145-
echo
146-
echo "Choose installation location:"
147-
echo " 1) $HOME/.shipnode (recommended)"
148-
echo " 2) /opt/shipnode (system-wide, requires sudo)"
149-
echo " 3) Custom path"
150-
echo
151-
152-
read -p "Enter choice [1-3]: " -n 1 -r
153-
echo
154-
155-
case $REPLY in
156-
1)
157-
INSTALL_DIR="$HOME/.shipnode"
158-
USE_SUDO=""
159-
;;
160-
2)
161-
INSTALL_DIR="/opt/shipnode"
162-
USE_SUDO="sudo"
163-
;;
164-
3)
165-
read -p "Enter installation path: " INSTALL_DIR
166-
INSTALL_DIR="${INSTALL_DIR/#\~/$HOME}"
167-
168-
# Check if we need sudo
169-
if [[ "$INSTALL_DIR" == /opt/* ]] || [[ "$INSTALL_DIR" == /usr/* ]]; then
170-
USE_SUDO="sudo"
171-
else
153+
# If not interactive (e.g., piped from curl or --non-interactive flag), default to recommended location
154+
if [ "$NON_INTERACTIVE" = true ] || [ ! -t 0 ]; then
155+
INSTALL_DIR="$HOME/.shipnode"
156+
USE_SUDO=""
157+
echo -e "${BLUE}→${NC} Non-interactive mode: installing to $INSTALL_DIR"
158+
else
159+
echo
160+
echo "Choose installation location:"
161+
echo " 1) $HOME/.shipnode (recommended)"
162+
echo " 2) /opt/shipnode (system-wide, requires sudo)"
163+
echo " 3) Custom path"
164+
echo
165+
166+
read -p "Enter choice [1-3]: " -n 1 -r
167+
echo
168+
169+
case $REPLY in
170+
1)
171+
INSTALL_DIR="$HOME/.shipnode"
172172
USE_SUDO=""
173-
fi
174-
;;
175-
*)
176-
echo -e "${RED}Invalid choice${NC}"
177-
exit 1
178-
;;
179-
esac
173+
;;
174+
2)
175+
INSTALL_DIR="/opt/shipnode"
176+
USE_SUDO="sudo"
177+
;;
178+
3)
179+
read -p "Enter installation path: " INSTALL_DIR
180+
INSTALL_DIR="${INSTALL_DIR/#\~/$HOME}"
181+
182+
# Check if we need sudo
183+
if [[ "$INSTALL_DIR" == /opt/* ]] || [[ "$INSTALL_DIR" == /usr/* ]]; then
184+
USE_SUDO="sudo"
185+
else
186+
USE_SUDO=""
187+
fi
188+
;;
189+
*)
190+
echo -e "${RED}Invalid choice${NC}"
191+
exit 1
192+
;;
193+
esac
194+
fi
180195
181196
# Install
182197
echo -e "${BLUE}→${NC} Installing to $INSTALL_DIR..."
@@ -199,103 +214,34 @@ $USE_SUDO chmod +x "$INSTALL_DIR/shipnode"
199214
echo -e "${GREEN}✓${NC} Files installed"
200215
201216
# Setup PATH
202-
echo
203-
echo "Choose how to make shipnode available:"
204-
echo " 1) Symlink to /usr/local/bin (recommended, may require sudo)"
205-
echo " 2) Add to PATH in ~/.bashrc"
206-
echo " 3) Add to PATH in ~/.zshrc"
207-
echo " 4) Both bashrc and zshrc"
208-
echo " 5) Skip (manual setup)"
209-
echo
210-
211-
read -p "Enter choice [1-5]: " -n 1 -r
212-
echo
213-
214217
SHIPNODE_BIN="$INSTALL_DIR/shipnode"
218+
EXPORT_LINE="export PATH=\"$INSTALL_DIR:\$PATH\""
219+
ADDED_TO=""
220+
221+
if [ -f ~/.bashrc ]; then
222+
if ! grep -q "$INSTALL_DIR" ~/.bashrc 2>/dev/null; then
223+
echo "" >> ~/.bashrc
224+
echo "# ShipNode" >> ~/.bashrc
225+
echo "$EXPORT_LINE" >> ~/.bashrc
226+
ADDED_TO="~/.bashrc"
227+
fi
228+
fi
215229
216-
case $REPLY in
217-
1)
218-
echo -e "${BLUE}→${NC} Creating symlink to /usr/local/bin..."
219-
sudo ln -sf "$SHIPNODE_BIN" /usr/local/bin/shipnode
220-
echo -e "${GREEN}✓${NC} Symlink created"
221-
222-
# Verify
223-
if command -v shipnode &> /dev/null; then
224-
echo -e "${GREEN}✓${NC} Installation successful!"
225-
else
226-
echo -e "${YELLOW}⚠${NC} Symlink created but shipnode not in PATH. Check your PATH settings."
227-
fi
228-
;;
229-
2)
230-
echo -e "${BLUE}→${NC} Adding to ~/.bashrc..."
231-
EXPORT_LINE="export PATH=\"$INSTALL_DIR:\$PATH\""
232-
233-
if grep -q "$INSTALL_DIR" ~/.bashrc 2>/dev/null; then
234-
echo -e "${YELLOW}⚠${NC} Already in ~/.bashrc"
235-
else
236-
echo "" >> ~/.bashrc
237-
echo "# ShipNode" >> ~/.bashrc
238-
echo "$EXPORT_LINE" >> ~/.bashrc
239-
echo -e "${GREEN}✓${NC} Added to ~/.bashrc"
240-
fi
241-
242-
echo -e "\n${BLUE}Run:${NC} source ~/.bashrc"
243-
echo -e "or restart your terminal to use shipnode"
244-
;;
245-
3)
246-
echo -e "${BLUE}→${NC} Adding to ~/.zshrc..."
247-
EXPORT_LINE="export PATH=\"$INSTALL_DIR:\$PATH\""
248-
249-
if grep -q "$INSTALL_DIR" ~/.zshrc 2>/dev/null; then
250-
echo -e "${YELLOW}⚠${NC} Already in ~/.zshrc"
251-
else
252-
echo "" >> ~/.zshrc
253-
echo "# ShipNode" >> ~/.zshrc
254-
echo "$EXPORT_LINE" >> ~/.zshrc
255-
echo -e "${GREEN}✓${NC} Added to ~/.zshrc"
256-
fi
257-
258-
echo -e "\n${BLUE}Run:${NC} source ~/.zshrc"
259-
echo -e "or restart your terminal to use shipnode"
260-
;;
261-
4)
262-
echo -e "${BLUE}→${NC} Adding to both ~/.bashrc and ~/.zshrc..."
263-
EXPORT_LINE="export PATH=\"$INSTALL_DIR:\$PATH\""
264-
265-
# Bashrc
266-
if grep -q "$INSTALL_DIR" ~/.bashrc 2>/dev/null; then
267-
echo -e "${YELLOW}⚠${NC} Already in ~/.bashrc"
268-
else
269-
echo "" >> ~/.bashrc
270-
echo "# ShipNode" >> ~/.bashrc
271-
echo "$EXPORT_LINE" >> ~/.bashrc
272-
echo -e "${GREEN}✓${NC} Added to ~/.bashrc"
273-
fi
274-
275-
# Zshrc
276-
if grep -q "$INSTALL_DIR" ~/.zshrc 2>/dev/null; then
277-
echo -e "${YELLOW}⚠${NC} Already in ~/.zshrc"
278-
else
279-
echo "" >> ~/.zshrc
280-
echo "# ShipNode" >> ~/.zshrc
281-
echo "$EXPORT_LINE" >> ~/.zshrc
282-
echo -e "${GREEN}✓${NC} Added to ~/.zshrc"
283-
fi
284-
285-
echo -e "\n${BLUE}Run:${NC} source ~/.bashrc (or ~/.zshrc)"
286-
echo -e "or restart your terminal to use shipnode"
287-
;;
288-
5)
289-
echo -e "${YELLOW}⚠${NC} Skipping PATH setup"
290-
echo -e "\nManual setup options:"
291-
echo -e " 1. Symlink: ${BLUE}sudo ln -s $SHIPNODE_BIN /usr/local/bin/shipnode${NC}"
292-
echo -e " 2. PATH: Add ${BLUE}export PATH=\"$INSTALL_DIR:\$PATH\"${NC} to your shell config"
293-
;;
294-
*)
295-
echo -e "${RED}Invalid choice${NC}"
296-
exit 1
297-
;;
298-
esac
230+
if [ -f ~/.zshrc ]; then
231+
if ! grep -q "$INSTALL_DIR" ~/.zshrc 2>/dev/null; then
232+
echo "" >> ~/.zshrc
233+
echo "# ShipNode" >> ~/.zshrc
234+
echo "$EXPORT_LINE" >> ~/.zshrc
235+
[ -n "$ADDED_TO" ] && ADDED_TO="$ADDED_TO and ~/.zshrc" || ADDED_TO="~/.zshrc"
236+
fi
237+
fi
238+
239+
if [ -n "$ADDED_TO" ]; then
240+
echo -e "${GREEN}✓${NC} Added to PATH in $ADDED_TO"
241+
echo -e " Restart your terminal or run: ${BLUE}source $ADDED_TO${NC}"
242+
else
243+
echo -e "${YELLOW}⚠${NC} Already in PATH or no shell config found"
244+
fi
299245
300246
# Cleanup
301247
cd - > /dev/null

0 commit comments

Comments
 (0)