fix: make rclone install script usable
parent
5dd0dbc469
commit
e548e54338
|
@ -1,171 +1,29 @@
|
||||||
#!/bin/bash
|
sudo rclone.bin
|
||||||
|
chmod 775 rclone.bin
|
||||||
rclone_install () {
|
touch $INSTALL_DIR/rclone
|
||||||
|
touch $INSTALL_DIR/rclone.conf
|
||||||
local INSTALL_DIR="/opt"
|
mkdir $INSTALL_DIR/cache 2> /dev/null || true
|
||||||
local BIN_DIR="/opt/bin"
|
echo '#!/bin/bash' > $INSTALL_DIR/rclone
|
||||||
local FORCE=false
|
CMD=$(echo $INSTALL_DIR/rclone.bin \
|
||||||
local VERSION=current
|
--config=$INSTALL_DIR/rclone.conf \
|
||||||
|
--cache-dir=$INSTALL_DIR/cache \
|
||||||
declare OPTION
|
'$@' \
|
||||||
declare OPTARG
|
|
||||||
declare OPTIND
|
|
||||||
|
|
||||||
while getopts 'i:b:v:f' OPTION; do
|
|
||||||
case "$OPTION" in
|
|
||||||
i)
|
|
||||||
INSTALL_DIR=$OPTARG
|
|
||||||
;;
|
|
||||||
b)
|
|
||||||
BIN_DIR=$OPTARG
|
|
||||||
;;
|
|
||||||
|
|
||||||
v)
|
|
||||||
echo "Installing Beta"
|
|
||||||
VERSION=$OPTARG
|
|
||||||
;;
|
|
||||||
f)
|
|
||||||
echo "FORCING download/overwrite"
|
|
||||||
FORCE=true
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
shift $(( OPTIND - 1 ))
|
|
||||||
|
|
||||||
# error codes
|
|
||||||
# 0 - exited without problems
|
|
||||||
# 1 - parameters not supported were used or some unexpected error occurred
|
|
||||||
# 2 - OS or Architecture not supported by this script
|
|
||||||
# 3 - installed version of rclone is up to date
|
|
||||||
# 4 - supported unzip tools are not available
|
|
||||||
# 5 - unable to install without sudo permission
|
|
||||||
|
|
||||||
[[ ! -w "$INSTALL_DIR" ]] && echo $INSTALL is not writable by user $USER, can\'t install there && exit 5
|
|
||||||
[[ ! -w "$BIN_DIR" ]] && echo $BIN_DIR is not writable by user $USER, won\'t be able to link binary there && exit 5
|
|
||||||
INSTALL_DIR=$INSTALL_DIR/rclone
|
|
||||||
# if [[ $EUID != 0 ]]; then
|
|
||||||
# sudo "$0" "$@"
|
|
||||||
# exit $?
|
|
||||||
# fi
|
|
||||||
|
|
||||||
#detect the platform
|
|
||||||
set +e
|
|
||||||
|
|
||||||
OS="`uname`"
|
|
||||||
case $OS in
|
|
||||||
Linux)
|
|
||||||
OS='linux'
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo 'Only Linux OS not supported by this script'
|
|
||||||
exit 2
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
OS_type="`uname -m`"
|
|
||||||
case $OS_type in
|
|
||||||
x86_64|amd64)
|
|
||||||
OS_type='amd64'
|
|
||||||
;;
|
|
||||||
i?86|x86)
|
|
||||||
OS_type='386'
|
|
||||||
;;
|
|
||||||
arm*)
|
|
||||||
OS_type='arm'
|
|
||||||
;;
|
|
||||||
aarch64)
|
|
||||||
OS_type='arm64'
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo 'OS architecture not supported'
|
|
||||||
exit 2
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
#when adding a tool to the list make sure to also add its corresponding command further in the script
|
|
||||||
|
|
||||||
# exit if no unzip tools available
|
|
||||||
[[ -z "unzip" ]] && printf "Please install unzip and try again.\n\n" && exit 4
|
|
||||||
|
|
||||||
# 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
|
|
||||||
# installed_version=`rclone --version 2>>errors | head -n 1`
|
|
||||||
# if [ -z "${install_beta}" ]; then
|
|
||||||
# current_version=`curl https://downloads.rclone.org/version.txt`
|
|
||||||
# else
|
|
||||||
# current_version=`curl https://beta.rclone.org/version.txt`
|
|
||||||
# fi
|
|
||||||
#
|
|
||||||
# if [ "$version" = "$current_version" ]; then
|
|
||||||
# printf "\nThe latest ${install_beta}version of rclone ${version} is already installed.\n\n"
|
|
||||||
# exit 3
|
|
||||||
# fi
|
|
||||||
|
|
||||||
echo Installing to $INSTALL_DIR
|
|
||||||
mkdir -p $INSTALL_DIR
|
|
||||||
cd $INSTALL_DIR
|
|
||||||
|
|
||||||
# mv rclone.bin rclone.bin.prev
|
|
||||||
|
|
||||||
#create tmp directory and move to it with macOS compatibility fallback
|
|
||||||
# mkdir $INSTALL_DIR/zip
|
|
||||||
# $(mktemp -d -f rclone-zip)
|
|
||||||
# cd $zip_dir
|
|
||||||
|
|
||||||
# echo made temp
|
|
||||||
#download and unzip
|
|
||||||
if [[ $VERSION = "current" ]]; then
|
|
||||||
download_link="https://downloads.rclone.org/rclone-current-$OS-$OS_type.zip"
|
|
||||||
rclone_zip="rclone-current-$OS-$OS_type.zip"
|
|
||||||
else
|
|
||||||
download_link="https://beta.rclone.org/rclone-beta-latest-$OS-$OS_type.zip"
|
|
||||||
rclone_zip="rclone-beta-latest-$OS-$OS_type.zip"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo downloading rclone binary archive $download_link
|
|
||||||
# curl -O $download_link
|
|
||||||
echo expanding archive
|
|
||||||
unzip -j -o -a $rclone_zip
|
|
||||||
mkdir -p $INSTALL_DIR/docs 2> /dev/null || true
|
|
||||||
rm $INSTALL_DIR/docs/*.* 2> /dev/null || true
|
|
||||||
echo moving documentation files to docs/
|
|
||||||
mv *.1 *.txt README.* $INSTALL_DIR/docs/ 2> /dev/null || true
|
|
||||||
# rm *.zip
|
|
||||||
echo preparing customized rclone command
|
|
||||||
rm -rf rclone.bin
|
|
||||||
mv rclone rclone.bin
|
|
||||||
chown :sudo rclone.bin
|
|
||||||
chmod 775 rclone.bin
|
|
||||||
touch $INSTALL_DIR/rclone
|
|
||||||
touch $INSTALL_DIR/rclone.conf
|
|
||||||
mkdir $INSTALL_DIR/cache 2> /dev/null || true
|
|
||||||
echo '#!/bin/bash' > $INSTALL_DIR/rclone
|
|
||||||
CMD=$(echo $INSTALL_DIR/rclone.bin \
|
|
||||||
--config=$INSTALL_DIR/rclone.conf \
|
|
||||||
--cache-dir=$INSTALL_DIR/cache \
|
|
||||||
'$@' \
|
|
||||||
)
|
)
|
||||||
echo "$CMD" >> $INSTALL_DIR/rclone
|
echo "$CMD" >> $INSTALL_DIR/rclone
|
||||||
chown :sudo rclone
|
chown :sudo rclone
|
||||||
chmod 775 rclone
|
chmod 775 rclone
|
||||||
rm $BIN_DIR/rclone
|
rm $BIN_DIR/rclone
|
||||||
ln -s $INSTALL_DIR/rclone $BIN_DIR/rclone
|
ln -s $INSTALL_DIR/rclone $BIN_DIR/rclone
|
||||||
echo -e "rclone customized command can be launched from echo where: $(command -v rclone) \n $CMD"
|
echo -e "rclone customized command can be launched from $(command -v rclone) \n $CMD"
|
||||||
cd ..
|
echo -e "uncustomized rclone can be run from $INSTALL_DIR/rclone.bin"
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
|
||||||
|
#update version variable post install
|
||||||
#update version variable post install
|
version=`rclone --version 2>>errors | head -n 1`
|
||||||
version=`rclone --version 2>>errors | head -n 1`
|
|
||||||
|
printf "\n${last_version} has successfully installed."
|
||||||
printf "\n${version} has successfully installed."
|
printf '\nNow run "rclone config" to set up remotes. Check https://rclone.org/docs/ for more details.\n\n'
|
||||||
printf '\nNow run "rclone config" for setup. Check https://rclone.org/docs/ for more details.\n\n'
|
return 0
|
||||||
exit 0
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue