Skip to content

Commit a34c1c1

Browse files
committed
update install
1 parent bd14568 commit a34c1c1

File tree

2 files changed

+55
-55
lines changed

2 files changed

+55
-55
lines changed

scripts/install.sh

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ API_URL="https://api.github.com/repos/$REPO/releases/latest"
3838
ASSET_URL=$(curl -s "$API_URL" | grep 'browser_download_url' | grep "$BIN_NAME" | head -n1 | cut -d '"' -f 4)
3939

4040
if [ -z "$ASSET_URL" ]; then
41-
echo -e "${RED}Error: Could not find asset $BIN_NAME in the latest release${NC}"
41+
echo "${RED}Error: Could not find asset $BIN_NAME in the latest release${NC}"
4242
exit 1
4343
fi
4444

@@ -47,7 +47,7 @@ curl -sL "$ASSET_URL" -o "$INSTALL_DIR/sitedog"
4747

4848
# Check if file was downloaded
4949
if [ ! -f "$INSTALL_DIR/sitedog" ]; then
50-
echo -e "${RED}Error: Failed to download sitedog${NC}"
50+
echo "${RED}Error: Failed to download sitedog${NC}"
5151
exit 1
5252
fi
5353

@@ -60,7 +60,7 @@ TPL_NAME="demo.html.tpl"
6060
TPL_URL=$(curl -s "$API_URL" | grep 'browser_download_url' | grep "$TPL_NAME" | head -n1 | cut -d '"' -f 4)
6161

6262
if [ -z "$TPL_URL" ]; then
63-
echo -e "${RED}Error: Could not find asset $TPL_NAME in the latest release${NC}"
63+
echo "${RED}Error: Could not find asset $TPL_NAME in the latest release${NC}"
6464
exit 1
6565
fi
6666

@@ -69,29 +69,59 @@ curl -sL "$TPL_URL" -o "$TEMPLATES_DIR/demo.html.tpl"
6969

7070
# Check if template was downloaded
7171
if [ ! -f "$TEMPLATES_DIR/demo.html.tpl" ]; then
72-
echo -e "${RED}Error: Failed to download demo.html.tpl${NC}"
72+
echo "${RED}Error: Failed to download demo.html.tpl${NC}"
7373
exit 1
7474
fi
7575

7676
echo "Installed demo.html.tpl to $TEMPLATES_DIR/demo.html.tpl"
7777

78-
# Try to create symlink in /usr/local/bin
79-
SYMLINK_OK=0
80-
if [ -w /usr/local/bin ]; then
81-
ln -sf "$INSTALL_DIR/sitedog" /usr/local/bin/sitedog && SYMLINK_OK=1
82-
else
83-
if sudo ln -sf "$INSTALL_DIR/sitedog" /usr/local/bin/sitedog; then
84-
SYMLINK_OK=1
78+
# Add to PATH if not already there
79+
RELOAD_MSG=""
80+
PROFILE=""
81+
# Determine shell profile to update
82+
case "$(basename "$SHELL")" in
83+
zsh) PROFILE="$HOME/.zshrc" ;;
84+
fish) PROFILE="$HOME/.config/fish/config.fish" ;;
85+
*) PROFILE="$HOME/.bashrc" ;;
86+
esac
87+
88+
if ! echo "$PATH" | grep -q "$INSTALL_DIR"; then
89+
# Add to PATH in the appropriate profile
90+
if [ "$SHELL" = "/usr/bin/fish" ] || [ "$SHELL" = "/bin/fish" ]; then
91+
echo "set -gx PATH \"$INSTALL_DIR\" \$PATH" >> "$PROFILE"
92+
else
93+
echo "export PATH=\"$INSTALL_DIR:\$PATH\"" >> "$PROFILE"
8594
fi
95+
96+
RELOAD_MSG="${YELLOW} (source $PROFILE or restart your shell)${NC}"
8697
fi
8798

88-
if [ $SYMLINK_OK -eq 1 ]; then
89-
echo "Symlink created: /usr/local/bin/sitedog -> $INSTALL_DIR/sitedog"
99+
echo "${GREEN}SiteDog has been installed successfully!${NC}"
100+
echo "Installed to: ${INSTALL_DIR}/sitedog${RELOAD_MSG}"
101+
102+
# Ask user if they want to create symlink in /usr/local/bin
103+
echo ""
104+
printf "Create symlink in /usr/local/bin? (sudo) [y/N] "
105+
read -r REPLY
106+
107+
if [ "$REPLY" = "y" ] || [ "$REPLY" = "Y" ] || [ "$REPLY" = "yes" ] || [ "$REPLY" = "YES" ]; then
108+
if sudo ln -sf "$INSTALL_DIR/sitedog" /usr/local/bin/sitedog; then
109+
echo "${GREEN}🔗 Symlink created → /usr/local/bin/sitedog${NC}"
110+
else
111+
echo "${RED}Failed to create symlink${NC}"
112+
fi
90113
else
91-
echo "${YELLOW}No permissions to create symlink in /usr/local/bin.${NC}"
92-
echo "Please add $INSTALL_DIR to your PATH. For example, add this line to your shell rc file (e.g., ~/.bashrc or ~/.zshrc):"
93-
echo 'export PATH="$HOME/.sitedog/bin:$PATH"'
114+
echo "Global symlink skipped."
94115
fi
95116

96-
echo "${GREEN}SiteDog has been installed successfully!${NC}"
97-
echo "Try: sitedog help"
117+
echo ""
118+
echo "Try: sitedog help"
119+
120+
# Show reload message if PATH was updated
121+
if [ -n "$PROFILE" ]; then
122+
echo ""
123+
echo "${YELLOW}If 'sitedog help' doesn't work, run:${NC}"
124+
echo ""
125+
echo "source $PROFILE"
126+
echo ""
127+
fi

scripts/uninstall.sh

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,20 @@ set -e
44

55
# Colors for output
66
GREEN='\033[0;32m'
7+
RED='\033[0;31m'
78
NC='\033[0m' # No Color
89

9-
# Remove binary or symlink from /usr/local/bin
10+
# Remove symlink from /usr/local/bin
1011
if [ -L "/usr/local/bin/sitedog" ] || [ -f "/usr/local/bin/sitedog" ]; then
1112
echo "Removing /usr/local/bin/sitedog (may require sudo)..."
1213
sudo rm -f /usr/local/bin/sitedog
13-
echo "Removed /usr/local/bin/sitedog"
14+
echo "${GREEN}Removed /usr/local/bin/sitedog${NC}"
1415
fi
1516

16-
# Remove demo.html.tpl
17-
if [ -f "$HOME/.sitedog/demo.html.tpl" ]; then
18-
rm -f "$HOME/.sitedog/demo.html.tpl"
19-
echo "Removed $HOME/.sitedog/demo.html.tpl"
17+
# Remove ~/.sitedog directory completely
18+
if [ -d "$HOME/.sitedog" ]; then
19+
rm -rf "$HOME/.sitedog"
20+
echo "${GREEN}Removed $HOME/.sitedog directory${NC}"
2021
fi
2122

22-
# Remove ~/.sitedog/bin directory if empty
23-
if [ -d "$HOME/.sitedog/bin" ] && [ ! "$(ls -A $HOME/.sitedog/bin)" ]; then
24-
rmdir "$HOME/.sitedog/bin"
25-
echo "Removed empty $HOME/.sitedog/bin directory"
26-
fi
27-
28-
# Remove ~/.sitedog directory if empty
29-
if [ -d "$HOME/.sitedog" ] && [ ! "$(ls -A $HOME/.sitedog)" ]; then
30-
rmdir "$HOME/.sitedog"
31-
echo "Removed empty $HOME/.sitedog directory"
32-
fi
33-
34-
# Remove ~/.sitedog/bin from PATH in all common rc files (backward compatibility)
35-
for RC in "$HOME/.bashrc" "$HOME/.zshrc" "$HOME/.profile" "$HOME/.bash_profile" "$HOME/.config/fish/config.fish"; do
36-
if [ -f "$RC" ]; then
37-
# Determine OS for correct sed usage
38-
case "$(uname)" in
39-
Darwin*)
40-
sed -i '' '/sitedog\/bin.*PATH/d' "$RC"
41-
sed -i '' '/# Added by sitedog installer/d' "$RC"
42-
;;
43-
*)
44-
sed -i.bak '/sitedog\/bin.*PATH/d' "$RC"
45-
sed -i '/# Added by sitedog installer/d' "$RC"
46-
;;
47-
esac
48-
# shellcheck disable=SC1090
49-
. "$RC"
50-
fi
51-
done
52-
5323
echo "${GREEN}SiteDog has been fully uninstalled!${NC}"

0 commit comments

Comments
 (0)