Sync Linux folder with OneDrive

From Luniwiki
Jump to: navigation, search

Install prerequisites

apt install libcurl4-openssl-dev libsqlite3-dev git curl pkg-config snapd
snap install --classic dmd
2019-08-11T21:44:24-04:00 INFO Waiting for restart...
dmd 2.087.0 from D Programming Language (dlang) installed
snap install --classic dub
dub 1.15.0 from D Programming Language (dlang) installed

Install onedrive

git clone https://github.com/abraunegg/onedrive.git
cd onedrive/
./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for dmd... dmd
checking version of D compiler... 2.087.0
checking for curl... yes
checking for sqlite... yes
configure: creating ./config.status
config.status: creating Makefile
config.status: creating contrib/pacman/PKGBUILD
config.status: creating contrib/spec/onedrive.spec
config.status: creating onedrive.1
config.status: creating contrib/systemd/onedrive.service
config.status: creating contrib/systemd/onedrive@.service
make
if [ -f .git/HEAD ] ; then \
       git describe --tags > version ; \
else \
       echo v2.3.9-dev > version ; \
fi
dmd  -w -g -O -J. -L-lcurl -L-lsqlite3  -L-ldl src/config.d src/itemdb.d src/log.d src/main.d src/monitor.d src/onedrive.d src/qxor.d src/selective.d src/sqlite.d src/sync.d src/upload.d src/util.d src/progress.d -ofonedrive
make install
/usr/bin/install -c -D onedrive /usr/local/bin/onedrive
/usr/bin/install -c -D onedrive.1 /usr/local/share/man/man1/onedrive.1
/usr/bin/install -c -D -m 644 contrib/logrotate/onedrive.logrotate /usr/local/etc/logrotate.d/onedrive
mkdir -p /usr/local/share/doc/onedrive
/usr/bin/install -c -D -m 644 README.md config LICENSE CHANGELOG.md docs/Docker.md docs/INSTALL.md docs/Office365.md docs/USAGE.md /usr/local/share/doc/onedrive
/usr/bin/install -c -d -m 0755 /usr/lib/systemd/user /lib/systemd/system
/usr/bin/install -c -m 0644 contrib/systemd/onedrive@.service /lib/systemd/system
/usr/bin/install -c -m 0644 contrib/systemd/onedrive.service /usr/lib/systemd/use

Authorize account

onedrive
Authorize this app visiting:

https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=22c49a0d-d21c-4792-aed1-8f163c982546&scope=Files.ReadWrite%20Files.ReadWrite.all%20Sites.ReadWrite.All%20offline_access&response_type=code&redirect_uri=https://login.microsoftonline.com/common/oauth2/nativeclient

Copy the URL and login, and after copy the URL in the blank page of your browser


Enter the response uri: https://login.microsoftonline.com/common/oauth2/nativeclient?code=XXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXXX
--synchronize or --monitor missing from your command options or use --help for further assistance
No OneDrive sync will be performed without either of these two arguments being present

First run

onedrive --synchronize

Run as a service

Creation of file /lib/systemd/system/onedrive.service

cat onedrive.service
[Unit]
Description=OneDrive Free Client
Documentation=https://github.com/abraunegg/onedrive
After=network-online.target
Wants=network-online.target

[Service] ExecStart=/usr/local/bin/onedrive --monitor --enable-logging --upload-only --monitor-interval 1200 Restart=on-failure RestartSec=3 RestartPreventExitStatus=3
[Install] WantedBy=default.target

We enable and start the service

systemctl daemon-reload
systemctl enable onedrive
systemctl start onedrive
systemctl status onedrive

References

Daniel Simao 21:27, 11 August 2019 (EDT)