-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·251 lines (215 loc) · 7.81 KB
/
setup.sh
File metadata and controls
executable file
·251 lines (215 loc) · 7.81 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#!/bin/bash
set -e
# Colors and Styling
BOLD=$(tput bold)
RESET=$(tput sgr0)
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
BLUE=$(tput setaf 4)
YELLOW=$(tput setaf 3)
APP_NAME="shufflekeys"
BIN_NAME="shufflekeys"
INSTALL_DIR="/usr/local/bin"
CONFIG_DIR="$HOME/.config/shufflekeys"
header() {
echo -e "
${BLUE}${BOLD}=== $1 ===${RESET}"
}
info() {
echo -e "${BOLD}INFO:${RESET} $1"
}
success() {
echo -e "${GREEN}${BOLD}SUCCESS:${RESET} $1"
}
warn() {
echo -e "${YELLOW}${BOLD}WARNING:${RESET} $1"
}
error() {
echo -e "${RED}${BOLD}ERROR:${RESET} $1"
}
ask_yes_no() {
while true; do
read -p "$1 [Y/n] " yn
case $yn in
[Yy]* ) return 0;;
[Nn]* ) return 1;;
"" ) return 0;;
* ) echo "Please answer yes or no.";;
esac
done
}
# -----------------------------------------------------------------------------
# 1. Welcome
# -----------------------------------------------------------------------------
clear
echo -e "${BLUE}${BOLD}"
echo " _____ _ __ __ _ __ __"
echo " / ___/| |__ _ _ / _|/ _| | ___| | | ___ _ _ ___"
echo " \___ \| '_ \| | | | |_| |_| |/ _ \ .-. |/ _ \ | | / __|"
echo " ___) | | | | |_| | _| _| | __/ | | | __/ |_| \__ "
echo " |____/|_| |_|\__,_|_| |_| |_|\___|_| |_|\___|\__, |___/"
echo " |___/"
echo -e "${RESET}"
echo "Welcome to the ${BOLD}ShuffleKeys${RESET} Setup Wizard!"
echo "This script will help you build, install, and configure ShuffleKeys."
echo "OS Detected: $(uname -s)"
echo ""
# -----------------------------------------------------------------------------
# 2. Check Dependencies
# -----------------------------------------------------------------------------
header "Checking Prerequisites"
if ! command -v cargo &> /dev/null; then
error "Rust/Cargo is not installed or not in PATH."
echo "Please install Rust from https://rustup.rs/ and try again."
exit 1
fi
success "Cargo found."
# -----------------------------------------------------------------------------
# 3. Build Release
# -----------------------------------------------------------------------------
header "Building Project"
info "Compiling release binary... (this might take a minute)"
if cargo build --release; then
success "Build complete."
else
error "Build failed. Please check the error messages above."
exit 1
fi
# -----------------------------------------------------------------------------
# 4. Install Binary
# -----------------------------------------------------------------------------
header "Installation"
TARGET_BIN="./target/release/$BIN_NAME"
if ask_yes_no "Do you want to install '$BIN_NAME' to $INSTALL_DIR?"; then
info "Installing binary (requires sudo)..."
if sudo cp "$TARGET_BIN" "$INSTALL_DIR/$BIN_NAME"; then
success "Installed to $INSTALL_DIR/$BIN_NAME"
else
error "Failed to install binary."
exit 1
fi
else
info "Skipping installation. You can run it from ./target/release/$BIN_NAME"
INSTALL_DIR=$(pwd)/target/release
fi
# -----------------------------------------------------------------------------
# 5. Initial Configuration
# -----------------------------------------------------------------------------
header "Configuration"
if [ ! -f "$CONFIG_DIR/config.toml" ]; then
if ask_yes_no "Initialize default configuration at $CONFIG_DIR?"; then
mkdir -p "$CONFIG_DIR"
"$INSTALL_DIR/$BIN_NAME" init-config
success "Configuration created."
fi
else
info "Configuration already exists at $CONFIG_DIR/config.toml"
fi
# -----------------------------------------------------------------------------
# 6. Platform Specific Setup
# -----------------------------------------------------------------------------
OS="$(uname -s)"
header "Platform Setup: $OS"
if [ "$OS" == "Linux" ]; then
info "Linux setup: Checking permissions for /dev/uinput"
# Check if uinput group exists (unlikely standard, usually 'input' group owns it)
# Common rule: KERNEL=="uinput", GROUP="input", MODE="0660"
if ask_yes_no "Configure udev rules for passwordless usage (recommended)?"; then
RULE_FILE="/etc/udev/rules.d/99-shufflekeys.rules"
RULE_CONTENT='KERNEL=="uinput", GROUP="input", MODE="0660"'
info "Creating $RULE_FILE..."
echo "$RULE_CONTENT" | sudo tee "$RULE_FILE" > /dev/null
info "Adding user '$USER' to 'input' group..."
sudo usermod -aG input "$USER"
info "Reloading udev rules..."
sudo udevadm control --reload-rules && sudo udevadm trigger
success "Permissions configured."
warn "You may need to LOG OUT and LOG BACK IN for group changes to apply."
fi
elif [ "$OS" == "Darwin" ]; then
info "macOS setup: Accessibility Permissions"
echo "ShuffleKeys requires 'Accessibility' (Input Monitoring) permissions to intercept keystrokes."
echo ""
echo "1. The app will try to run now to trigger the permission prompt."
echo "2. Open System Settings -> Privacy & Security -> Accessibility."
echo "3. Ensure your Terminal (or shufflekeys binary) is checked."
echo ""
if ask_yes_no "Open System Settings now?"; then
open "x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility"
fi
fi
# -----------------------------------------------------------------------------
# 7. Service Setup (Daemon)
# -----------------------------------------------------------------------------
header "Service Setup"
if ask_yes_no "Do you want ShuffleKeys to start automatically at login?"; then
if [ "$OS" == "Linux" ]; then
# Create systemd user service
SERVICE_DIR="$HOME/.config/systemd/user"
SERVICE_FILE="$SERVICE_DIR/shufflekeys.service"
mkdir -p "$SERVICE_DIR"
cat <<EOF > "$SERVICE_FILE"
[Unit]
Description=ShuffleKeys Keystroke Obfuscation
After=network.target
[Service]
ExecStart=$INSTALL_DIR/$BIN_NAME --daemon
Restart=always
RestartSec=3
[Install]
WantedBy=default.target
EOF
info "Created $SERVICE_FILE"
systemctl --user daemon-reload
systemctl --user enable shufflekeys
success "Service enabled. It will start on next login."
if ask_yes_no "Start the service now?"; then
systemctl --user start shufflekeys
success "Service started."
fi
elif [ "$OS" == "Darwin" ]; then
# Create launchd agent
PLIST_DIR="$HOME/Library/LaunchAgents"
PLIST_FILE="$PLIST_DIR/com.user.shufflekeys.plist"
LOG_DIR="$HOME/Library/Logs/shufflekeys"
mkdir -p "$PLIST_DIR"
mkdir -p "$LOG_DIR"
cat <<EOF > "$PLIST_FILE"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.user.shufflekeys</string>
<key>ProgramArguments</key>
<array>
<string>$INSTALL_DIR/$BIN_NAME</string>
<string>--daemon</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>$LOG_DIR/shufflekeys.out.log</string>
<key>StandardErrorPath</key>
<string>$LOG_DIR/shufflekeys.err.log</string>
</dict>
</plist>
EOF
info "Created $PLIST_FILE"
launchctl load "$PLIST_FILE" 2>/dev/null || true
success "Launch agent loaded."
fi
else
info "Skipping service setup."
fi
# -----------------------------------------------------------------------------
# 8. Done
# -----------------------------------------------------------------------------
header "Setup Complete"
echo "ShuffleKeys is ready!"
echo "Usage: sudo $BIN_NAME [OPTIONS]"
echo "Check '$BIN_NAME --help' for more info."
echo ""
echo -e "${GREEN}${BOLD}Enjoy your privacy!${RESET}"