-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
326 lines (261 loc) · 8.92 KB
/
install.sh
File metadata and controls
326 lines (261 loc) · 8.92 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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
#!/bin/bash
# SPDX-License-Identifier: PMPL-1.0-or-later
# Cloud Sync Tuner - Install Script
# Installs cloud-sync-tuner and all components
set -euo pipefail
VERSION="1.0.0"
PREFIX="${PREFIX:-$HOME/.local}"
BINDIR="${PREFIX}/bin"
DATADIR="${PREFIX}/share/cloud-sync-tuner"
SYSTEMD_USER_DIR="${HOME}/.config/systemd/user"
NAUTILUS_EXT_DIR="${HOME}/.local/share/nautilus-python/extensions"
DOLPHIN_SVC_DIR="${HOME}/.local/share/kservices5/ServiceMenus"
SELINUX_DIR="/etc/selinux/targeted/policy"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
info() { echo -e "${BLUE}[INFO]${NC} $1"; }
success() { echo -e "${GREEN}[OK]${NC} $1"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
error() { echo -e "${RED}[ERROR]${NC} $1"; exit 1; }
check_deps() {
info "Checking dependencies..."
local missing=()
command -v rclone >/dev/null 2>&1 || missing+=("rclone")
command -v systemctl >/dev/null 2>&1 || missing+=("systemd")
command -v gnatmake >/dev/null 2>&1 || missing+=("gnat (Ada compiler)")
if [[ ${#missing[@]} -gt 0 ]]; then
error "Missing dependencies: ${missing[*]}"
fi
success "All dependencies found"
}
build_ada() {
info "Building cloud-sync-tuner (Ada)..."
cd src
gnatmake -O2 -gnatn cloud_sync_tuner.adb -o cloud-sync-tuner
cd ..
success "Built cloud-sync-tuner"
}
build_overlay_daemon() {
info "Building overlay daemon (Rust)..."
if command -v cargo >/dev/null 2>&1; then
cd overlay-daemon
cargo build --release
cd ..
success "Built cloud-sync-overlay"
else
warn "Rust/Cargo not found - skipping overlay daemon"
fi
}
install_binaries() {
info "Installing binaries to ${BINDIR}..."
mkdir -p "${BINDIR}"
# Main TUI
install -m 755 src/cloud-sync-tuner "${BINDIR}/"
# Overlay daemon (if built)
if [[ -f overlay-daemon/target/release/cloud-sync-overlay ]]; then
install -m 755 overlay-daemon/target/release/cloud-sync-overlay "${BINDIR}/"
fi
# Health check script
install -m 755 scripts/cloud-sync-status "${BINDIR}/"
success "Installed binaries"
}
install_systemd_services() {
info "Installing systemd user services..."
mkdir -p "${SYSTEMD_USER_DIR}"
# Overlay daemon service
if [[ -f overlay-daemon/cloud-sync-overlay.service ]]; then
install -m 644 overlay-daemon/cloud-sync-overlay.service "${SYSTEMD_USER_DIR}/"
fi
# Watchdog service for error recovery
install -m 644 systemd/cloud-sync-watchdog.service "${SYSTEMD_USER_DIR}/"
install -m 644 systemd/cloud-sync-watchdog.timer "${SYSTEMD_USER_DIR}/"
# Reload systemd
systemctl --user daemon-reload
success "Installed systemd services"
}
install_file_manager_extensions() {
info "Installing file manager extensions..."
# Nautilus (GNOME)
if command -v nautilus >/dev/null 2>&1; then
mkdir -p "${NAUTILUS_EXT_DIR}"
install -m 644 nautilus-extension/cloud_sync_overlay.py "${NAUTILUS_EXT_DIR}/"
success "Installed Nautilus extension"
fi
# Dolphin (KDE)
if command -v dolphin >/dev/null 2>&1; then
mkdir -p "${DOLPHIN_SVC_DIR}"
install -m 644 dolphin-extension/cloud_sync_overlay.desktop "${DOLPHIN_SVC_DIR}/"
success "Installed Dolphin extension"
fi
}
install_selinux_policy() {
info "Installing SELinux policy..."
if ! command -v semodule >/dev/null 2>&1; then
warn "SELinux not available - skipping policy installation"
return
fi
if ! selinuxenabled 2>/dev/null; then
warn "SELinux disabled - skipping policy installation"
return
fi
cd selinux
if [[ -f cloud_sync_tuner.pp ]]; then
sudo semodule -i cloud_sync_tuner.pp
success "Installed SELinux policy"
else
warn "SELinux policy not compiled - run 'make' in selinux/ first"
fi
cd ..
}
install_auditd_rules() {
info "Installing auditd rules..."
if ! command -v auditctl >/dev/null 2>&1; then
warn "auditd not available - skipping audit rules"
return
fi
if [[ -f audit/cloud-sync-tuner.rules ]]; then
sudo install -m 644 audit/cloud-sync-tuner.rules /etc/audit/rules.d/
sudo augenrules --load 2>/dev/null || warn "Could not reload audit rules"
success "Installed auditd rules"
fi
}
install_man_page() {
info "Installing man page..."
local mandir="${PREFIX}/share/man/man1"
mkdir -p "${mandir}"
if [[ -f man/cloud-sync-tuner.1 ]]; then
install -m 644 man/cloud-sync-tuner.1 "${mandir}/"
success "Installed man page"
fi
}
install_config() {
info "Installing default configuration..."
local config_dir="${HOME}/.config/cloud-sync-tuner"
mkdir -p "${config_dir}"
if [[ ! -f "${config_dir}/config.toml" ]]; then
install -m 644 config/config.toml.example "${config_dir}/config.toml"
success "Installed default config"
else
warn "Config exists - not overwriting"
fi
}
create_offline_dir() {
info "Creating offline sync directory..."
local offline_dir="${HOME}/Offline"
mkdir -p "${offline_dir}"/{Dropbox,GoogleDrive,OneDrive}
success "Created ${offline_dir}"
}
enable_services() {
info "Enabling services..."
# Enable watchdog
systemctl --user enable --now cloud-sync-watchdog.timer 2>/dev/null || true
# Enable overlay daemon if installed
if [[ -f "${SYSTEMD_USER_DIR}/cloud-sync-overlay.service" ]]; then
systemctl --user enable cloud-sync-overlay.service 2>/dev/null || true
fi
success "Enabled services"
}
print_summary() {
echo
echo -e "${GREEN}═══════════════════════════════════════════════════════════${NC}"
echo -e "${GREEN} Cloud Sync Tuner ${VERSION} installed successfully!${NC}"
echo -e "${GREEN}═══════════════════════════════════════════════════════════${NC}"
echo
echo "Commands:"
echo " cloud-sync-tuner Launch TUI"
echo " cloud-sync-tuner writes Apply writes mode"
echo " cloud-sync-status Check sync health"
echo
echo "Next steps:"
echo " 1. Configure rclone remotes: rclone config"
echo " 2. Run the TUI: cloud-sync-tuner"
echo " 3. Apply configuration: press [A] in TUI"
echo
echo "Documentation:"
echo " man cloud-sync-tuner"
echo
}
uninstall() {
info "Uninstalling cloud-sync-tuner..."
# Stop services
systemctl --user stop cloud-sync-watchdog.timer 2>/dev/null || true
systemctl --user stop cloud-sync-overlay.service 2>/dev/null || true
systemctl --user disable cloud-sync-watchdog.timer 2>/dev/null || true
systemctl --user disable cloud-sync-overlay.service 2>/dev/null || true
# Remove binaries
rm -f "${BINDIR}/cloud-sync-tuner"
rm -f "${BINDIR}/cloud-sync-overlay"
rm -f "${BINDIR}/cloud-sync-status"
# Remove services
rm -f "${SYSTEMD_USER_DIR}/cloud-sync-overlay.service"
rm -f "${SYSTEMD_USER_DIR}/cloud-sync-watchdog.service"
rm -f "${SYSTEMD_USER_DIR}/cloud-sync-watchdog.timer"
# Remove extensions
rm -f "${NAUTILUS_EXT_DIR}/cloud_sync_overlay.py"
rm -f "${DOLPHIN_SVC_DIR}/cloud_sync_overlay.desktop"
# Remove man page
rm -f "${PREFIX}/share/man/man1/cloud-sync-tuner.1"
# Remove SELinux policy
if command -v semodule >/dev/null 2>&1; then
sudo semodule -r cloud_sync_tuner 2>/dev/null || true
fi
# Remove audit rules
sudo rm -f /etc/audit/rules.d/cloud-sync-tuner.rules 2>/dev/null || true
systemctl --user daemon-reload
success "Uninstalled cloud-sync-tuner"
echo
echo "Config preserved at: ~/.config/cloud-sync-tuner/"
echo "Remove manually if not needed."
}
usage() {
echo "Usage: $0 [OPTIONS]"
echo
echo "Options:"
echo " --prefix PATH Install prefix (default: ~/.local)"
echo " --uninstall Remove cloud-sync-tuner"
echo " --help Show this help"
echo
}
main() {
echo
echo -e "${BLUE}Cloud Sync Tuner Installer${NC}"
echo
while [[ $# -gt 0 ]]; do
case $1 in
--prefix)
PREFIX="$2"
BINDIR="${PREFIX}/bin"
shift 2
;;
--uninstall)
uninstall
exit 0
;;
--help|-h)
usage
exit 0
;;
*)
error "Unknown option: $1"
;;
esac
done
check_deps
build_ada
build_overlay_daemon
install_binaries
install_systemd_services
install_file_manager_extensions
install_selinux_policy
install_auditd_rules
install_man_page
install_config
create_offline_dir
enable_services
print_summary
}
main "$@"