LoginSignup
1
0

Ubuntuのonedriveをマルチアカウントに対応するための手順【備忘録】

Last updated at Posted at 2024-03-04

Ubuntuに複数アカウントのOneDriveを同期させるときに私が行った手順の備忘録です。

インストール日と環境

作業日:2024/03/02

システム構成
```
[System]
OS:              Ubuntu 22.04 Jammy Jellyfish
Arch:            x86_64
Kernel:          6.5.0-21-generic
Desktop:         ubuntu:GNOME
Display Server:  x11

[CPU]
Vendor:          GenuineIntel
Model:           Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz
Physical cores:  8
Logical cores:   8

[Memory]
RAM:             15.5 GB
Swap:            2.0 GB

[Graphics]
Vendor:          NVIDIA Corporation
OpenGL Renderer: NVIDIA GeForce RTX 2080/PCIe/SSE2
OpenGL Version:  4.6.0 NVIDIA 535.154.05
OpenGL Core:     4.6.0 NVIDIA 535.154.05
OpenGL ES:       OpenGL ES 3.2 NVIDIA 535.154.05
Vulkan:          Supported
```

前提(私の環境)

私の環境は、1つのアカウントでOneDriveの同期を取っている状態です。

以下、私がonedriveを入れたときのコマンドです。

1. onedriveインストール

wget -qO - https://download.opensuse.org/repositories/home:/npreining:/debian-ubuntu-onedrive/xUbuntu_22.04/Release.key | gpg --dearmor | sudo tee /usr/share/keyrings/obs-onedrive.gpg > /dev/null
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/obs-onedrive.gpg] https://download.opensuse.org/repositories/home:/npreining:/debian-ubuntu-onedrive/xUbuntu_22.04/ ./" | sudo tee /etc/apt/sources.list.d/onedrive.list
sudo apt update -y
sudo apt install onedrive -y

2. 起動

※初めからマルチアカウント運用を考えている場合、これ以降は一旦飛ばしていいかも。

onedrive
  1. ログインURLが表示されるため、Ctrl+左クリックでブラウザで開く。

  2. いつものMicrosoftのログイン画面が表示されるため、ログイン。

  3. ターミナルにてresponse uriの入力が求められるので、URLを入力。

    他の記事によると、”認証に成功したらReturnURLが表示される”とあるが、私の環境(ブラウザはVivaldi)では何も表示されない真っ白な画面だった。

    とりあえず、その真っ白画面のURLをコピーしてターミナルに貼り付けたところ、問題なく完了した。

3. 同期

onedrive --synchronize

4. 自動起動の設定

systemctl --user enable onedrive
systemctl --user start onedrive

私は同期の後に自動起動の設定を行ったが、同期の時間を考えると、先に自動起動の設定をしてから同期をさせて気兼ねなく放置したほうが良かったかも。

手順

1. 設定ファイルの作成

  • 設定ファイルの雛形を拾ってきて編集する。(エディタはお好みで。VScodeなら"code”とか。)
mkdir -p ~/.config/onedrive
wget https://raw.githubusercontent.com/abraunegg/onedrive/master/config -O ~/.config/onedrive/config
nano ~/.config/onedrive/config

後々思ったが、このときのフォルダは手順2の新しいフォルダに直接入れても良かったかも。

2. 同期させるフォルダと設定ファイルをしまうフォルダを作成。(ファイル名は各自でつける)

mkdir ~/OneDriveMyAccount1
mkdir ~/.config/onedriveMyAccount1

3. アカウント専用の設定ファイルを作成

  1. 雛形をコピーして、エディタで開く

    cp ~/.config/onedrive/config ~/.config/onedriveMyAccount1/
    nano ~/.config/onedriveMyAccount1/config
    
  2. 設定ファイル編集
    # sync_dir = "~/OneDrive"のフォルダを手順2で作成した同期させるフォルダに書き換えて、コメントアウトを解除

    # Configuration for OneDrive Linux Client
    # This file contains the list of supported configuration fields
    # with their default values.
    # All values need to be enclosed in quotes
    # When changing a config option below, remove the '#' from the start of the line
    # For explanations of all config options below see docs/USAGE.md or the man page.
    #
    - # sync_dir = "~/OneDrive"
    + sync_dir = "~/OneDriveMyAccount1"
    # skip_file = "~*|.~*|*.tmp"
    # monitor_interval = "300"
    # skip_dir = ""
    # log_dir = "/var/log/onedrive/"
    ...
    

    ※設定ファイルの他の項目は以下サイトを参考にして必要であれば変えてもいいかも
    Ubuntu 22.04 でOneDriveを使う

  3. アカウント専用のサービス用の設定ファイルを作成

    1. 既にあるサービス用の設定ファイルをコピーしてエディタで開く

      sudo cp /usr/lib/systemd/user/onedrive.service /usr/lib/systemd/user/onedriveMyAccount1.service
      sudo nano /usr/lib/systemd/user/onedriveMyAccount1.service
      

      このファイルをVScode(code)で開こうとすると、「権限的にVScodeはおすすめしないね。どうしてもやりたいってんなら、こねこねしてもろて。」みたいな文章が帰ってくる。
      私としてはこねこねするのが面倒だったのでnanoエディタで編集した。

    2. サービス用設定ファイルの編集

      ExecStart=/usr/bin/onedrive --monitorの後ろに --confdir="~/.config/onedriveMyAccount"を付け加える

      [Unit]
      Description=OneDrive Free Client
      Documentation=https://github.com/abraunegg/onedrive
      After=network-online.target
      Wants=network-online.target
      
      [Service]
      # Commented out hardenings are disabled because they may not work out of the box on your distribution
      # If you know what you are doing please try to enable them.
      
      ProtectSystem=full
      #PrivateUsers=true
      #PrivateDevices=true
      ProtectHostname=true
      #ProtectClock=true
      ProtectKernelTunables=true
      #ProtectKernelModules=true
      #ProtectKernelLogs=true
      ProtectControlGroups=true
      RestrictRealtime=true
      - ExecStart=/usr/bin/onedrive --monitor
      + ExecStart=/usr/bin/onedrive --monitor --confdir="~/.config/onedriveMyAccount1"
      Restart=on-failure
      RestartSec=3
      RestartPreventExitStatus=3
      
      [Install]
      WantedBy=default.target
      
      

5. 設定ファイルを指定して起動

onedrive --confdir="~/.config/onedriveMyAccount1"
  1. ログインURLが表示されるため、Ctrl+左クリックを押してブラウザで開く

  2. いつものMicrosoftのログイン画面が表示されるため、ログイン

  3. ターミナルにてresponse uriの入力が求められるので、URLを入力

    他の記事によると、”認証に成功したらReturnURLが表示される”とあるが、私の環境(ブラウザはVivaldi)では何も表示されない真っ白な画面だった。

    とりあえず、その真っ白画面のURLをコピーしてターミナルに貼り付けたところ、問題なく完了した。

6. 同期(単発。省略可らしい。)

onedrive --synchronize --confdir="~/.config/onedriveMyAccount1"

7. 常に同期させる設定

onedrive --monitor --confdir="~/.config/onedriveMyAccount1" &

8. 自動起動の設定

systemctl --user enable onedriveMyAccount1
systemctl --user start onedriveMyAccount1

私は同期の後に自動起動の設定を行ったが、同期の時間を考えると、先に自動起動の設定をしてから同期をさせて気兼ねなく放置したほうが良かったかも。

9. 同期させたいアカウントのぶんだけ繰り返す

短時間に繰り返すと、Microsoftアカウントがログイン済み状態になっている可能性があるようなので、ブラウザからログアウトしておくのが安牌らしい。

参考リンク

【備忘録:PC・ソフト】Linux MintでOneDriveをマルチアカウントで使う

Ubuntu 22.04 でOneDriveを使う

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0