From 026809d4d1be49e7892b78263b8e84bf601a33bd Mon Sep 17 00:00:00 2001 From: adudek <3772966+adudek@users.noreply.github.com> Date: Tue, 4 Dec 2018 01:59:03 +0100 Subject: [PATCH] Docker buildfiles for onedrive service (#262) * Separate install options for binary (make install.noservice) only and binary * Docker build files and usage documentation --- Makefile | 11 +++++---- README.md | 24 ++++++++++++++----- docker/Dockerfile | 25 ++++++++++++++++++++ docker/README.md | 55 ++++++++++++++++++++++++++++++++++++++++++++ docker/entrypoint.sh | 26 +++++++++++++++++++++ 5 files changed, 131 insertions(+), 10 deletions(-) create mode 100644 docker/Dockerfile create mode 100644 docker/README.md create mode 100755 docker/entrypoint.sh diff --git a/Makefile b/Makefile index 6f2acaa0..e6322d59 100644 --- a/Makefile +++ b/Makefile @@ -31,13 +31,18 @@ all: onedrive onedrive.service onedrive.1 clean: rm -f onedrive onedrive.o onedrive.service onedrive@.service onedrive.1 -install: all +onedrive: version $(SOURCES) + $(DC) $(DFLAGS) $(SOURCES) + +install.noservice: onedrive onedrive.1 mkdir -p $(DESTDIR)/var/log/onedrive chown root.users $(DESTDIR)/var/log/onedrive chmod 0775 $(DESTDIR)/var/log/onedrive install -D onedrive $(DESTDIR)$(PREFIX)/bin/onedrive install -D onedrive.1 $(DESTDIR)$(MANDIR)/onedrive.1 install -D -m 644 logrotate/onedrive.logrotate $(DESTDIR)/etc/logrotate.d/onedrive + +install: all install.noservice for i in $(DOCFILES) ; do install -D -m 644 $$i $(DESTDIR)$(DOCDIR)/$$i ; done ifeq ($(RHEL),1) mkdir -p $(DESTDIR)/usr/lib/systemd/system/ @@ -54,9 +59,7 @@ else chmod 0755 $(DESTDIR)/usr/lib/systemd/system/ install -D -m 644 onedrive@.service $(DESTDIR)/usr/lib/systemd/system/ endif - -onedrive: version $(SOURCES) - $(DC) $(DFLAGS) $(SOURCES) + install -D -m 644 onedrive.service $(DESTDIR)/usr/lib/systemd/user/onedrive.service onedrive.service: sed "s|@PREFIX@|$(PREFIX)|g" systemd.units/onedrive.service.in > onedrive.service diff --git a/README.md b/README.md index 5e5c7839..2d838cb6 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ wget http://ftp.us.debian.org/debian/pool/main/n/ncurses/libtinfo6_6.1+20180714- sudo dpkg -i ./*.deb ``` -### Dependencies: Fedora < Version 18 / CentOS / RHEL +### Dependencies: Fedora < Version 18 / CentOS / RHEL ``` sudo yum groupinstall 'Development Tools' sudo yum install libcurl-devel @@ -65,7 +65,7 @@ sudo yum install sqlite-devel curl -fsS https://dlang.org/install.sh | bash -s dmd ``` -### Dependencies: Fedora > Version 18 +### Dependencies: Fedora > Version 18 ``` sudo dnf groupinstall 'Development Tools' sudo dnf install libcurl-devel @@ -151,6 +151,18 @@ make DC=~/ldc2-1.11.0-linux-aarch64/bin/ldmd2 sudo make install ``` +#### Docker onedrive monitor +``` +# Update onedriveDir with correct existing OneDrive directory path +onedriveDir="${HOME}/OneDrive" + +firstRun='-d' +docker pull driveone/onedrive +docker inspect onedrive_conf > /dev/null || { docker volume create onedrive_conf; firstRun='-it'; } +docker inspect onedrive > /dev/null && docker rm -f onedrive +docker run $firstRun --restart unless-stopped --name onedrive -v onedrive_conf:/onedrive/conf -v "${onedriveDir}:/onedrive/data" driveone/onedrive +``` + ## Using the client ### Upgrading from 'skilion' client The 'skilion' version contains a significant number of defect's in how the local sync state is managed. When upgrading from the 'skilion' version to this version, it is advisable to stop any service / onedrive process from running and then remove any `items.sqlite3` file from your configuration directory (`~/.config/onedrive/`) as this will force the creation of a new local cache file. @@ -189,7 +201,7 @@ onedrive --synchronize --download-only ### Performing a 'one-way' upload sync In some cases it may be desirable to 'upload only' to OneDrive. To do this use the following command: ``` -onedrive --synchronize --upload-only +onedrive --synchronize --upload-only ``` ### Increasing logging level @@ -263,14 +275,14 @@ rm -f ~/.config/onedrive/refresh_token ``` ## Additional Configuration -Additional configuration is optional. +Additional configuration is optional. If you want to change the defaults, you can copy and edit the included config file into your `~/.config/onedrive` directory: ```sh mkdir -p ~/.config/onedrive cp ./config ~/.config/onedrive/config nano ~/.config/onedrive/config ``` -This file does not get created by default, and should only be created if you want to change the 'default' operational parameters. +This file does not get created by default, and should only be created if you want to change the 'default' operational parameters. Available options: * `sync_dir`: directory where the files will be synced @@ -371,7 +383,7 @@ In some cases it is desirable to run the OneDrive client as a service, but not r 1. As the user, who will be running the service, run the application in standalone mode, authorize the application for use & validate that the synchronization is working as expected: ``` -onedrive --synchronize --verbose +onedrive --synchronize --verbose ``` 2. Once the application is validated and working for your user, as the 'root' user, where is your username from step 1 above. ``` diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 00000000..92acca4e --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,25 @@ +FROM centos +ENV GOSU_VERSION=1.11 + +RUN yum install -y make git gcc libcurl-devel sqlite-devel && \ + rm -rf /var/cache/yum/ && \ + curl -fsS https://dlang.org/install.sh | bash -s dmd && \ + # gosu installation + gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \ + && curl -o /usr/local/bin/gosu -SL "https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-amd64" \ + && curl -o /usr/local/bin/gosu.asc -SL "https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-amd64.asc" \ + && gpg --verify /usr/local/bin/gosu.asc \ + && rm /usr/local/bin/gosu.asc \ + && rm -r /root/.gnupg/ \ + && chmod +x /usr/local/bin/gosu \ + && gosu nobody true +RUN mkdir -p /onedrive/conf /onedrive/data +ADD onedrive /usr/src/onedrive +RUN . /root/dlang/dmd-2.083.0/activate && \ + cd /usr/src/onedrive && \ + make install.noservice && \ + make clean +ADD entrypoint.sh /entrypoint.sh +VOLUME ["/onedrive/conf"] + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 00000000..cabceca8 --- /dev/null +++ b/docker/README.md @@ -0,0 +1,55 @@ +# onedrive docker image + +Thats right folks onedrive is now dockerized ;) + +This container offers simple monitoring-mode service for 'Free Client for OneDrive on Linux'. + +## Usage instructions +``` +docker pull driveone/onedrive +``` +NOTE: +> SELinux context needs to be configured or disabled for Docker, to be able to write to OneDrive host directory. + + +1. Run or update onedrive container +``` +# Update onedriveDir with correct existing OneDrive directory path +onedriveDir="${HOME}/OneDrive" + +firstRun='-d' +docker pull driveone/onedrive +docker inspect onedrive_conf > /dev/null || { docker volume create onedrive_conf; firstRun='-it'; } +docker inspect onedrive > /dev/null && docker rm -f onedrive +docker run $firstRun --restart unless-stopped --name onedrive -v onedrive_conf:/onedrive/conf -v "${onedriveDir}:/onedrive/data" driveone/onedrive +``` + +## Poweruser section +1. Check if monitor service is running +``` +docker ps -f name=onedrive +``` +2. Show monitor run logs +``` +docker logs onedrive +``` +3. Stop running monitor +``` +docker stop onedrive +``` +4. Resume monitor +``` +docker start onedrive +``` +5. Unregister onedrive monitor +``` +docker rm -f onedrive +``` + +## Build instructions +``` +cd docker +git clone https://github.com/abraunegg/onedrive +docker build . -t driveone/onedrive +``` + diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100755 index 00000000..144bc532 --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,26 @@ +#!/bin/bash -eu + +set +H -xeuo pipefail + +ONEDRIVE_UID=$(stat /onedrive/data -c '%u') +ONEDRIVE_GID=$(stat /onedrive/data -c '%g') + +# Create new group using target GID +if ! odgroup="$(getent group $ONEDRIVE_GID)"; then + odgroup='onedrive' + groupadd "${odgroup}" -g $ONEDRIVE_GID +fi + +# Create new user using target UID +if ! oduser="$(getent passwd $ONEDRIVE_UID)"; then + oduser='onedrive' + useradd "${oduser}" -u $ONEDRIVE_UID -g $ONEDRIVE_GID +else + oduser="${oduser%%:*}" + odgroup="${odgroup%%:*}" + usermod -g "${odgroup}" "${oduser}" + grep -qv root <( groups "${oduser}" ) || { echo 'ROOT level priviledges prohibited!'; exit 1; } +fi + +chown "${oduser}:${odgroup}" /onedrive/ /onedrive/conf +exec gosu "${oduser}" /usr/local/bin/onedrive --monitor --verbose --confdir /onedrive/conf --syncdir /onedrive/data