forked from ohhdemgirls/PlexInTheCloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01-rclone-acd.sh
executable file
·165 lines (145 loc) · 4.56 KB
/
01-rclone-acd.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
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
#!/bin/bash
source vars
## INFO
# This script installs and configures rclone.
# Your Amazon Drive will be mounted on boot
# and encrypted/decrypted on the fly.
##
#######################
# Pre-Install
#######################
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root. Execute 'sudo su' to swap to the root user."
exit 1
fi
#######################
# Dependencies
#######################
apt-get install -y git unionfs-fuse unzip
#######################
# Install
#######################
curl -O http://downloads.rclone.org/rclone-current-linux-amd64.zip
unzip rclone-current-linux-amd64.zip
cd rclone-*-linux-amd64
cp rclone /usr/sbin/
chown root:root /usr/sbin/rclone
chmod 755 /usr/sbin/rclone
#######################
# Configure
#######################
cat << EOF
rclone config
n # New remote
AMZ # name
1 # Choose "Amazon Drive"
# press enter, leave blank for Client Id
# press enter, leave blank for Client Secret
n # press n for headless setup
# On your personal computer with rclone installed, type: rclone authorize "amazon cloud drive" (at a terminal prompt, quotes included in the command)
# Login to Amazon using the browser that rclone opened on your personal computer.
# Get the code from your Terminal window on your personal computer and copy-paste it to your remote server.
y # to accept everything, "Yes this is OK"
q # Quit
EOF
echo ''
echo "Did you add your rclone AMZ mount in previous step?"
echo ''
select yn in "Yes" "No"; do
case $yn in
Yes ) break;;
No ) echo 'You need to do that before we can move on, exiting.'; exit;;
esac
done
cat << EOF
# RCLONE ENCRYPT
rclone config
n # New remote
$encrypted # name
5 # Choose "crypt"
AMZ # remote name you set up previously + folder
2 # Choose "Encrypt the filenames"
g # Choose "Generate random password"
128 # Strength of password
y # Accept password (and write it down for backup!!!!)
g # Choose "Generate random password" for salt
128 # Strength of salt
y # Accept salt (and write it down for backup!!!!)
y # Accept everything "Yes this is OK"
q # Quit
EOF
echo ''
echo "Did you add your rclone crypt mount in previous step?"
echo ''
select yn in "Yes" "No"; do
case $yn in
Yes ) break;;
No ) echo 'You need to do that before we can move on, exiting.'; exit;;
esac
done
echo ''
echo "Did you back up/write down your password and salt?"
echo ''
select yn in "Yes" "No"; do
case $yn in
Yes ) break;;
No ) echo "It's your choice, but losing those means you'll be unable to recover any of your encrypted files."; break;;
esac
done
#######################
# Structure
#######################
mkdir -p /home/$username/$encrypted
mkdir -p /home/$username/$local
mkdir -p /home/$username/$overlayfuse
mkdir -p /home/$username/scripts
#######################
# Helper Scripts
#######################
tee "/home/$username/scripts/rcloneMount.sh" > /dev/null <<EOF
#!/bin/bash
rclone mount \
--read-only \
--allow-non-empty \
--dir-cache-time 1m \
--acd-templink-threshold 0\
--checkers 16 \
--no-check-certificate \
--quiet \
--stats 0 \
$encrypted: /home/$username/$encrypted/ &
sleep 3s
unionfs-fuse -o cow,max_readahead=2000000000 /home/$username/$local=RW:/home/$username/$encrypted=RO /home/$username/$overlayfuse
EOF
#######################
# Systemd Service File
#######################
tee "/etc/systemd/system/rcloneMount.service" > /dev/null <<EOF
[Unit]
Description=Mount Amazon Cloud Drive
Documentation=https://acd-cli.readthedocs.org/en/latest/
After=network-online.target
[Service]
Type=forking
User=$username
ExecStart=/bin/bash /home/$username/scripts/rcloneMount.sh
ExecStop=/bin/umount /home/$username/$encrypted
ExecStop=/bin/umount /home/$username/$overlayfuse
Restart=on-abort
[Install]
WantedBy=default.target
EOF
#######################
# Permissions
#######################
chmod +x /home/$username/scripts
chown -R $username:$username /home/$username/scripts
chown -R $username:$username /home/$username/$local
chown -R $username:$username /home/$username/$encrypted
chown -R $username:$username /home/$username/$overlayfuse
#######################
# Autostart
#######################
systemctl daemon-reload
systemctl start rcloneMount.service
systemctl enable rcloneMount.service