-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseabox.sh
135 lines (120 loc) · 3.81 KB
/
seabox.sh
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
#!/usr/bin/env bash
set -euo pipefail
# Variables
USER=seed # username
GROUP=seed # group
#
SET_DIR=/opt/seabox/sets # set files location
SA_FILE=/opt/sa/mount/1.json # service account file for auth
SA_PATH=/opt/sa/mount # service account files location
TAG="nc" # ro or nc to tag the remote as read only or no create
VFSMAX=100G # vfs-cache-max-size limit
CPORT=1 # not used
# cloudbox defaults
MOUNTNAME=google # we will be replacing this mount with the union of share drives
MOUNT_DIR=/mnt/remote # mount point of remote
MRG_DIR=/mnt/unionfs # not used
MPORT=5572 # rc port
#
# FUNCTIONS
# check dirs and clean up in case of failure
check_firstrun() {
([ ! -f temp.conf ] || rm temp.conf)
([ -d "${MOUNT_DIR}" ] || mkmounce)
}
# mountpoints
mkmounce() {
sudo mkdir ${MOUNT_DIR} && sudo chown ${USER}:${GROUP} ${MOUNT_DIR} && sudo chmod -R 775 ${MOUNT_DIR}
}
# rclone config
make_arrclone_conf() {
sed '/^\s*#.*$/d' ${SET_DIR}/"$1" |
while read -r name driveid; do
rclone config create "${name}" drive scope drive server_side_across_configs true team_drive "${driveid}" service_account_file "${SA_FILE}" service_account_file_path "${SA_PATH}" >>"/home/${USER}/.config/rclone/rclone.conf"
done
}
make_temp_conf() {
sed '/^\s*#.*$/d' ${SET_DIR}/"$1" |
while read -r name other; do
echo -n "${name}::${TAG} " >>temp.conf
done
}
mkreunion() {
rclone config create "${MOUNTNAME}" union upstreams "${REUNION}"
}
# service file editor
sysdmaker() {
sudo bash -c 'cat > /etc/systemd/system/rclone_vfs.service' <<EOF
# /etc/systemd/system/rclone_vfs.service
#########################################################################
# Title: Cloudbox: Rclone VFS Mount #
# Author(s): EnorMOZ #
# URL: https://github.com/cloudbox/cloudbox #
# -- #
# Part of the Cloudbox project: https://cloudbox.works #
#########################################################################
# GNU General Public License v3.0 #
#########################################################################
[Unit]
Description=Rclone VFS Mount
After=network-online.target
[Service]
User=${USER}
Group=${GROUP}
Type=notify
ExecStartPre=/bin/sleep 10
ExecStart=/usr/bin/rclone mount \\
--config=/home/${USER}/.config/rclone/rclone.conf \\
--allow-other \\
--allow-non-empty \\
--rc \\
--rc-addr=localhost:${MPORT} \\
--vfs-read-ahead=128M \\
--vfs-read-chunk-size=64M \\
--vfs-read-chunk-size-limit=2G \\
--vfs-cache-mode=full \\
--vfs-cache-max-age=24h \\
--vfs-cache-max-size=${VFSMAX} \\
--fast-list \\
--buffer-size=64M \\
--dir-cache-time=1h \\
--timeout=10m \\
--umask=002 \\
--syslog \\
-v \\
${MOUNTNAME}: ${MOUNT_DIR}
ExecStop=/bin/fusermount -uz ${MOUNT_DIR}
Restart=on-abort
RestartSec=5
StartLimitInterval=60s
StartLimitBurst=3
[Install]
WantedBy=default.target
EOF
}
# stop existing services
stopper() {
sudo systemctl stop rclone_vfs.service
sudo systemctl stop rclone_vfs_primer.service
sudo systemctl stop mergerfs.service
}
# start services
starter() {
sudo systemctl start rclone_vfs.service
nohup sh sudo systemctl start rclone_vfs_primer.service &>/dev/null &
sudo systemctl start mergerfs.service
}
# setlist
stopper
check_firstrun
echo "stopping mount"
make_arrclone_conf "$1"
make_temp_conf "$1"
REUNION=$(cat temp.conf)
mkreunion
sysdmaker
sudo systemctl daemon-reload
starter
rm temp.conf
echo "mounts completed"
# eof