-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
199 lines (165 loc) · 5.6 KB
/
Copy pathinstall.sh
File metadata and controls
199 lines (165 loc) · 5.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/usr/bin/env bash
# WarpClip Installer Script
# This script installs WarpClip components on your local macOS system
# Set to exit immediately if a command fails
set -e
# Colors for prettier output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
BLUE='\033[0;34m'
BOLD='\033[1m'
NC='\033[0m' # No Color
# Configuration
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
SRC_DIR="$SCRIPT_DIR/src"
ETC_DIR="$SCRIPT_DIR/etc"
BIN_DIR="$HOME/bin"
LAUNCH_AGENTS_DIR="$HOME/Library/LaunchAgents"
SSH_CONFIG="$HOME/.ssh/config"
PLIST_FILE="$LAUNCH_AGENTS_DIR/com.user.warpclip.plist"
VERSION="1.0.0"
TIMESTAMP=$(date +"%Y%m%d%H%M%S")
# Function to print section headers
print_header() {
echo -e "\n${BLUE}${BOLD}==== $1 ====${NC}\n"
}
# Function to print success messages
print_success() {
echo -e "${GREEN}✓ $1${NC}"
}
# Function to print warning messages
print_warning() {
echo -e "${YELLOW}⚠ $1${NC}"
}
# Function to print error messages
print_error() {
echo -e "${RED}✗ $1${NC}"
}
# Function to back up a file
backup_file() {
local file="$1"
if [ -f "$file" ]; then
local backup="${file}.${TIMESTAMP}.bak"
cp "$file" "$backup"
print_warning "Backed up existing file to: $backup"
fi
}
# Display welcome banner
cat <<EOF
${BLUE}${BOLD}
__ __ .__
/ \ / \_____ _______ ____ | | _______ ______
\ \/\/ /\__ \\_ __ \/ _ \| |/ /\__ \ \____ \\
\ / / __ \| | \( <_> ) < / __ \| |_> >
\__/\ / (____ /__| \____/|__|_ \(____ / __/
\/ \/ \/ \/|__|
${NC}
${BOLD}WarpClip Installer v${VERSION}${NC}
Seamless remote-to-local clipboard integration
EOF
# Check if running on macOS
if [[ "$OSTYPE" != "darwin"* ]]; then
print_error "This script requires macOS to run. Exiting."
exit 1
fi
# 1. Create necessary directories
print_header "Setting up directories"
if [ ! -d "$BIN_DIR" ]; then
mkdir -p "$BIN_DIR"
print_success "Created $BIN_DIR directory"
else
print_success "$BIN_DIR directory already exists"
fi
if [ ! -d "$LAUNCH_AGENTS_DIR" ]; then
mkdir -p "$LAUNCH_AGENTS_DIR"
print_success "Created $LAUNCH_AGENTS_DIR directory"
else
print_success "$LAUNCH_AGENTS_DIR directory already exists"
fi
# Make sure ~/.ssh exists
if [ ! -d "$HOME/.ssh" ]; then
mkdir -p "$HOME/.ssh"
chmod 700 "$HOME/.ssh"
print_success "Created $HOME/.ssh directory"
else
print_success "$HOME/.ssh directory already exists"
fi
# 2. Install server script
print_header "Installing WarpClip server script"
backup_file "$BIN_DIR/warpclip-server.sh"
cp "$SRC_DIR/warpclip-server.sh" "$BIN_DIR/"
chmod +x "$BIN_DIR/warpclip-server.sh"
print_success "Installed and set permissions on warpclip-server.sh"
# 3. Install client script
print_header "Installing WarpClip client script"
backup_file "$BIN_DIR/warp-copy"
cp "$SRC_DIR/warp-copy" "$BIN_DIR/"
chmod +x "$BIN_DIR/warp-copy"
print_success "Installed and set permissions on warp-copy"
# 4. Set up LaunchAgent
print_header "Setting up LaunchAgent"
backup_file "$PLIST_FILE"
# Copy plist file but replace any instances of /Users/michael with the actual home directory
sed "s|/Users/michael|$HOME|g" "$ETC_DIR/com.user.warpclip.plist" > "$PLIST_FILE"
print_success "Created LaunchAgent plist file"
# 5. Update SSH config if it doesn't already have the RemoteForward entry
print_header "Updating SSH configuration"
backup_file "$SSH_CONFIG"
if grep -q "RemoteForward 9999 localhost:8888" "$SSH_CONFIG" 2>/dev/null; then
print_warning "SSH RemoteForward already configured"
else
echo -e "\n# WarpClip SSH Configuration" >> "$SSH_CONFIG"
echo "# Added automatically by WarpClip installer on $(date)" >> "$SSH_CONFIG"
echo "Host *" >> "$SSH_CONFIG"
echo " RemoteForward 9999 localhost:8888" >> "$SSH_CONFIG"
print_success "Added RemoteForward to SSH config"
fi
# 6. Load LaunchAgent
print_header "Loading LaunchAgent"
launchctl unload "$PLIST_FILE" 2>/dev/null || true
if launchctl load "$PLIST_FILE"; then
print_success "LaunchAgent loaded successfully"
else
print_error "Failed to load LaunchAgent. You may need to load it manually."
fi
# Add PATH to include ~/bin if not already there
if [[ ":$PATH:" != *":$BIN_DIR:"* ]]; then
print_warning "$BIN_DIR is not in your PATH. Add the following to your shell profile:"
echo 'export PATH="$HOME/bin:$PATH"'
echo ""
fi
# 7. Display instructions
print_header "WarpClip Installation Complete"
cat <<EOT
${GREEN}${BOLD}Local Setup:${NC}
✓ Server script installed at: $BIN_DIR/warpclip-server.sh
✓ LaunchAgent installed at: $PLIST_FILE
✓ SSH configured for automatic port forwarding
${GREEN}${BOLD}Usage Instructions:${NC}
1. ${BLUE}${BOLD}On Remote Servers:${NC}
- Copy the warp-copy script to your remote server:
scp $BIN_DIR/warp-copy user@remote-server:~/bin/
- Make it executable:
ssh user@remote-server "chmod +x ~/bin/warp-copy"
2. ${BLUE}${BOLD}How to Use:${NC}
- On the remote server, use warp-copy to send content to your local clipboard:
cat file.txt | warp-copy
OR
warp-copy < file.txt
3. ${BLUE}${BOLD}Troubleshooting:${NC}
- Check WarpClip status:
$BIN_DIR/warpclip-server.sh status
- Check logs at:
~/.warpclip.log
~/.warpclip.debug.log
- Restart the service:
launchctl unload $PLIST_FILE
launchctl load $PLIST_FILE
- Verify SSH tunnel is working:
ssh -v user@remote-server
${GREEN}${BOLD}Enjoy using WarpClip!${NC}
EOT
# Run a status check to verify installation
echo ""
$BIN_DIR/warpclip-server.sh status || true