-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopencoperlock-linux-wizard.sh
More file actions
executable file
·134 lines (118 loc) · 5.35 KB
/
Copy pathopencoperlock-linux-wizard.sh
File metadata and controls
executable file
·134 lines (118 loc) · 5.35 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
#!/usr/bin/env bash
# OpenCoperLock - Linux setup wizard.
#
# One command to set up the OpenCoperLock client tools on a Linux machine:
# curl -fsSL https://raw.githubusercontent.com/softpython2884/OpenCoperLock/main/scripts/opencoperlock-linux-wizard.sh | bash
#
# It asks for your WebDAV URL + API token once, then lets you choose to install the right-click
# "Send to OpenCoperLock" integration and/or mount your Drive as a folder (via rclone). Everything
# is per-user; no root needed (rclone/davfs install may need your package manager).
set -euo pipefail
REPO_RAW="https://raw.githubusercontent.com/softpython2884/OpenCoperLock/main/scripts/send-to"
data="${XDG_DATA_HOME:-$HOME/.local/share}/opencoperlock"
cfgdir="${XDG_CONFIG_HOME:-$HOME/.config}/opencoperlock"
mkdir -p "$data" "$cfgdir"
say() { printf '\033[36m%s\033[0m\n' "$*"; }
ok() { printf '\033[32m%s\033[0m\n' "$*"; }
warn() { printf '\033[33m%s\033[0m\n' "$*"; }
# When piped through `curl | bash`, stdin is the script, so read prompts from the terminal.
if [ -r /dev/tty ]; then exec 3</dev/tty; else exec 3<&0; fi
ask() { local p="$1" d="${2:-}" a; printf '%s' "$p" >&2; IFS= read -r a <&3 || true; printf '%s' "${a:-$d}"; }
asks() { local p="$1" a; printf '%s' "$p" >&2; IFS= read -rs a <&3 || true; printf '\n' >&2; printf '%s' "$a"; }
say "=== OpenCoperLock - Linux setup wizard ==="
echo
if [ -n "${HTTPS_PROXY:-${https_proxy:-}}" ]; then say "(using proxy ${HTTPS_PROXY:-$https_proxy})"; fi
default_base="https://copper.forgenet.fr/api/dav"
# Collect + verify the URL and token. curl goes through HTTP(S)_PROXY automatically if set.
while true; do
BASE="$(ask "WebDAV base URL [$default_base]: " "$default_base")"
BASE="${BASE%/}"
TOKEN="$(asks "Paste your OpenCoperLock API token (ocl_...): ")"
[ -n "$TOKEN" ] || { warn "No token provided."; continue; }
printf 'Checking the connection... ' >&2
code="$(curl -fsS -o /dev/null -w '%{http_code}' -u "me:$TOKEN" -X PROPFIND -H 'Depth: 0' "$BASE/" 2>/dev/null || true)"
if [ "$code" = "207" ]; then ok "OK (server reachable, token valid)."; break; fi
warn "Failed (HTTP ${code:-no response})."
case "$code" in
401) warn " -> the token is wrong or lacks read/write scope." ;;
404|405) warn " -> the URL looks off. It usually ends in /dav or /api/dav." ;;
000|"") warn " -> could not reach the host (DNS/TLS/proxy/offline?)." ;;
esac
retry="$(ask "Try again? [Y/n]: " "Y")"
case "${retry,,}" in n|no|non) warn "Aborting."; exit 1 ;; esac
done
# Save config (readable only by you).
umask 077
printf 'BASE=%q\nTOKEN=%q\n' "$BASE" "$TOKEN" > "$cfgdir/config"
chmod 600 "$cfgdir/config"
ok "Saved config to $cfgdir/config"
# Pre-create the ComputerShared space.
curl -fsS -u "me:$TOKEN" -X MKCOL "$BASE/ComputerShared/" >/dev/null 2>&1 || true
echo
say "What do you want to set up?"
echo " 1) Right-click 'Send to OpenCoperLock' (file-manager integration)"
echo " 2) Mount your Drive as a folder (via rclone)"
echo " 3) Both"
echo " 4) Nothing else (config only)"
choice="$(ask "Choice [3]: " "3")"
install_sendto() {
say "Installing the 'Send to' integration..."
# Fetch the uploader + icon from the official repo.
curl -fsSL "$REPO_RAW/linux/send.sh" -o "$data/send.sh" && chmod 0755 "$data/send.sh"
curl -fsSL "$REPO_RAW/assets/opencoperlock.png" -o "$data/opencoperlock.png" || true
local done=()
for fm in nautilus nemo; do
if [ -d "$HOME/.local/share/$fm" ] || command -v "$fm" >/dev/null 2>&1; then
mkdir -p "$HOME/.local/share/$fm/scripts"
ln -sf "$data/send.sh" "$HOME/.local/share/$fm/scripts/Send to OpenCoperLock"
done+=("$fm")
fi
done
for sm in "$HOME/.local/share/kio/servicemenus" "$HOME/.local/share/kservices5/ServiceMenus"; do
mkdir -p "$sm"
cat > "$sm/opencoperlock.desktop" <<EOF
[Desktop Entry]
Type=Service
MimeType=all/all;
Actions=sendToOpenCoperLock;
X-KDE-Priority=TopLevel
[Desktop Action sendToOpenCoperLock]
Name=Send to OpenCoperLock
Icon=$data/opencoperlock.png
Exec=$data/send.sh %F
EOF
chmod +x "$sm/opencoperlock.desktop" 2>/dev/null || true
done
ok "Send-to installed for: ${done[*]:-KDE} (right-click a file; you may need: nautilus -q / nemo -q)"
}
mount_rclone() {
if ! command -v rclone >/dev/null 2>&1; then
warn "rclone is not installed. Install it, then re-run this wizard and choose option 2."
warn " Debian/Ubuntu: sudo apt install rclone | Fedora: sudo dnf install rclone | or: curl https://rclone.org/install.sh | sudo bash"
return
fi
say "Configuring an rclone remote 'opencoperlock'..."
rclone config delete opencoperlock >/dev/null 2>&1 || true
rclone config create opencoperlock webdav url "$BASE" vendor other user me pass "$TOKEN" >/dev/null
local mnt="$HOME/OpenCoperLock"
mkdir -p "$mnt"
ok "Remote ready. Test it: rclone lsd opencoperlock:"
echo
local now
now="$(ask "Mount it now at $mnt ? [y/N]: " "N")"
if [ "${now,,}" = "y" ] || [ "${now,,}" = "o" ]; then
rclone mount opencoperlock: "$mnt" --vfs-cache-mode writes --daemon
ok "Mounted at $mnt (background). Unmount with: fusermount -u \"$mnt\""
else
echo "Mount later with:"
echo " rclone mount opencoperlock: \"$mnt\" --vfs-cache-mode writes --daemon"
fi
}
case "$choice" in
1) install_sendto ;;
2) mount_rclone ;;
4) : ;;
*) install_sendto; echo; mount_rclone ;;
esac
echo
ok "Done. Your uploads land in the 'ComputerShared' space of your Drive."