forked from rclone/rclone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
201 lines (175 loc) · 4.79 KB
/
install.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
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
#!/usr/bin/env bash
# error codes
# 0 - exited without problems
# 1 - parameters not supported were used or some unexpected error occurred
# 2 - OS not supported by this script
# 3 - installed version of rclone is up to date
# 4 - supported unzip tools are not available
set -e
#when adding a tool to the list make sure to also add its corresponding command further in the script
unzip_tools_list=('unzip' '7z' 'busybox')
usage() { echo "Usage: sudo -v ; curl https://raw.githubusercontent.com/Sakura-Byte/rclone/master/install.sh | sudo bash" 1>&2; exit 1; }
if [ -n "$1" ]; then
tag_name="$1"
else
tag_name=$(curl -fsS https://api.github.com/repos/Sakura-Byte/rclone/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
fi
#make sure unzip tool is available and choose one to work with
set +e
for tool in "${unzip_tools_list[@]}"; do
if command -v "$tool" >/dev/null 2>&1; then
unzip_tool="$tool"
break
fi
done
set -e
# exit if no unzip tools available
if [ -z "$unzip_tool" ]; then
printf "\nNone of the supported tools for extracting zip archives (%s) were found." "${unzip_tools_list[*]}"
printf "Please install one of them and try again.\n\n"
exit 4
fi
#create tmp directory and move to it with macOS compatibility fallback
tmp_dir=$(mktemp -d 2>/dev/null || mktemp -d -t 'rclone-install.XXXXXXXXXX')
trap 'rm -rf "$tmp_dir"' EXIT
cd "$tmp_dir"
# Make sure we don't create a root owned .config/rclone directory #2127
export XDG_CONFIG_HOME=config
#check installed version of rclone to determine if update is necessary
version=$(rclone --version 2>/dev/null | head -n1 | cut -d' ' -f2)
if [ "$version" = "$tag_name" ]; then
printf "\nThe latest version of rclone mod %s is already installed.\n\n" "${version}"
exit 3
fi
#detect the platform
OS="$(uname)"
case $OS in
Linux)
OS='linux'
echo "$PREFIX" | grep -qo "com.termux" && \
{ OS="termux"; unzip_tool="deb"; }
;;
FreeBSD)
OS='freebsd'
;;
NetBSD)
OS='netbsd'
;;
OpenBSD)
OS='openbsd'
;;
Darwin)
OS='osx'
binTgtDir=/usr/local/bin
man1TgtDir=/usr/local/share/man/man1
;;
SunOS)
OS='solaris'
echo 'OS not supported'
exit 2
;;
*)
echo 'OS not supported'
exit 2
;;
esac
OS_type="$(uname -m)"
case "$OS_type" in
x86_64|amd64)
OS_type='amd64'
;;
i?86|x86)
OS_type='386'
;;
aarch64|arm64)
OS_type='arm64'
;;
armv7*)
OS_type='arm-v7'
;;
armv6*)
OS_type='arm-v6'
;;
arm*)
OS_type='arm'
;;
*)
echo 'OS type not supported'
exit 2
;;
esac
#download and unzip
rclone_zip="rclone-${tag_name}-${OS}-${OS_type}.zip"
[ $OS = "termux" ] && rclone_zip="rclone-${tag_name}-${OS}-$(dpkg --print-architecture).deb"
download_link="https://github.com/Sakura-Byte/rclone/releases/download/${tag_name}/${rclone_zip}"
curl -fLJO "$download_link"
unzip_dir="tmp_unzip_dir_for_rclone"
# there should be an entry in this switch for each element of unzip_tools_list
case "$unzip_tool" in
'unzip')
unzip -a "$rclone_zip" -d "$unzip_dir"
;;
'7z')
7z x "$rclone_zip" "-o$unzip_dir"
;;
'busybox')
mkdir -p "$unzip_dir"
busybox unzip "$rclone_zip" -d "$unzip_dir"
;;
'deb')
mkdir -p "$unzip_dir/empty"
;;
esac
cd $unzip_dir/*
#mounting rclone to environment
case "$OS" in
'linux')
#binary
cp rclone /usr/bin/rclone.new
chmod 755 /usr/bin/rclone.new
chown root:root /usr/bin/rclone.new
mv /usr/bin/rclone.new /usr/bin/rclone
#manual
if ! [ -x "$(command -v mandb)" ]; then
echo 'mandb not found. The rclone man docs will not be installed.'
else
mkdir -p /usr/local/share/man/man1
cp rclone.1 /usr/local/share/man/man1/
mandb
fi
;;
'freebsd'|'openbsd'|'netbsd')
#binary
cp rclone /usr/bin/rclone.new
chown root:wheel /usr/bin/rclone.new
mv /usr/bin/rclone.new /usr/bin/rclone
#manual
mkdir -p /usr/local/man/man1
cp rclone.1 /usr/local/man/man1/
makewhatis
;;
'osx')
# Set binary target directory
mkdir -p "${binTgtDir}" && chmod 555 "${binTgtDir}"
cp rclone "${binTgtDir}/rclone.new"
mv "${binTgtDir}/rclone.new" "${binTgtDir}/rclone"
chmod a=x "${binTgtDir}/rclone"
# Set manual target directory
mkdir -p "${man1TgtDir}" && chmod 555 "${man1TgtDir}"
cp rclone.1 "${man1TgtDir}"
chmod a=r "${man1TgtDir}/rclone.1"
;;
'termux')
cd ../..
dpkg -i "$rclone_zip"
;;
*)
echo 'OS not supported'
exit 2
esac
# checking binary available
command -v rclone >/dev/null 2>&1 || \
{ printf "\nERROR: rclone seems not installed.\n\n"; exit 1; }
printf "\n%s has successfully installed." "$(rclone --version | head -n1)"
printf '\nNow run "rclone config" for setup. Check https://rclone.org/docs/ for more details.\n\n'
exit 0