@@ -8,120 +8,122 @@ RED='\033[0;31m'
88YELLOW=' \033[1;33m'
99NC=' \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
1225OS=$( uname -s | tr ' [:upper:]' ' [:lower:]' )
1326ARCH=$( uname -m)
1427
1528case " $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+ ;;
1935esac
2036
2137case " $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+ ;;
2544esac
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 "
3051mkdir -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
3455REPO=" SiteDog-io/sitedog-cli"
3556API_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
4069if [ -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
4372fi
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
5282fi
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
5987TPL_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
6290if [ -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
6593fi
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
74100fi
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
80103PROFILE=" "
81- # Determine shell profile to update
82104case " $( basename " $SHELL " ) " in
83105 zsh) PROFILE=" $HOME /.zshrc" ;;
84106 fish) PROFILE=" $HOME /.config/fish/config.fish" ;;
85107 * ) PROFILE=" $HOME /.bashrc" ;;
86108esac
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} "
97119fi
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
103122echo " "
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!"
117124echo " "
118125echo " 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 " "
0 commit comments