Skip to content

Commit ccbc617

Browse files
committed
update install.sh and unistall.sh
1 parent a34c1c1 commit ccbc617

File tree

2 files changed

+82
-64
lines changed

2 files changed

+82
-64
lines changed

scripts/install.sh

Lines changed: 66 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -8,120 +8,122 @@ RED='\033[0;31m'
88
YELLOW='\033[1;33m'
99
NC='\033[0m' # No Color
1010

11-
# Detect platform
11+
# Function to print colored output
12+
print_info() {
13+
echo "${GREEN}$1${NC}"
14+
}
15+
16+
print_error() {
17+
echo "${RED}$1${NC}"
18+
}
19+
20+
print_warning() {
21+
echo "${YELLOW}$1${NC}"
22+
}
23+
24+
# Detect platform and architecture
1225
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
1326
ARCH=$(uname -m)
1427

1528
case "$ARCH" in
1629
x86_64|amd64) ARCH="amd64" ;;
1730
aarch64|arm64) ARCH="arm64" ;;
18-
*) echo "Unsupported architecture: $ARCH"; exit 1 ;;
31+
*)
32+
print_error "Unsupported architecture: $ARCH"
33+
exit 1
34+
;;
1935
esac
2036

2137
case "$OS" in
2238
linux) BIN_NAME="sitedog-linux-$ARCH" ;;
2339
darwin) BIN_NAME="sitedog-darwin-$ARCH" ;;
24-
*) echo "Unsupported OS: $OS"; exit 1 ;;
40+
*)
41+
print_error "Unsupported OS: $OS"
42+
exit 1
43+
;;
2544
esac
2645

27-
# Directories
28-
INSTALL_DIR="$HOME/.sitedog/bin"
29-
TEMPLATES_DIR="$HOME/.sitedog"
46+
# Setup directories
47+
INSTALL_DIR="$HOME/.sitedog"
48+
BINARY_DIR="$HOME/.sitedog/bin"
49+
50+
print_info "Creating user directory $INSTALL_DIR"
3051
mkdir -p "$INSTALL_DIR"
31-
mkdir -p "$TEMPLATES_DIR"
52+
mkdir -p "$BINARY_DIR"
3253

33-
# Download latest release from GitHub (без jq)
54+
# GitHub repository and API
3455
REPO="SiteDog-io/sitedog-cli"
3556
API_URL="https://api.github.com/repos/$REPO/releases/latest"
3657

37-
# Получаем ссылку на нужный бинарник из релиза (без jq)
38-
ASSET_URL=$(curl -s "$API_URL" | grep 'browser_download_url' | grep "$BIN_NAME" | head -n1 | cut -d '"' -f 4)
58+
# Get latest release assets
59+
RELEASE_INFO=$(curl -s "$API_URL")
60+
if [ $? -ne 0 ]; then
61+
print_error "Failed to fetch release information from GitHub"
62+
exit 1
63+
fi
64+
65+
# Extract version and binary download URL
66+
VERSION=$(echo "$RELEASE_INFO" | grep '"tag_name"' | head -n1 | cut -d '"' -f 4)
67+
ASSET_URL=$(echo "$RELEASE_INFO" | grep 'browser_download_url' | grep "$BIN_NAME" | head -n1 | cut -d '"' -f 4)
3968

4069
if [ -z "$ASSET_URL" ]; then
41-
echo "${RED}Error: Could not find asset $BIN_NAME in the latest release${NC}"
70+
print_error "Could not find binary $BIN_NAME in the latest release"
4271
exit 1
4372
fi
4473

45-
echo "Downloading $BIN_NAME from $ASSET_URL..."
46-
curl -sL "$ASSET_URL" -o "$INSTALL_DIR/sitedog"
74+
print_info "Installing version $VERSION"
4775

48-
# Check if file was downloaded
49-
if [ ! -f "$INSTALL_DIR/sitedog" ]; then
50-
echo "${RED}Error: Failed to download sitedog${NC}"
76+
# Download binary
77+
curl -sL "$ASSET_URL" -o "$BINARY_DIR/sitedog"
78+
79+
if [ ! -f "$BINARY_DIR/sitedog" ]; then
80+
print_error "Failed to download binary"
5181
exit 1
5282
fi
5383

54-
# Make file executable
55-
chmod +x "$INSTALL_DIR/sitedog"
56-
echo "Installed sitedog to $INSTALL_DIR/sitedog"
84+
chmod +x "$BINARY_DIR/sitedog"
5785

58-
# Download demo.html.tpl template
86+
# Download template
5987
TPL_NAME="demo.html.tpl"
60-
TPL_URL=$(curl -s "$API_URL" | grep 'browser_download_url' | grep "$TPL_NAME" | head -n1 | cut -d '"' -f 4)
88+
TPL_URL=$(echo "$RELEASE_INFO" | grep 'browser_download_url' | grep "$TPL_NAME" | head -n1 | cut -d '"' -f 4)
6189

6290
if [ -z "$TPL_URL" ]; then
63-
echo "${RED}Error: Could not find asset $TPL_NAME in the latest release${NC}"
91+
print_error "Could not find template $TPL_NAME in the latest release"
6492
exit 1
6593
fi
6694

67-
echo "Downloading $TPL_NAME from $TPL_URL..."
68-
curl -sL "$TPL_URL" -o "$TEMPLATES_DIR/demo.html.tpl"
95+
curl -sL "$TPL_URL" -o "$INSTALL_DIR/demo.html.tpl"
6996

70-
# Check if template was downloaded
71-
if [ ! -f "$TEMPLATES_DIR/demo.html.tpl" ]; then
72-
echo "${RED}Error: Failed to download demo.html.tpl${NC}"
97+
if [ ! -f "$INSTALL_DIR/demo.html.tpl" ]; then
98+
print_error "Failed to download template"
7399
exit 1
74100
fi
75101

76-
echo "Installed demo.html.tpl to $TEMPLATES_DIR/demo.html.tpl"
77-
78-
# Add to PATH if not already there
79-
RELOAD_MSG=""
102+
# Determine shell profile and update PATH
80103
PROFILE=""
81-
# Determine shell profile to update
82104
case "$(basename "$SHELL")" in
83105
zsh) PROFILE="$HOME/.zshrc" ;;
84106
fish) PROFILE="$HOME/.config/fish/config.fish" ;;
85107
*) PROFILE="$HOME/.bashrc" ;;
86108
esac
87109

88-
if ! echo "$PATH" | grep -q "$INSTALL_DIR"; then
89-
# Add to PATH in the appropriate profile
110+
# Check if PATH already contains the binary directory
111+
if ! grep -Eq 'PATH.*sitedog' "$PROFILE"; then
90112
if [ "$SHELL" = "/usr/bin/fish" ] || [ "$SHELL" = "/bin/fish" ]; then
91-
echo "set -gx PATH \"$INSTALL_DIR\" \$PATH" >> "$PROFILE"
113+
# For fish shell, add the appropriate PATH export
114+
echo "set -gx PATH \"$BINARY_DIR\" \$PATH" >> "$PROFILE"
92115
else
93-
echo "export PATH=\"$INSTALL_DIR:\$PATH\"" >> "$PROFILE"
116+
# For bash/zsh, add the appropriate PATH export
117+
echo "export PATH=\"$BINARY_DIR:\$PATH\"" >> "$PROFILE"
94118
fi
95-
96-
RELOAD_MSG="${YELLOW} (source $PROFILE or restart your shell)${NC}"
97119
fi
98120

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
121+
# Success message
103122
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
113-
else
114-
echo "Global symlink skipped."
115-
fi
116-
123+
print_info "SiteDog successfully installed!"
117124
echo ""
118125
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
126+
echo ""
127+
print_warning "If 'sitedog help' doesn't work, run:"
128+
echo "source $PROFILE"
129+
echo ""

scripts/uninstall.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,20 @@ if [ -d "$HOME/.sitedog" ]; then
2020
echo "${GREEN}Removed $HOME/.sitedog directory${NC}"
2121
fi
2222

23+
# Remove PATH entries from shell profiles
24+
for RC in "$HOME/.bashrc" "$HOME/.zshrc" "$HOME/.config/fish/config.fish"; do
25+
if [ -f "$RC" ]; then
26+
# Remove lines that add sitedog to PATH
27+
case "$(uname)" in
28+
Darwin*)
29+
sed -i '' '/sitedog\/bin.*PATH/d' "$RC"
30+
;;
31+
*)
32+
sed -i '/sitedog\/bin.*PATH/d' "$RC"
33+
;;
34+
esac
35+
echo "${GREEN}Cleaned PATH from $RC${NC}"
36+
fi
37+
done
38+
2339
echo "${GREEN}SiteDog has been fully uninstalled!${NC}"

0 commit comments

Comments
 (0)