github.com/ncw/rclone@v1.48.1-0.20190724201158-a35aa1360e3e/docs/content/install.sh (about) 1 #!/usr/bin/env bash 2 3 # error codes 4 # 0 - exited without problems 5 # 1 - parameters not supported were used or some unexpected error occurred 6 # 2 - OS not supported by this script 7 # 3 - installed version of rclone is up to date 8 # 4 - supported unzip tools are not available 9 10 set -e 11 12 #when adding a tool to the list make sure to also add it's corresponding command further in the script 13 unzip_tools_list=('unzip' '7z' 'busybox') 14 15 usage() { echo "Usage: curl https://rclone.org/install.sh | sudo bash [-s beta]" 1>&2; exit 1; } 16 17 #check for beta flag 18 if [ -n "$1" ] && [ "$1" != "beta" ]; then 19 usage 20 fi 21 22 if [ -n "$1" ]; then 23 install_beta="beta " 24 fi 25 26 27 #create tmp directory and move to it with macOS compatibility fallback 28 tmp_dir=`mktemp -d 2>/dev/null || mktemp -d -t 'rclone-install'`; cd $tmp_dir 29 30 31 #make sure unzip tool is available and choose one to work with 32 set +e 33 for tool in ${unzip_tools_list[*]}; do 34 trash=`hash $tool 2>>errors` 35 if [ "$?" -eq 0 ]; then 36 unzip_tool="$tool" 37 break 38 fi 39 done 40 set -e 41 42 # exit if no unzip tools available 43 if [ -z "${unzip_tool}" ]; then 44 printf "\nNone of the supported tools for extracting zip archives (${unzip_tools_list[*]}) were found. " 45 printf "Please install one of them and try again.\n\n" 46 exit 4 47 fi 48 49 # Make sure we don't create a root owned .config/rclone directory #2127 50 export XDG_CONFIG_HOME=config 51 52 #check installed version of rclone to determine if update is necessary 53 version=`rclone --version 2>>errors | head -n 1` 54 if [ -z "${install_beta}" ]; then 55 current_version=`curl https://downloads.rclone.org/version.txt` 56 else 57 current_version=`curl https://beta.rclone.org/version.txt` 58 fi 59 60 if [ "$version" = "$current_version" ]; then 61 printf "\nThe latest ${install_beta}version of rclone ${version} is already installed.\n\n" 62 exit 3 63 fi 64 65 66 67 #detect the platform 68 OS="`uname`" 69 case $OS in 70 Linux) 71 OS='linux' 72 ;; 73 FreeBSD) 74 OS='freebsd' 75 ;; 76 NetBSD) 77 OS='netbsd' 78 ;; 79 OpenBSD) 80 OS='openbsd' 81 ;; 82 Darwin) 83 OS='osx' 84 ;; 85 SunOS) 86 OS='solaris' 87 echo 'OS not supported' 88 exit 2 89 ;; 90 *) 91 echo 'OS not supported' 92 exit 2 93 ;; 94 esac 95 96 OS_type="`uname -m`" 97 case $OS_type in 98 x86_64|amd64) 99 OS_type='amd64' 100 ;; 101 i?86|x86) 102 OS_type='386' 103 ;; 104 arm*) 105 OS_type='arm' 106 ;; 107 aarch64) 108 OS_type='arm64' 109 ;; 110 *) 111 echo 'OS type not supported' 112 exit 2 113 ;; 114 esac 115 116 117 #download and unzip 118 if [ -z "${install_beta}" ]; then 119 download_link="https://downloads.rclone.org/rclone-current-$OS-$OS_type.zip" 120 rclone_zip="rclone-current-$OS-$OS_type.zip" 121 else 122 download_link="https://beta.rclone.org/rclone-beta-latest-$OS-$OS_type.zip" 123 rclone_zip="rclone-beta-latest-$OS-$OS_type.zip" 124 fi 125 126 curl -O $download_link 127 unzip_dir="tmp_unzip_dir_for_rclone" 128 # there should be an entry in this switch for each element of unzip_tools_list 129 case $unzip_tool in 130 'unzip') 131 unzip -a $rclone_zip -d $unzip_dir 132 ;; 133 '7z') 134 7z x $rclone_zip -o$unzip_dir 135 ;; 136 'busybox') 137 mkdir -p $unzip_dir 138 busybox unzip $rclone_zip -d $unzip_dir 139 ;; 140 esac 141 142 cd $unzip_dir/* 143 144 145 #mounting rclone to environment 146 147 case $OS in 148 'linux') 149 #binary 150 cp rclone /usr/bin/rclone.new 151 chmod 755 /usr/bin/rclone.new 152 chown root:root /usr/bin/rclone.new 153 mv /usr/bin/rclone.new /usr/bin/rclone 154 #manuals 155 if ! [ -x "$(command -v mandb)" ]; then 156 echo 'mandb not found. The rclone man docs will not be installed.' 157 else 158 mkdir -p /usr/local/share/man/man1 159 cp rclone.1 /usr/local/share/man/man1/ 160 mandb 161 fi 162 ;; 163 'freebsd'|'openbsd'|'netbsd') 164 #bin 165 cp rclone /usr/bin/rclone.new 166 chown root:wheel /usr/bin/rclone.new 167 mv /usr/bin/rclone.new /usr/bin/rclone 168 #man 169 mkdir -p /usr/local/man/man1 170 cp rclone.1 /usr/local/man/man1/ 171 makewhatis 172 ;; 173 'osx') 174 #binary 175 mkdir -p /usr/local/bin 176 cp rclone /usr/local/bin/rclone.new 177 mv /usr/local/bin/rclone.new /usr/local/bin/rclone 178 #manual 179 mkdir -p /usr/local/share/man/man1 180 cp rclone.1 /usr/local/share/man/man1/ 181 ;; 182 *) 183 echo 'OS not supported' 184 exit 2 185 esac 186 187 188 #update version variable post install 189 version=`rclone --version 2>>errors | head -n 1` 190 191 printf "\n${version} has successfully installed." 192 printf '\nNow run "rclone config" for setup. Check https://rclone.org/docs/ for more details.\n\n' 193 exit 0