github.com/artpar/rclone@v1.67.3/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 its corresponding command further in the script 13 unzip_tools_list=('unzip' '7z' 'busybox') 14 15 usage() { echo "Usage: sudo -v ; 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.XXXXXXXXXX') 29 cd "$tmp_dir" 30 31 32 #make sure unzip tool is available and choose one to work with 33 set +e 34 for tool in ${unzip_tools_list[*]}; do 35 trash=$(hash "$tool" 2>>errors) 36 if [ "$?" -eq 0 ]; then 37 unzip_tool="$tool" 38 break 39 fi 40 done 41 set -e 42 43 # exit if no unzip tools available 44 if [ -z "$unzip_tool" ]; then 45 printf "\nNone of the supported tools for extracting zip archives (${unzip_tools_list[*]}) were found. " 46 printf "Please install one of them and try again.\n\n" 47 exit 4 48 fi 49 50 # Make sure we don't create a root owned .config/rclone directory #2127 51 export XDG_CONFIG_HOME=config 52 53 #check installed version of rclone to determine if update is necessary 54 version=$(rclone --version 2>>errors | head -n 1) 55 if [ -z "$install_beta" ]; then 56 current_version=$(curl -fsS https://downloads.rclone.org/version.txt) 57 else 58 current_version=$(curl -fsS https://beta.rclone.org/version.txt) 59 fi 60 61 if [ "$version" = "$current_version" ]; then 62 printf "\nThe latest ${install_beta}version of rclone ${version} is already installed.\n\n" 63 exit 3 64 fi 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 binTgtDir=/usr/local/bin 85 man1TgtDir=/usr/local/share/man/man1 86 ;; 87 SunOS) 88 OS='solaris' 89 echo 'OS not supported' 90 exit 2 91 ;; 92 *) 93 echo 'OS not supported' 94 exit 2 95 ;; 96 esac 97 98 OS_type="$(uname -m)" 99 case "$OS_type" in 100 x86_64|amd64) 101 OS_type='amd64' 102 ;; 103 i?86|x86) 104 OS_type='386' 105 ;; 106 aarch64|arm64) 107 OS_type='arm64' 108 ;; 109 armv7*) 110 OS_type='arm-v7' 111 ;; 112 armv6*) 113 OS_type='arm-v6' 114 ;; 115 arm*) 116 OS_type='arm' 117 ;; 118 *) 119 echo 'OS type not supported' 120 exit 2 121 ;; 122 esac 123 124 125 #download and unzip 126 if [ -z "$install_beta" ]; then 127 download_link="https://downloads.rclone.org/rclone-current-${OS}-${OS_type}.zip" 128 rclone_zip="rclone-current-${OS}-${OS_type}.zip" 129 else 130 download_link="https://beta.rclone.org/rclone-beta-latest-${OS}-${OS_type}.zip" 131 rclone_zip="rclone-beta-latest-${OS}-${OS_type}.zip" 132 fi 133 134 curl -OfsS "$download_link" 135 unzip_dir="tmp_unzip_dir_for_rclone" 136 # there should be an entry in this switch for each element of unzip_tools_list 137 case "$unzip_tool" in 138 'unzip') 139 unzip -a "$rclone_zip" -d "$unzip_dir" 140 ;; 141 '7z') 142 7z x "$rclone_zip" "-o$unzip_dir" 143 ;; 144 'busybox') 145 mkdir -p "$unzip_dir" 146 busybox unzip "$rclone_zip" -d "$unzip_dir" 147 ;; 148 esac 149 150 cd $unzip_dir/* 151 152 #mounting rclone to environment 153 154 case "$OS" in 155 'linux') 156 #binary 157 cp rclone /usr/bin/rclone.new 158 chmod 755 /usr/bin/rclone.new 159 chown root:root /usr/bin/rclone.new 160 mv /usr/bin/rclone.new /usr/bin/rclone 161 #manual 162 if ! [ -x "$(command -v mandb)" ]; then 163 echo 'mandb not found. The rclone man docs will not be installed.' 164 else 165 mkdir -p /usr/local/share/man/man1 166 cp rclone.1 /usr/local/share/man/man1/ 167 mandb 168 fi 169 ;; 170 'freebsd'|'openbsd'|'netbsd') 171 #binary 172 cp rclone /usr/bin/rclone.new 173 chown root:wheel /usr/bin/rclone.new 174 mv /usr/bin/rclone.new /usr/bin/rclone 175 #manual 176 mkdir -p /usr/local/man/man1 177 cp rclone.1 /usr/local/man/man1/ 178 makewhatis 179 ;; 180 'osx') 181 #binary 182 mkdir -m 0555 -p ${binTgtDir} 183 cp rclone ${binTgtDir}/rclone.new 184 mv ${binTgtDir}/rclone.new ${binTgtDir}/rclone 185 chmod a=x ${binTgtDir}/rclone 186 #manual 187 mkdir -m 0555 -p ${man1TgtDir} 188 cp rclone.1 ${man1TgtDir} 189 chmod a=r ${man1TgtDir}/rclone.1 190 ;; 191 *) 192 echo 'OS not supported' 193 exit 2 194 esac 195 196 #update version variable post install 197 version=$(rclone --version 2>>errors | head -n 1) 198 199 #cleanup 200 rm -rf "$tmp_dir" 201 202 printf "\n${version} has successfully installed." 203 printf '\nNow run "rclone config" for setup. Check https://rclone.org/docs/ for more details.\n\n' 204 exit 0