Skip to content

Commit 8a679ac

Browse files
committed
feat: add automatic rsync installation for Windows
1 parent 0736b26 commit 8a679ac

1 file changed

Lines changed: 128 additions & 20 deletions

File tree

lib/rsync-installer.sh

Lines changed: 128 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,92 @@
22
#
33
# rsync-installer.sh - Rsync installer for Windows
44
#
5-
# Ensures rsync is available on Windows systems by installing it via Git for Windows
5+
# Automatically installs rsync on Windows systems via Chocolatey or Scoop
66
#
77

88
# Check if rsync is available
99
has_rsync() {
1010
command -v rsync &> /dev/null
1111
}
1212

13-
# Check if Git for Windows is installed
14-
has_git_for_windows() {
15-
command -v git &> /dev/null && [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]
13+
# Check if running in PowerShell/CMD vs Git Bash/WSL
14+
is_native_windows() {
15+
[[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]] && return 1
16+
[[ -n "$WSL_DISTRO_NAME" ]] && return 1
17+
[[ "$OS" == "Windows_NT" ]] && return 0
18+
return 1
1619
}
1720

18-
# Install rsync on Windows
21+
# Check if Chocolatey is installed
22+
has_chocolatey() {
23+
command -v choco &> /dev/null
24+
}
25+
26+
# Check if Scoop is installed
27+
has_scoop() {
28+
command -v scoop &> /dev/null
29+
}
30+
31+
# Install rsync via Chocolatey
32+
install_rsync_choco() {
33+
info "Installing rsync via Chocolatey..."
34+
35+
if ! has_chocolatey; then
36+
info "Installing Chocolatey first..."
37+
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))"
38+
39+
if [ $? -ne 0 ]; then
40+
warn "Failed to install Chocolatey"
41+
return 1
42+
fi
43+
44+
success "Chocolatey installed"
45+
fi
46+
47+
info "Installing rsync package..."
48+
choco install rsync -y
49+
50+
if [ $? -eq 0 ]; then
51+
success "rsync installed via Chocolatey"
52+
# Update PATH for current session
53+
export PATH="$PATH:/c/ProgramData/chocolatey/bin"
54+
return 0
55+
else
56+
warn "Failed to install rsync via Chocolatey"
57+
return 1
58+
fi
59+
}
60+
61+
# Install rsync via Scoop
62+
install_rsync_scoop() {
63+
info "Installing rsync via Scoop..."
64+
65+
if ! has_scoop; then
66+
info "Installing Scoop first..."
67+
powershell.exe -NoProfile -ExecutionPolicy RemoteSigned -Command "Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh'))"
68+
69+
if [ $? -ne 0 ]; then
70+
warn "Failed to install Scoop"
71+
return 1
72+
fi
73+
74+
success "Scoop installed"
75+
fi
76+
77+
info "Adding extras bucket and installing rsync..."
78+
scoop bucket add extras
79+
scoop install rsync
80+
81+
if [ $? -eq 0 ]; then
82+
success "rsync installed via Scoop"
83+
return 0
84+
else
85+
warn "Failed to install rsync via Scoop"
86+
return 1
87+
fi
88+
}
89+
90+
# Install rsync on Windows with automatic installation
1991
install_rsync_windows() {
2092
info "Checking rsync availability on Windows..."
2193

@@ -26,30 +98,66 @@ install_rsync_windows() {
2698

2799
warn "rsync is not installed on your system"
28100

29-
# Check if Git for Windows is available
30-
if has_git_for_windows; then
31-
info "Git for Windows is installed but rsync is missing"
32-
info "rsync should be included in Git for Windows by default"
33-
warn "Try running this command from Git Bash instead of Command Prompt/PowerShell"
34-
error "Please run ShipNode from Git Bash to access rsync"
101+
# If in Git Bash or WSL, guide user
102+
if ! is_native_windows; then
103+
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then
104+
info "You are running in Git Bash"
105+
info "rsync should be available in Git for Windows"
106+
warn "Try running: pacman -S rsync"
107+
echo ""
108+
echo "Or reinstall Git for Windows with rsync option enabled"
109+
elif [[ -n "$WSL_DISTRO_NAME" ]]; then
110+
info "You are running in WSL"
111+
info "Installing rsync via apt..."
112+
sudo apt update && sudo apt install -y rsync
113+
114+
if has_rsync; then
115+
success "rsync installed in WSL"
116+
return 0
117+
fi
118+
fi
119+
120+
error "Failed to install rsync. Please install it manually and try again."
35121
fi
36122

37-
# Git for Windows not found
38-
warn "rsync is required for deployment"
123+
# Native Windows (PowerShell/CMD) - try automatic installation
124+
info "Attempting automatic installation..."
125+
126+
# Try Chocolatey first (more common)
127+
if install_rsync_choco; then
128+
if has_rsync; then
129+
success "rsync is now available!"
130+
return 0
131+
fi
132+
fi
133+
134+
# Fallback to Scoop
135+
if install_rsync_scoop; then
136+
if has_rsync; then
137+
success "rsync is now available!"
138+
return 0
139+
fi
140+
fi
141+
142+
# All methods failed - show manual instructions
143+
warn "Automatic installation failed"
144+
echo ""
145+
echo "Please install rsync manually using one of these methods:"
39146
echo ""
40-
echo "To install rsync on Windows, you have two options:"
147+
echo "Option 1: Chocolatey (Recommended for Windows)"
148+
echo " 1. Open PowerShell as Administrator"
149+
echo " 2. Run: Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))"
150+
echo " 3. Run: choco install rsync -y"
41151
echo ""
42-
echo "Option 1: Git for Windows (Recommended)"
152+
echo "Option 2: Git for Windows"
43153
echo " 1. Download from: https://git-scm.com/download/win"
44-
echo " 2. Run the installer (includes rsync)"
154+
echo " 2. Run installer and select 'rsync' component"
45155
echo " 3. Use Git Bash to run ShipNode"
46156
echo ""
47-
echo "Option 2: WSL (Windows Subsystem for Linux)"
157+
echo "Option 3: WSL"
48158
echo " 1. Open PowerShell as Administrator"
49159
echo " 2. Run: wsl --install"
50-
echo " 3. Restart your computer"
51-
echo " 4. In WSL terminal: sudo apt install rsync"
52-
echo " 5. Use WSL terminal to run ShipNode"
160+
echo " 3. Restart and run: sudo apt install rsync"
53161
echo ""
54162

55163
error "Please install rsync and try again"

0 commit comments

Comments
 (0)