Skip to content

Instantly share code, notes, and snippets.

@Mehran
Created December 4, 2018 10:19
Show Gist options
  • Save Mehran/4cd482315702ad7701736bec5ad2301f to your computer and use it in GitHub Desktop.
Save Mehran/4cd482315702ad7701736bec5ad2301f to your computer and use it in GitHub Desktop.
Upload files to Dropbox
#!/bin/bash
### Author ###
# By : Mehran Goudarzi
# Release : 2018-12-04
# Description : File Download then Upload to Dropbox
# Version : 1.2
###############
path_to_upload() {
default_up_path="/Education"
read -p $"Enter Path to upload (Enter to default): " up_path
up_path="${up_path:-${default_up_path}}"
}
get_url() {
read -p $"Enter URL(s) For Download (Seperate by space): " download
}
download_file() {
echo -n "[*] Downloading URL(s) (Take some time ...)" >&2
mkdir /root/download && cd /root/download
wget -c $download > /dev/null 2>&1
echo " Done" >&2
}
get_dropbox_token() {
read -p $"Your Dropbox Access Token: " token
}
dependencies() {
echo -n "[*] Dependecy Check ..." >&2
command -v git > /dev/null 2>&1 || { apt-get update >/dev/null 2>&1; apt-get install git -y >/dev/null 2>&1; }
command -v unrar > /dev/null 2>&1 || { apt-get update >/dev/null 2>&1; apt-get install unrar -y >/dev/null 2>&1; }
echo " Done" >&2
}
get_dropbox_downloader() {
echo -n "[*] Prepare Downloader ..." >&2
cd
git clone https://github.com/andreafabrizi/Dropbox-Uploader.git > /dev/null 2>&1 && cd Dropbox-Uploader
if grep -q 'The configuration has been saved.' <<< "$(echo -e "${token}\ny\n" | ./dropbox_uploader.sh)" ; then
echo " Ok" >&2
fi
echo " Done" >&2
}
extract_rar() {
echo -n "[*] Extacting RAR files ..." >&2
unrar x -e "*.rar" > /dev/null 2>&1
rm *.rar
echo " Done" >&2
}
upload_file() {
echo -n "[*] Uploading files to Dropbox ..." >&2
cd /root/Dropbox-Uploader/
./dropbox_uploader.sh upload /root/download/ $up_path
rm -rf /root/Dropbox-Uploader/
rm -rf /root/download
echo "[*] All files uploaded to Dropbox in $up_path/download" >&2
}
get_url
dependencies
get_dropbox_token
path_to_upload
get_dropbox_downloader
download_file
extract_rar
upload_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment