├── .gitattributes ├── .rarreg.key ├── README.md ├── bin ├── compile ├── detect └── release └── rclone.conf /.gitattributes: -------------------------------------------------------------------------------- 1 | * text eol=lf 2 | -------------------------------------------------------------------------------- /.rarreg.key: -------------------------------------------------------------------------------- 1 | put your winrar registration key here 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Heroku Google Drive 4 | Remote [Google Drive client](https://github.com/ewwink/heroku-google-drive) on Heroku using Rclone and Aria2 5 | 6 | ## Installation 7 | Create new app 8 | 9 | ``` 10 | heroku create myapp -b https://github.com/ewwink/heroku-google-drive.git 11 | heroku git:clone -a myapp 12 | ``` 13 | 14 | Existing app, use: `add|set` 15 | 16 | ``` 17 | heroku buildpacks:set https://github.com/ewwink/heroku-google-drive.git -a myapp 18 | ``` 19 | 20 | go to `myapp` directory, create or copy `rclone.conf` and winrar registraton key `.rarreg.key` (optional) then commit the change 21 | 22 | ``` 23 | cd myapp 24 | git add . 25 | git commit -am "add config" 26 | git push heroku master 27 | ``` 28 | if you don't have `rclone.conf` download `rclone` and run locally `rclone config` generated config file will be 29 | 30 | ``` 31 | Windows: %userprofile%\.config\rclone\rclone.conf 32 | Linux: $HOME/.config/rclone/rclone.conf 33 | ``` 34 | ## Usage 35 | **Open remote Heroku** 36 | ``` 37 | cd myapp 38 | heroku run bash 39 | # or 40 | heroku run bash --remote origin 41 | ``` 42 | 43 | **Upload to Google Drive** 44 | 45 | assume `gdrive_config` is your Google drive config name that generated above 46 | ``` 47 | rclone -v copy local_dir gdrive_config:remote_drive_dir 48 | ``` 49 | 50 | **Speed up upload** 51 | 52 | If you want to upload many files smaller than 8mb increase only `--transfers` option 53 | 54 | ``` 55 | rclone -v --transfers=16 --drive-chunk-size=16384k --drive-upload-cutoff=16384k copy local_dir gdrive_config:remote_drive_dir 56 | ``` 57 | `--transfers=N` number parallel of connection. `default: 4` 58 | 59 | ` --drive-chunk-size=N` if file bigger than this size it will splits into multiple upload, increase if you want better speed. `default: 8192k or 8mb` 60 | 61 | `--drive-upload-cutoff=N` should be same with chunk size 62 | 63 | `-v` option to view upload progress stats 64 | 65 | **view file on Google drive** 66 | ``` 67 | rclone lsd gdrive_config:remote_drive_dir 68 | ``` 69 | view option: 70 | 71 | `lsd` only show file in current directory 72 | 73 | `ls` show file including in subdirectory (recursvely) 74 | 75 | ## Bonus 76 | **Download file using `Aria2`** 77 | 78 | Aria2 is command-line download accelerator 79 | ``` 80 | aria2c -x4 http://host/file.rar 81 | ``` 82 | `-x4` mean download using 4 connection 83 | 84 | **To extract `.rar` file** 85 | 86 | to current directory 87 | ``` 88 | unrar e file.rar 89 | ``` 90 | 91 | with full path 92 | 93 | ``` 94 | unrar x file.rar 95 | ``` 96 | -------------------------------------------------------------------------------- /bin/compile: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | indent() { 6 | sed -u 's/^/ /' 7 | } 8 | 9 | ###### install Rclone ########## 10 | echo "-----> Installing rclone" 11 | BUILD_DIR=$1 12 | CACHE_DIR=$2 13 | VENDOR_DIR="vendor" 14 | FILE="rclone-current-linux-amd64.zip" 15 | DOWNLOAD_URL="https://downloads.rclone.org/$FILE" 16 | 17 | mkdir -p "$CACHE_DIR" 18 | 19 | if ! [ -e "$CACHE_DIR/$FILE" ]; then 20 | echo "-----> Fetching Latest Rclone binaries at ${DOWNLOAD_URL}" | indent 21 | wget $DOWNLOAD_URL -q -O "$CACHE_DIR/$FILE" 22 | else 23 | filestr=$(find . -name "$CACHE_DIR/$FILE" -mtime +1 -print) 24 | if [ "$filestr" = "" ]; then 25 | echo "-----> cache Expired, Fetching Latest Rclone at ${DOWNLOAD_URL}" | indent 26 | wget $DOWNLOAD_URL -q -O "$CACHE_DIR/$FILE" 27 | else 28 | echo "build using cached source" | indent 29 | fi 30 | fi 31 | 32 | cd "$BUILD_DIR" 33 | mkdir -p "$VENDOR_DIR" 34 | cd "$VENDOR_DIR" 35 | mkdir -p rclone 36 | cd rclone 37 | cp "$CACHE_DIR/$FILE" . 38 | unzip -qqj "$FILE" 39 | rm -rf "$FILE" 40 | 41 | echo "exporting PATH" | indent 42 | PROFILE_PATH="$BUILD_DIR/.profile.d/rclone.sh" 43 | mkdir -p "$(dirname "$PROFILE_PATH")" 44 | echo 'export PATH="$PATH:${HOME}/vendor/rclone"' >> $PROFILE_PATH 45 | echo "Rclone installed" | indent 46 | 47 | ###### install aria2 ########## 48 | echo "-----> Installing Aria2" 49 | 50 | FILE="aria2-1.34.0-linux-gnu-64bit-build1" 51 | FILE_ARC="${FILE}.tar.bz2" 52 | DOWNLOAD_URL="https://github.com/q3aql/aria2-static-builds/releases/download/v1.34.0/$FILE_ARC" 53 | 54 | if ! [ -e "$CACHE_DIR/$FILE_ARC" ]; then 55 | echo "-----> Fetching Aria2 binaries at ${DOWNLOAD_URL}" | indent 56 | wget "$DOWNLOAD_URL" -q -O "$CACHE_DIR/$FILE_ARC" 57 | else 58 | echo "build using cached source" | indent 59 | fi 60 | 61 | 62 | cd "$BUILD_DIR/$VENDOR_DIR" 63 | mkdir -p aria2c 64 | cd aria2c 65 | cp "$CACHE_DIR/$FILE_ARC" . 66 | tar jxf "$FILE_ARC" 67 | mv "$FILE"/* . 68 | rm -rf "$FILE_ARC" "$FILE" 69 | 70 | echo "exporting PATH" | indent 71 | PROFILE_PATH="$BUILD_DIR/.profile.d/aria2c.sh" 72 | mkdir -p "$(dirname "$PROFILE_PATH")" 73 | echo 'export PATH="$PATH:${HOME}/vendor/aria2c"' >> $PROFILE_PATH 74 | 75 | #### install winrar ######## 76 | 77 | echo "-----> Installing winrar" 78 | 79 | FILE="rarlinux-x64-5.9.0.tar.gz" 80 | DOWNLOAD_URL="https://www.rarlab.com/rar/$FILE" 81 | 82 | if ! [ -e "$CACHE_DIR/$FILE" ]; then 83 | echo "-----> Fetching Winrar binaries at ${DOWNLOAD_URL}" | indent 84 | wget $DOWNLOAD_URL -q -O "$CACHE_DIR/$FILE" 85 | else 86 | echo "build using cached source" | indent 87 | fi 88 | 89 | cd "$BUILD_DIR/$VENDOR_DIR" 90 | mkdir -p winrar 91 | cd winrar 92 | cp "$CACHE_DIR/$FILE" . 93 | tar xf "$CACHE_DIR/$FILE" --strip-components=1 94 | 95 | echo "exporting PATH" | indent 96 | PROFILE_PATH="$BUILD_DIR/.profile.d/rar.sh" 97 | mkdir -p "$(dirname "$PROFILE_PATH")" 98 | echo 'export PATH="$PATH:${HOME}/vendor/winrar"' >> $PROFILE_PATH 99 | PROFILE_PATH="$BUILD_DIR/.profile.d/unrar.sh" 100 | mkdir -p "$(dirname "$PROFILE_PATH")" 101 | echo 'export PATH="$PATH:${HOME}/vendor/winrar"' >> $PROFILE_PATH 102 | 103 | #### moving rclone.conf ######## 104 | 105 | mkdir -p "$BUILD_DIR"/.profile.d 106 | cat <"$BUILD_DIR"/.profile.d/rclone_config.sh 107 | #!/bin/sh 108 | cd "\$HOME" 109 | echo "-----> moving config file, rclone.conf" 110 | if [ -f "rclone.conf" ]; then 111 | mkdir -p .config/rclone 112 | mv -f rclone.conf .config/rclone/rclone.conf 113 | echo "-----> Done." 114 | else 115 | echo "rclone.conf not exist" | indent 116 | fi 117 | 118 | echo "-----> moving id_rsa" 119 | if [ -f "id_rsa" ]; then 120 | mkdir -p .ssh 121 | mv -f id_rsa .ssh/id_rsa 122 | chmod 0700 .ssh/id_rsa 123 | echo "-----> Done." 124 | else 125 | echo "id_rsa not exist" | indent 126 | fi 127 | 128 | 129 | -------------------------------------------------------------------------------- /bin/detect: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # this pack is valid for all apps 4 | echo "gdrive-client" 5 | exit 0 6 | -------------------------------------------------------------------------------- /bin/release: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | echo "--- {}" 3 | -------------------------------------------------------------------------------- /rclone.conf: -------------------------------------------------------------------------------- 1 | [gdrive_config] 2 | type = drive 3 | client_id = 4 | client_secret = 5 | scope = drive.file 6 | root_folder_id = 7 | service_account_file = 8 | token = {"access_token":"xxxxxxxxxxxxxxx,"token_type":"Bearer","refresh_token":"xxxxxxxxxxxxxxxxxxxxxxxxxxx","expiry":"2018-07-25T21:27:02.0923008+07:00"} 9 | 10 | --------------------------------------------------------------------------------