2018-02-27 09:32:01 +01:00
|
|
|
#!/usr/bin/env bash
|
2017-12-10 10:28:02 +01:00
|
|
|
|
|
|
|
# error codes
|
|
|
|
# 0 - exited without problems
|
2019-03-27 20:12:24 +01:00
|
|
|
# 1 - parameters not supported were used or some unexpected error occurred
|
2017-12-10 10:28:02 +01:00
|
|
|
# 2 - OS not supported by this script
|
|
|
|
# 3 - installed version of rclone is up to date
|
2018-01-06 23:11:05 +01:00
|
|
|
# 4 - supported unzip tools are not available
|
2017-12-10 10:28:02 +01:00
|
|
|
|
2017-12-04 21:58:14 +01:00
|
|
|
set -e
|
|
|
|
|
2020-05-19 13:02:44 +02:00
|
|
|
#when adding a tool to the list make sure to also add its corresponding command further in the script
|
2018-12-06 15:03:21 +01:00
|
|
|
unzip_tools_list=('unzip' '7z' 'busybox')
|
2018-01-06 23:11:05 +01:00
|
|
|
|
2022-05-12 21:19:33 +02:00
|
|
|
usage() { echo "Usage: sudo -v ; curl https://rclone.org/install.sh | sudo bash [-s beta]" 1>&2; exit 1; }
|
2017-12-04 21:58:14 +01:00
|
|
|
|
|
|
|
#check for beta flag
|
|
|
|
if [ -n "$1" ] && [ "$1" != "beta" ]; then
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$1" ]; then
|
2017-12-08 17:39:31 +01:00
|
|
|
install_beta="beta "
|
2017-12-04 21:58:14 +01:00
|
|
|
fi
|
|
|
|
|
2017-12-10 10:28:02 +01:00
|
|
|
|
2018-03-23 23:19:40 +01:00
|
|
|
#create tmp directory and move to it with macOS compatibility fallback
|
2021-03-20 13:58:59 +01:00
|
|
|
tmp_dir=$(mktemp -d 2>/dev/null || mktemp -d -t 'rclone-install.XXXXXXXXXX')
|
|
|
|
cd "$tmp_dir"
|
2017-12-10 10:28:02 +01:00
|
|
|
|
|
|
|
|
2018-01-06 23:11:05 +01:00
|
|
|
#make sure unzip tool is available and choose one to work with
|
|
|
|
set +e
|
|
|
|
for tool in ${unzip_tools_list[*]}; do
|
2021-03-20 13:58:59 +01:00
|
|
|
trash=$(hash "$tool" 2>>errors)
|
2018-01-06 23:11:05 +01:00
|
|
|
if [ "$?" -eq 0 ]; then
|
|
|
|
unzip_tool="$tool"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# exit if no unzip tools available
|
2021-03-20 13:58:59 +01:00
|
|
|
if [ -z "$unzip_tool" ]; then
|
2018-01-06 23:11:05 +01:00
|
|
|
printf "\nNone of the supported tools for extracting zip archives (${unzip_tools_list[*]}) were found. "
|
|
|
|
printf "Please install one of them and try again.\n\n"
|
|
|
|
exit 4
|
|
|
|
fi
|
|
|
|
|
2018-03-10 11:37:55 +01:00
|
|
|
# Make sure we don't create a root owned .config/rclone directory #2127
|
|
|
|
export XDG_CONFIG_HOME=config
|
|
|
|
|
2017-12-08 17:39:31 +01:00
|
|
|
#check installed version of rclone to determine if update is necessary
|
2021-03-20 13:58:59 +01:00
|
|
|
version=$(rclone --version 2>>errors | head -n 1)
|
|
|
|
if [ -z "$install_beta" ]; then
|
2021-04-12 15:18:29 +02:00
|
|
|
current_version=$(curl -fsS https://downloads.rclone.org/version.txt)
|
2017-12-08 17:39:31 +01:00
|
|
|
else
|
2021-04-12 15:18:29 +02:00
|
|
|
current_version=$(curl -fsS https://beta.rclone.org/version.txt)
|
2017-12-08 17:39:31 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$version" = "$current_version" ]; then
|
2018-01-06 23:11:05 +01:00
|
|
|
printf "\nThe latest ${install_beta}version of rclone ${version} is already installed.\n\n"
|
2017-12-10 10:28:02 +01:00
|
|
|
exit 3
|
2017-12-08 17:39:31 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
2017-12-04 21:58:14 +01:00
|
|
|
#detect the platform
|
2021-03-20 13:58:59 +01:00
|
|
|
OS="$(uname)"
|
2017-12-04 21:58:14 +01:00
|
|
|
case $OS in
|
|
|
|
Linux)
|
|
|
|
OS='linux'
|
|
|
|
;;
|
|
|
|
FreeBSD)
|
|
|
|
OS='freebsd'
|
|
|
|
;;
|
|
|
|
NetBSD)
|
|
|
|
OS='netbsd'
|
|
|
|
;;
|
|
|
|
OpenBSD)
|
|
|
|
OS='openbsd'
|
|
|
|
;;
|
|
|
|
Darwin)
|
|
|
|
OS='osx'
|
2022-05-05 18:50:22 +02:00
|
|
|
binTgtDir=/usr/local/bin
|
|
|
|
man1TgtDir=/usr/local/share/man/man1
|
2017-12-04 21:58:14 +01:00
|
|
|
;;
|
|
|
|
SunOS)
|
|
|
|
OS='solaris'
|
|
|
|
echo 'OS not supported'
|
2017-12-10 10:28:02 +01:00
|
|
|
exit 2
|
2017-12-04 21:58:14 +01:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo 'OS not supported'
|
2017-12-10 10:28:02 +01:00
|
|
|
exit 2
|
2017-12-04 21:58:14 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2021-03-20 13:58:59 +01:00
|
|
|
OS_type="$(uname -m)"
|
|
|
|
case "$OS_type" in
|
2017-12-04 21:58:14 +01:00
|
|
|
x86_64|amd64)
|
|
|
|
OS_type='amd64'
|
|
|
|
;;
|
|
|
|
i?86|x86)
|
|
|
|
OS_type='386'
|
|
|
|
;;
|
2021-03-31 22:02:55 +02:00
|
|
|
aarch64|arm64)
|
|
|
|
OS_type='arm64'
|
|
|
|
;;
|
2022-10-21 09:54:16 +02:00
|
|
|
armv7*)
|
|
|
|
OS_type='arm-v7'
|
|
|
|
;;
|
2022-11-04 00:15:03 +01:00
|
|
|
armv6*)
|
|
|
|
OS_type='arm-v6'
|
|
|
|
;;
|
2017-12-04 21:58:14 +01:00
|
|
|
arm*)
|
|
|
|
OS_type='arm'
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo 'OS type not supported'
|
2017-12-10 10:28:02 +01:00
|
|
|
exit 2
|
2017-12-04 21:58:14 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
|
|
#download and unzip
|
2021-03-20 13:58:59 +01:00
|
|
|
if [ -z "$install_beta" ]; then
|
|
|
|
download_link="https://downloads.rclone.org/rclone-current-${OS}-${OS_type}.zip"
|
|
|
|
rclone_zip="rclone-current-${OS}-${OS_type}.zip"
|
2017-12-04 21:58:14 +01:00
|
|
|
else
|
2021-03-20 13:58:59 +01:00
|
|
|
download_link="https://beta.rclone.org/rclone-beta-latest-${OS}-${OS_type}.zip"
|
|
|
|
rclone_zip="rclone-beta-latest-${OS}-${OS_type}.zip"
|
2017-12-04 21:58:14 +01:00
|
|
|
fi
|
|
|
|
|
2021-04-12 15:18:29 +02:00
|
|
|
curl -OfsS "$download_link"
|
2017-12-04 21:58:14 +01:00
|
|
|
unzip_dir="tmp_unzip_dir_for_rclone"
|
2018-01-06 23:11:05 +01:00
|
|
|
# there should be an entry in this switch for each element of unzip_tools_list
|
2021-03-20 13:58:59 +01:00
|
|
|
case "$unzip_tool" in
|
2018-01-06 23:11:05 +01:00
|
|
|
'unzip')
|
2021-03-20 13:58:59 +01:00
|
|
|
unzip -a "$rclone_zip" -d "$unzip_dir"
|
2018-01-06 23:11:05 +01:00
|
|
|
;;
|
|
|
|
'7z')
|
2021-03-20 13:58:59 +01:00
|
|
|
7z x "$rclone_zip" "-o$unzip_dir"
|
2018-01-06 23:11:05 +01:00
|
|
|
;;
|
2018-11-19 05:13:31 +01:00
|
|
|
'busybox')
|
2021-03-20 13:58:59 +01:00
|
|
|
mkdir -p "$unzip_dir"
|
|
|
|
busybox unzip "$rclone_zip" -d "$unzip_dir"
|
2018-11-19 05:13:31 +01:00
|
|
|
;;
|
2018-01-06 23:11:05 +01:00
|
|
|
esac
|
2017-12-04 21:58:14 +01:00
|
|
|
|
2021-03-20 13:58:59 +01:00
|
|
|
cd $unzip_dir/*
|
2018-01-06 23:11:05 +01:00
|
|
|
|
2019-03-27 20:12:24 +01:00
|
|
|
#mounting rclone to environment
|
2017-12-04 21:58:14 +01:00
|
|
|
|
2021-03-20 13:58:59 +01:00
|
|
|
case "$OS" in
|
2017-12-04 21:58:14 +01:00
|
|
|
'linux')
|
|
|
|
#binary
|
2018-02-02 14:23:58 +01:00
|
|
|
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
|
2021-03-20 13:58:59 +01:00
|
|
|
#manual
|
2019-05-12 13:44:51 +02:00
|
|
|
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
|
2017-12-04 21:58:14 +01:00
|
|
|
;;
|
|
|
|
'freebsd'|'openbsd'|'netbsd')
|
2021-03-20 13:58:59 +01:00
|
|
|
#binary
|
2018-02-02 14:23:58 +01:00
|
|
|
cp rclone /usr/bin/rclone.new
|
|
|
|
chown root:wheel /usr/bin/rclone.new
|
|
|
|
mv /usr/bin/rclone.new /usr/bin/rclone
|
2021-03-20 13:58:59 +01:00
|
|
|
#manual
|
2017-12-04 21:58:14 +01:00
|
|
|
mkdir -p /usr/local/man/man1
|
|
|
|
cp rclone.1 /usr/local/man/man1/
|
|
|
|
makewhatis
|
|
|
|
;;
|
|
|
|
'osx')
|
|
|
|
#binary
|
2022-05-05 18:50:22 +02:00
|
|
|
mkdir -m 0555 -p ${binTgtDir}
|
|
|
|
cp rclone ${binTgtDir}/rclone.new
|
|
|
|
mv ${binTgtDir}/rclone.new ${binTgtDir}/rclone
|
|
|
|
chmod a=x ${binTgtDir}/rclone
|
2017-12-04 21:58:14 +01:00
|
|
|
#manual
|
2022-05-05 18:50:22 +02:00
|
|
|
mkdir -m 0555 -p ${man1TgtDir}
|
|
|
|
cp rclone.1 ${man1TgtDir}
|
|
|
|
chmod a=r ${man1TgtDir}/rclone.1
|
2017-12-04 21:58:14 +01:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo 'OS not supported'
|
2017-12-10 10:28:02 +01:00
|
|
|
exit 2
|
2017-12-04 21:58:14 +01:00
|
|
|
esac
|
|
|
|
|
2023-11-20 09:05:42 +01:00
|
|
|
#cleanup
|
|
|
|
rm -rf "$tmp_dir"
|
2017-12-04 21:58:14 +01:00
|
|
|
|
2018-02-20 14:03:50 +01:00
|
|
|
#update version variable post install
|
2021-03-20 13:58:59 +01:00
|
|
|
version=$(rclone --version 2>>errors | head -n 1)
|
2018-02-20 14:03:50 +01:00
|
|
|
|
|
|
|
printf "\n${version} has successfully installed."
|
2018-01-06 23:11:05 +01:00
|
|
|
printf '\nNow run "rclone config" for setup. Check https://rclone.org/docs/ for more details.\n\n'
|
2017-12-04 21:58:14 +01:00
|
|
|
exit 0
|