Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
ewwink committed Jul 25, 2018
1 parent 64104ab commit e69bc0d
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text eol=lf
1 change: 1 addition & 0 deletions .rarreg.key
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
put your winrar registration key here
82 changes: 80 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,80 @@
# heroku-google-drive
Remote Google Drive client on Heroku using Rclone and Aria2


# Heroku Google Drive
Remote [Google Drive client](https://github.com/ewwink/heroku-google-drive) on Heroku using Rclone and Aria2

## Installation
new app

```
heroku create myapp --b https://github.com/ewwink/heroku-google-drive.git
heroku git:clone -a myapp
```

existing app, use: `add|set`
```
heroku buildpacks:set https://github.com/ewwink/heroku-google-drive.git -a myapp
```

go to `myapp` directory, create or copy `rclone.conf` and winrar registraton key `.rarreg.key` (optional) then commit the change

```
cd myapp
git add .
git commit -am "add config"
git push heroku master
```
if you don't have `rclone.conf` download `rclone` and run `rclone config` generated config file will be

```
Windows: %userprofile%\.config\rclone\rclone.conf
Linux: $HOME/.config/rclone/rclone.conf
```
## Usage
**Open remote Heroku**
```
cd myapp
heroku run bash
# or
heroku run bash --remote origin
```

**Upload to Google Drive**
assume `gdrive_config` is your Google drive config name that generated above
```
rclone copy local_dir gdrive_config:remote_drive_dir
```
**Speed up upload**
`--transfers=N` number parallel of connection. `default: 4`
` --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`
`--drive-upload-cutoff=N` should be same with chunk size

```
$ rclone --transfers=16 `--drive-chunk-size=16384k --drive-upload-cutoff=16384k`copy local_dir gdrive_config:remote_drive_dir
```

to view file on Google drive
```
rclone lsd gdrive_config:remote_drive_dir
```
view option:
`lsd` only show file in current directory
`ls` show file including in subdirectory (recursvely)

## Bonus
**Download file using `Aria2`**
Aria2 is command-line download accelerator
```
aria2c -x4 http://host/file.rar
```
`-x4` mean download using 4 connection

**To extract `.rar` file**
to current directory
```
unrar e file.rar
```
with full path
```
unrar x file.rar
```
116 changes: 116 additions & 0 deletions bin/compile
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#!/bin/sh

set -e

indent() {
sed -u 's/^/ /'
}

###### install Rclone ##########
echo "-----> Installing rclone"
BUILD_DIR=$1
CACHE_DIR=$2
VENDOR_DIR="vendor"
FILE="rclone-current-linux-amd64.zip"
DOWNLOAD_URL="https://downloads.rclone.org/$FILE"

mkdir -p "$CACHE_DIR"

if ! [ -e "$CACHE_DIR/$FILE" ]; then
echo "-----> Fetching Latest Rclone binaries at ${DOWNLOAD_URL}" | indent
wget $DOWNLOAD_URL -q -O "$CACHE_DIR/$FILE"
else
echo "build using cached source" | indent
fi

cd "$BUILD_DIR"
mkdir -p "$VENDOR_DIR"
cd "$VENDOR_DIR"
mkdir -p rclone
cd rclone
cp "$CACHE_DIR/$FILE" .
unzip -qqj "$FILE"
rm -rf "$FILE"

echo "exporting PATH" | indent
PROFILE_PATH="$BUILD_DIR/.profile.d/rclone.sh"
mkdir -p "$(dirname "$PROFILE_PATH")"
echo 'export PATH="$PATH:${HOME}/vendor/rclone"' >> $PROFILE_PATH
echo "Rclone installed" | indent

###### install aria2 ##########
echo "-----> Installing Aria2"

FILE="aria2-1.34.0-linux-gnu-64bit-build1"
FILE_ARC="${FILE}.tar.bz2"
DOWNLOAD_URL="https://github.com/q3aql/aria2-static-builds/releases/download/v1.34.0/$FILE_ARC"

if ! [ -e "$CACHE_DIR/$FILE_ARC" ]; then
echo "-----> Fetching Aria2 binaries at ${DOWNLOAD_URL}" | indent
wget "$DOWNLOAD_URL" -q -O "$CACHE_DIR/$FILE_ARC"
else
echo "build using cached source" | indent
fi


cd "$BUILD_DIR/$VENDOR_DIR"
mkdir -p aria2c
cd aria2c
cp "$CACHE_DIR/$FILE_ARC" .
tar jxf "$FILE_ARC"
mv "$FILE"/* .
rm -rf "$FILE_ARC" "$FILE"

echo "exporting PATH" | indent
PROFILE_PATH="$BUILD_DIR/.profile.d/aria2c.sh"
mkdir -p "$(dirname "$PROFILE_PATH")"
echo 'export PATH="$PATH:${HOME}/vendor/aria2c"' >> $PROFILE_PATH

#### install winrar ########

echo "-----> Installing winrar"

FILE="rarlinux-x64-5.6.b4.tar.gz"
DOWNLOAD_URL="https://www.rarlab.com/rar/$FILE"

if ! [ -e "$CACHE_DIR/$FILE" ]; then
echo "-----> Fetching Winrar binaries at ${DOWNLOAD_URL}" | indent
wget $DOWNLOAD_URL -q -O "$CACHE_DIR/$FILE"
else
echo "build using cached source" | indent
fi

cd "$BUILD_DIR/$VENDOR_DIR"
mkdir -p winrar
cd winrar
cp "$CACHE_DIR/$FILE" .
tar xf "$CACHE_DIR/$FILE" --strip-components=1

echo "exporting PATH" | indent
PROFILE_PATH="$BUILD_DIR/.profile.d/rar.sh"
mkdir -p "$(dirname "$PROFILE_PATH")"
echo 'export PATH="$PATH:${HOME}/vendor/winrar"' >> $PROFILE_PATH
PROFILE_PATH="$BUILD_DIR/.profile.d/unrar.sh"
mkdir -p "$(dirname "$PROFILE_PATH")"
echo 'export PATH="$PATH:${HOME}/vendor/winrar"' >> $PROFILE_PATH

#### moving rclone.conf ########

mkdir -p "$BUILD_DIR"/.profile.d
cat <<EOF >"$BUILD_DIR"/.profile.d/rclone_config.sh
#!/bin/sh
cd "\$HOME"
echo "-----> moving config file, rclone.conf"
if [ -f "rclone.conf" ]; then
mkdir -p .config/rclone
mv -f rclone.conf .config/rclone/rclone.conf
echo "-----> Done."
else
echo "rclone.conf not exist" | indent
fi
EOF





5 changes: 5 additions & 0 deletions bin/detect
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

# this pack is valid for all apps
echo "gdrive-client"
exit 0
2 changes: 2 additions & 0 deletions bin/release
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
echo "--- {}"
9 changes: 9 additions & 0 deletions rclone.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[gdrive_config]
type = drive
client_id =
client_secret =
scope = drive.file
root_folder_id =
service_account_file =
token = {"access_token":"xxxxxxxxxxxxxxx,"token_type":"Bearer","refresh_token":"xxxxxxxxxxxxxxxxxxxxxxxxxxx","expiry":"2018-07-25T21:27:02.0923008+07:00"}

0 comments on commit e69bc0d

Please sign in to comment.