Skip to content

A Microsoft OneDrive and OneDrive for Business client for Linux, written in Python3.

License

Notifications You must be signed in to change notification settings

adornetejr/onedriveClient

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

onedriveCLient

GitHub version Build Status License codecov Coverage Status Code Climate Codacy Badge

Introduction

onedrive_client is a client program for Microsoft OneDrive for Linux. It enables you to sync local directories with remote OneDrive repositories (a.k.a., "Drive") of one or more OneDrive Personal account (OneDrive for Business accounts are in beta tests, use with caution!).

The program is written in Python3, and uses official OneDrive Python SDK to communicate with OneDrive server, Keyring to securely store account credentials, and Linux inotify API to monitor file system changes.

IN DEVELOPMENT. USE WITH CAUTION.

Installation

To install onedrive_client, install all pre-requisite packages, make sure old versions of onedrive_client are uninstalled, and lastly install onedrive_client. Each of those steps will be addressed in following subsections.

The guide that follows will assume an environment with Python3 interpreter installed. To check the version of your Python3 interpreter, run command

$ python3 --version
Python 3.5.2

If python3 command is not found, or its version is below 3.4, please install the latest python3 package. For example, on Ubuntu

$ sudo apt-get install python3

It's strongly suggested that you use the latest PIP to manage Python package dependencies. To get the latest pip from source, run command

# Download pip installation script from official site using wget.
$ wget -O- https://bootstrap.pypa.io/get-pip.py | sudo python3
# Upgrade the components (e.g., setuptools) to latest version.
$ sudo pip3 install -U pip setuptools

To run on Raspbery PI 3, is necessary add more packages.

$ sudo apt-get install python3 build-essential python3-dev libssl-dev inotify-tools python3-dbus libffi-dev dbus-devel libdbus-glib-1-dev -y
$ sudo pip3 install pydbus

Pre-requisites

The use of low-level tools and APIs like inotify and keyring introduces low-level dependencies that need to be installed manually. On Ubuntu the following packages are needed:

  • gcc
  • python3-dev
  • libssl-dev
  • inotify-tools
  • python3-dbus (or probably libdbus-glib-1-dev)

On other distros like Fedora, names of those packages may vary.

Note that keyring, which provides secure local storage for OneDrive credentials (the leak of which may result in total compromise of your OneDrive data), may require additional packages (for example, D-Bus or FreeDesktop Secret Service) depending on your Linux distro and desktop manager. Please refer to its installation instructions for more details. If your environment requires keyring.alt package, make sure to use the latest version (sudo pip3 install -U keyrings.alt).

To install those dependencies on Ubuntu, use apt-get command:

# Install gcc and other C-level pre-requisites.
$ sudo apt install build-essential python3-dev libssl-dev inotify-tools python3-dbus libdbus-1-dev libdbus-glib-1-dev

# Install keyring to store the passwords
$ sudo apt install gnome-keyring
$ eval `gnome-keyring-daemon`
$ eval `dbus-launch`

# install ngrok from own website (ngrok.com) and install in /usr/local/bin
# Don't install ngrok with sudo apt-get install ngrok-client, it does not install the 'good' ngrok!

Python-level pre-requisites are listed in requirements.txt and will be installed automatically when installing onedrive_client.

Uninstall older onedrive_client

If you have old versions of onedrive_client (also named onedrived in the past) in system, please uninstall them before proceeding. The packages can be easily removed with pip.

# Remove Python packages of older onedrive-d.
$ sudo pip3 uninstall onedrive_d onedrive_client

# Remove useless config files.
$ rm -rf ~/.onedrived ~/.onedrive_client

Install onedrive_client

First pull the code from GitHub repository:

$ git clone https://github.com/derrix060/onedriveClient.git
$ cd onedrive_client

Then install onedrive_client:

$ python3 setup.py install

Usage

onedrive_client exposes two commands -- onedrive-client and onedrive-client-pref. The former is the "synchronizer" and the latter is the "configurator". If you want to run it directly in code repository without installing the package, in the following example commands replace onedrive-client with python3 -m onedrive_client.od_main and replace onedrive-client-pref with python3 -m onedrive_client.od_pref.

Configure onedrive_client

Before running onedrive_client for the first time, or whenever you need to change the configurations, you will need to use onedrive-client-pref command. The subsections that follow introduces the basic usage scenarios. For more usage scenarios, refer to "More Usages" section.

To read the complete usage of onedrive-client-pref, use argument --help:

$ onedrive-client-pref --help
Usage: od_pref.py [OPTIONS] COMMAND [ARGS]...

Options:
  --version   Show the version and exit.
  -h, --help  Show this message and exit.

Commands:
  account  Add new OneDrive account to onedrive_client, list all existing ones, or
           remove some.
  config   Modify config (e.g., proxies, intervals) for current user.
  drive    List all remote OneDrive repositories (Drives) of linked accounts,
           add new Drives to sync, edit configurations of existing Drives, or
           remove a Drive from local list.

Authorizing accounts

Operations related to configuring accounts can be listed by command onedrive-client-pref account

$ onedrive-client-pref account --help
Usage: od_pref.py account [OPTIONS] COMMAND [ARGS]...

Options:
  -h, --help  Show this message and exit.

Commands:
  add   Add a new OneDrive account to onedrive_client.
  del   De-authorize and delete an existing account from onedrive_client.
  list  List all linked accounts.

To add an OneDrive account to onedrive_client, you will need command onedrive-client-pref account add. Help message for this command is as follows:

$ onedrive-client-pref account add --help
Usage: od_pref.py account add [OPTIONS]

Options:
  -u, --get-auth-url  If set, print the authentication URL and exit.
  -c, --code TEXT     Skip interactions and try authenticating with the code
                      directly.
  -b, --for-business  If set, add an OneDrive for Business account.
  -h, --help          Show this message and exit.

More specifically, the CLI offers two modes to add an account -- interactive mode, in which the CLI guides you step by step, and command mode, in which you provide the information from command line arguments.

Interactive mode

In interactive mode, the program will provide you with an URL to visit. Open this URL with a web browser (e.g., Chrome, Firefox), sign in with your Microsoft Account and authorize onedrive_client to access your OneDrive data. The web page will eventually land to a blank page whose URL starts with "https://login.live.com/oauth20_desktop.srf". Paste this URL (a.k.a., callback URL) back to the program.

Note that onedrive_client needs your basic account information (e.g., email address) to distinguish different accounts (otherwise OneDrive returns "tokens" from which you cannot tell which account they stand for).

$ onedrive-client-pref account add

NOTE: To better manage your OneDrive accounts, onedrive_client needs permission to access your account info (e.g., email
address to distinguish different accounts) and read/write your OneDrive files.

Paste this URL into your browser to sign in and authorize onedrive_client:

https://login.live.com/oauth20_authorize.srf?response_type=code&scope=wl.signin+wl.emails+wl.offline_access+
onedrive.readwrite&client_id=000000004010C916&redirect_uri=https%3A%2F%2Flogin.live.com%2Foauth20_desktop.srf

The authentication web page will finish with a blank page whose URL starts with
"https://login.live.com/oauth20_desktop.srf". Paste this URL here.
Paste URL here: https://login.live.com/oauth20_desktop.srf?code=<some_code_here>&lc=1033

Successfully authorized onedrive_client.
Successfully added account for Xiangyu Bu ([email protected], <account_id_token>)!

All OneDrive accounts associated with user "xb":

  #  Account ID          Owner Name    Email Address
---  ------------------  ------------  ---------------
  0  <account_id_token>  Xiangyu Bu    [email protected]
One Drive for Business Support

Be careful, it's still on beta test. As explained before, the onedrive needs some informations. In case of Business, it needs to use 2 different services, one of them to do the background tasks (add, remove, rename some item) and another one just to get your name and email. That's why you need to authenticate in two different services.

To add a business account, just insert the tag '-b' at end:

$ onedrive-client-pref account add -b

As happen in normal account, you need to click on link showed and copy the entire link (not only the code!!), but as explained before, you need to do this twice (one for each service).

Command mode

Instead of giving the sign-in URL and then prompting for the callback URL, use the following command to get the sign-in URL:

$ onedrive-client-pref account add --get-auth-url
NOTE: To better manage your OneDrive accounts, onedrive_client needs permission to access your account info (e.g., email
address to distinguish different accounts) and read/write your OneDrive files.

Paste this URL into your browser to sign in and authorize onedrive_client:

https://login.live.com/oauth20_authorize.srf?response_type=code&client_id=000000004010C916&redirect_uri=https%3A%2F%2F
login.live.com%2Foauth20_desktop.srf&scope=wl.signin+wl.emails+wl.offline_access+onedrive.readwrite

Visit the URL and do the same steps as interactive mode until you get the blank page. Copy the URL and copy the code parameter from the URL. For example, in URL https://login.live.com/oauth20_desktop.srf?code=<some_code_here>&lc=1033, find the part ?code=<some_code_here>& and the code is the part <some_code_here>.

Use command onedrive-client-pref account add --code <some_code_here>, where <some_code_here> is the code, to add your account.

Adding Drives to onedrive_client

After you authorize onedrive_client to access your OneDrive data, you are now able to add Drives. Each OneDrive account has one or more Drive associated, and onedrive_client allows you to choose which Drive to sync. Similar to the step of authorizing onedrive_client, the CLI provides both interactive mode and command mode.

Interactive mode

$ onedrive-client-pref drive set
Reading drives information from OneDrive server...

All available Drives of authorized accounts:

  #  Account Email    Drive ID          Type      Quota                        Status
---  ---------------  ----------------  --------  ---------------------------  --------
  0  <some_email>     <some_drive_id>   personal  5.3 GB Used / 33.0 GB Total  active

Please enter row number of the Drive to add or modify (CTRL+C to abort): 0

Going to add/edit Drive "<some_drive_id>" of account "<some_email>"...
Enter the directory path to sync with this Drive [/home/xb/OneDrive]:  
Syncing with directory "/home/xb/OneDrive"? [y/N]: y
Enter the path to ignore file for this Drive [/home/xb/.config/onedrive_client/ignore_v2.txt]: 

Successfully configured Drive <some_drive_id> of account <some_email> (<some_user_id>):
  Local directory: /home/xb/OneDrive
  Ignore file path: /home/xb/.config/onedrive_client/ignore_v2.txt

If you have more than one account authorized, all drives of all authorized accounts will appear in the table.

Command mode

Please find the available command-line arguments from help message using command onedrive-client-pref drive set --help.

Set up webhook

Webhook explained

For now, refer to issue #19. More details TBA.

Using ngrok-based webhook

Download and install ngrok.

By default, onedrive_client will look for ngrok binary from PATH. To specify path to the binary manually, set up environment variable NGROK when running onedrive-client. For example, NGROK=~/utils/ngrok onedrive-client start --debug.

To use a custom config file for ngrok, set environment variable NGROK_CONFIG_FILE to path of your desired config file. Note that onedrive_client will create a HTTPS tunnel automatically and there is no need to specify tunnels. The purpose of using a custom ngrok config file should be to adjust resource usage, or link ngrok process with your paid ngrok account. The default ngrok config file shipped with onedrive_client turns off terminal output of ngrok and disables inspection database.

Using direct connection

TBA. Not applicable to most end-user machines.

Run onedrive_client in debug mode

Use argument --debug so that onedrive_client runs in debug mode, using debug-level log verbosity and printing log to stderr.

onedrive-client start --debug

To stop onedrive_client process which is running in debug mode, send SIGINT to the process or hitting CTRL+C if it runs in a terminal.

Run onedrive_client as daemon

It's suggested that you set up a log file before running in daemon mode:

$ onedrive-client-pref config set logfile_path PATH_TO_SOME_WRITABLE_FILE

To start the program as daemon,

onedrive-client start

To stop the daemon,

onedrive-client stop

or send SIGTERM to the process (Ctrl + C).

More Usages

Run onedrive_client with proxies

onedrive_client follows behavior of standard Python library function getproxies() to read proxies information from the OS. That is, run the command with environment variable HTTP_PROXY (or http_proxy) to set up a HTTP proxy, and variable HTTPS_PROXY (or https_proxy) to set up a HTTPS proxy. For example,

$ HTTPS_PROXY=https://user:pass@host:port/some_path onedrive-client start --debug

A HTTPS proxy must have a verifiable SSL certificate.

List all authorized OneDrive accounts

Remove an authorized account

List all remote Drives

Edit configuration of an existing Drive

Edit ignore list (selective sync)

Remove a Drive from onedrive_client

Interactive mode
$ onedrive-client-pref drive del
Drives that have been set up:

 #0 - Drive "<some_drive_id_here>":
   Account:     <some_account_email> (<some_user_id_here>)
   Local root:  /home/xb/OneDrive
   Ignore file: /home/xb/.config/onedrive_client/ignore_v2.txt

Please enter the # number of the Drive to delete (CTRL+C to abort): 0
Continue to delete Drive "<some_drive_id_here>" (its local directory will NOT be deleted)? [y/N]: y
Successfully deleted Drive "<some_drive_id_here>" from onedrive_client.
Command mode

The command-mode equivalent is:

onedrive-client-pref drive del --drive-id <some_drive_id_here> [--yes]

If argument --yes is used, the specified Drive, if already added, will be deleted without confirmation.

Adjusting parameters of onedrive_client

Check latest version of onedrive_client

Uninstallation

Use pip3 to uninstall onedrive_client from system:

$ pip3 uninstall onedrive_client

If --user argument was not used when installing (that is, onedrive_client was installed as a system-level package), you will need root permission to run the command above.

License

MIT License.

About

A Microsoft OneDrive and OneDrive for Business client for Linux, written in Python3.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%