-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·178 lines (163 loc) · 6.54 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·178 lines (163 loc) · 6.54 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
#!/usr/bin/env bash
# SPDX-License-Identifier: GPL-3.0-or-later
set -euo pipefail
readonly minimum_safe_rclone='v1.76.0'
readonly minimum_safe_beta_build=10204
umask 022
project_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
bin_dir="${HOME}/.local/bin"
libexec_dir="${HOME}/.local/libexec"
applications_dir="${HOME}/.local/share/applications"
config_dir="${HOME}/.config"
real_rclone="${libexec_dir}/rclone-bin"
mount_dir='/pdrive'
enable_proton_cli_updater=false
usage() {
printf '%s\n' \
'Usage: ./install.sh [--with-proton-cli-updater]' \
'' \
'Installs or updates the user-local helpers, systemd units and docs.' \
'Installs the pinned, source-published PDrive rclone build when the local' \
'binary is missing or lacks the required Proton data limiter. Configuration,' \
'cache, logs and a running mount are never overwritten or restarted.' \
'' \
'--with-proton-cli-updater also enable the optional official Proton' \
' Drive CLI update timer.' \
'-h, --help only show this help.'
}
case "${1:-}" in
'')
(( $# == 0 )) || { usage >&2; exit 2; }
;;
--with-proton-cli-updater)
(( $# == 1 )) || { usage >&2; exit 2; }
enable_proton_cli_updater=true
;;
-h|--help)
(( $# == 1 )) || { usage >&2; exit 2; }
usage
exit 0
;;
*)
printf 'Unknown option: %s\n\n' "$1" >&2
usage >&2
exit 2
;;
esac
rclone_upload_retry_safe() {
local candidate="$1" first_line version base beta_suffix beta_build newest
[[ -x "${candidate}" ]] || return 1
first_line="$("${candidate}" version 2>/dev/null | head -n 1)" || return 1
version="${first_line#rclone }"
if [[ ! "${version}" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)(-beta\.([0-9]+)\.[^[:space:]]+)?$ ]]; then
return 1
fi
base="v${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${BASH_REMATCH[3]}"
beta_suffix="${BASH_REMATCH[4]:-}"
beta_build="${BASH_REMATCH[5]:-0}"
newest="$(printf '%s\n%s\n' "${minimum_safe_rclone}" "${base}" | sort -V | tail -n 1)"
[[ "${newest}" == "${base}" ]] || return 1
[[ "${base}" != "${minimum_safe_rclone}" || -z "${beta_suffix}" \
|| "${beta_build}" -ge "${minimum_safe_beta_build}" ]]
}
rclone_ready() {
local candidate="$1"
rclone_upload_retry_safe "${candidate}" || return 1
"${candidate}" help backend protondrive >/dev/null 2>&1 || return 1
"${candidate}" backend help protondrive 2>/dev/null \
| grep -q '^### data-bandwidth$'
}
missing_commands=()
for command_name in bash curl findmnt flock fusermount3 jq mountpoint openssl \
python3 secret-tool ss sudo systemctl timeout; do
command -v "${command_name}" >/dev/null 2>&1 || missing_commands+=("${command_name}")
done
if (( ${#missing_commands[@]} != 0 )); then
printf 'Missing required commands: %s\n' "${missing_commands[*]}" >&2
printf 'Run bin/pdrive-platform --manual-setup for this distribution, then retry.\n' >&2
exit 69
fi
if ! python3 -c \
"import gi; import cairo; gi.require_foreign('cairo'); gi.require_version('Gtk', '3.0'); from gi.repository import Gtk" \
>/dev/null 2>&1; then
printf '%s\n' \
'Missing GTK/Cairo Python bindings for PDrive Control Center.' \
'Debian/Ubuntu: python3-gi python3-gi-cairo gir1.2-gtk-3.0' \
'Arch Linux: python-gobject python-cairo gtk3' >&2
exit 69
fi
if ! python3 -c \
"import gi; gi.require_version('AyatanaAppIndicator3', '0.1'); from gi.repository import AyatanaAppIndicator3" \
>/dev/null 2>&1; then
printf '%s\n' \
'Missing Ayatana AppIndicator binding for the PDrive tray.' \
'Debian/Ubuntu: gir1.2-ayatanaappindicator3-0.1' \
'Arch Linux: libayatana-appindicator' >&2
exit 69
fi
if [[ -L "${mount_dir}" ]]; then
printf 'Refusing symlink mountpoint: %s\n' "${mount_dir}" >&2
exit 73
fi
if mountpoint -q -- "${mount_dir}"; then
mounted_fstype="$(findmnt -rn -M "${mount_dir}" -o FSTYPE 2>/dev/null || true)"
case "${mounted_fstype}" in
fuse.rclone|fuse) ;;
*)
printf 'Refusing unexpected filesystem at %s (%s).\n' \
"${mount_dir}" "${mounted_fstype:-unknown}" >&2
exit 73
;;
esac
else
sudo install -d -m 0700 -o "$(id -un)" -g "$(id -gn)" "${mount_dir}"
fi
if [[ ! -d "${mount_dir}" \
|| "$(stat -c %u -- "${mount_dir}" 2>/dev/null || true)" != "$(id -u)" ]]; then
printf 'Mountpoint is not a real directory owned by this user: %s\n' "${mount_dir}" >&2
exit 73
fi
mkdir -p -- "${libexec_dir}" "${config_dir}"
if ! rclone_ready "${real_rclone}"; then
PDRIVE_REAL_RCLONE="${real_rclone}" \
"${project_dir}/bin/pdrive-prerequisites" --install-rclone
fi
"${project_dir}/packaging/install-static.sh" --layout user --destdir "${HOME}"
if command -v update-desktop-database >/dev/null 2>&1; then
update-desktop-database "${applications_dir}" >/dev/null 2>&1 || true
fi
create_default() {
local path="$1"
local line="$2"
if [[ ! -e "${path}" ]]; then
printf '%s\n' '# Managed by proton-drive-linux; do not source as shell code.' "${line}" > "${path}"
chmod 0600 "${path}"
fi
}
create_default "${config_dir}/pdrive-bwlimit.conf" 'bwlimit=off'
create_default "${config_dir}/pdrive-cache.conf" 'cache_max_age_hours=24'
create_default "${config_dir}/pdrive-recovery.conf" 'proton_metadata_cache=false'
create_default "${config_dir}/pdrive-draft-recovery.conf" 'replace_existing_draft=false'
create_default "${config_dir}/pdrive-transfers.conf" 'transfers=4'
systemctl --user daemon-reload
systemctl --user enable rclone-selfupdate.timer >/dev/null
if [[ -r "${HOME}/.config/rclone/rclone.conf" ]]; then
systemctl --user enable --now rclone-proton-drive.service pdrive-watch.timer \
pdrive-draft-recovery.timer >/dev/null
fi
if [[ "${enable_proton_cli_updater}" == true ]]; then
systemctl --user enable proton-drive-update.timer >/dev/null
fi
printf '%s\n' \
'proton-drive-linux installed.' \
'No running rclone process or transfer was restarted.' \
'Open “PDrive Control Center” from the desktop menu or run pdrive-ui.'
if [[ ! -e "${HOME}/.config/rclone/rclone.conf" ]]; then
printf '%s\n' 'Next: open PDrive Control Center for guided setup, or run pdrive-setup --setup.'
else
printf '%s\n' 'Existing encrypted configuration retained. Check with pdrive-doctor.'
fi
case ":${PATH}:" in
*:"${bin_dir}":*) ;;
*) printf 'Note: add %s to PATH to invoke the helpers by name.\n' "${bin_dir}" ;;
esac