User Tools

Site Tools


linux:sharepoint

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
linux:sharepoint [2021/11/22 02:28] – created Wulf Rajeklinux:sharepoint [2023/05/29 11:55] (current) – external edit 127.0.0.1
Line 40: Line 40:
 </code> </code>
  
 +====== Use in fstab ======
  
-#to use in fstab, create wrapper using:+to use in fstab, create wrapper using:
 <code> <code>
 sudo ln -s /usr/bin/rclone /sbin/mount.rclone sudo ln -s /usr/bin/rclone /sbin/mount.rclone
Line 47: Line 48:
 then it can be used in fstab like: then it can be used in fstab like:
 <code> <code>
-whatevername: /path/to/mount/point rclone rw,noauto,nofail,_netdev,x-systemd.automount,args2env,vfs_cache_mode=writes,config=/etc/rclone.conf,cache_dir=/var/cache/rclone 0 0+whatevername: /path/to/mount/point rclone user,rw,noauto,nofail,_netdev,x-systemd.automount,args2env,vfs_cache_mode=writes,rc.config=/etc/rclone.conf,cache_dir=/var/cache/rclone 0 0
 </code> </code>
 +
 +or better use rclonefspy script
 +https://forum.rclone.org/t/auto-mount-from-fstab-entry-with-systemd-options/23897
 +<code - /usr/local/bin/rclonefspy>
 +#!/usr/bin/env python3
 +from os import environ
 +from time import sleep
 +import sys
 +from subprocess import check_call, check_output, CalledProcessError,TimeoutExpired, Popen, PIPE
 +
 +def write_to_journal(string):
 +    check_output(['systemd-cat'], input=string.encode('utf-8'))
 +
 +write_to_journal('rclone-script started')
 +
 +# Save passed arguments
 +remote_mount = sys.argv[1]
 +local_mount = sys.argv[2]
 +sys_args = sys.argv[4].split(',')
 +
 +# Must add path to environment in order for rclone mount to work
 +env = environ.copy()
 +output_raw = check_output(['whereis', 'rclone'],)
 +##path = output_raw.decode('utf-8').split(' ')[1].removesuffix('/rclone')
 +path = "/usr/bin"
 +env['PATH'] = path
 +
 +# If path extraction does not work enter desired path here
 +# env['PATH'] = '/usr/bin'
 +
 +options = []
 +discarded_options = []
 +
 +# Load options for rclone mount to consume
 +for arg in sys_args:
 +    if not arg.startswith('rc.'):
 +        discarded_options.append(arg)
 +        continue
 +    options.append(f'--{arg[3:]}')
 +
 +write_to_journal(f'rclone-script options: {options}')
 +write_to_journal(f'rclone-script discarded options: {discarded_options}')
 +
 +# Mount folder, if this doesn't work try with full path for rclone
 +output = Popen(
 +    ['rclone', 'mount', *options, remote_mount, local_mount ], env=env,
 +    stdout=PIPE, stderr=PIPE, close_fds=True, shell=False,
 +)
 +try:
 +    output.wait(1)
 +except TimeoutExpired as e:
 +    # Must wait for mount to be seen, in order for systemd not to complain
 +    write_to_journal('rclone-script rclone mount success')
 +    for tries in range(1, 20):
 +        try:
 +            check_call(['mountpoint', local_mount], env=env)
 +            write_to_journal(f'rclone-script mount found after {tries} tries')
 +            break
 +        except CalledProcessError:
 +            write_to_journal('rclone-script mount not found, sleeping')
 +            sleep(0.1)
 +    else:
 +        write_to_journal('rclone-script mount not found, not looking anymore')
 +        sys.exit(1)
 +
 +    sys.exit(0)
 +else:
 +    write_to_journal(f'rclone-script mount failed. ErrMsg: {output.stderr.read().decode("utf-8")}')
 +    sys.exit(1)
 +</code>
 +<code>
 +sudo chmod 755 /usr/local/bin/rclonefspy
 +</code>
 +Then use
 +<code>
 +gdrive: /mnt/gdrive fuse.rclonefspy user,noauto,x-systemd.automount,_netdev,x-systemd.mount-timeout=30,x-systemd.idle-timeout=10min,rc.allow-other,rc.fast-list,rc.drive-export-formats=.link.html,rc.config=/home/user/.config/rclone/rclone.conf 0 0
 +</code>
 +For troubleshooting use:
 +<code>
 +journalctl -b | grep rclone
 +</code>
 +
 +====== systemd service ======
 +
 +https://gist.github.com/kabili207/2cd2d637e5c7617411a666d8d7e97101
 +
 +Fuse config required for user systemd service:
 +<code - /etc/fuse.conf>
 +# Allow non-root users to specify the allow_other or allow_root mount options.
 +user_allow_other
 +</code>
 +
 +<code - rclone@.service>
 +# User service for Rclone mounting
 +#
 +# Place in ~/.config/systemd/user/
 +# File must include the '@' (ex rclone@.service)
 +# As your normal user, run 
 +#   systemctl --user daemon-reload
 +# You can now start/enable each remote by using rclone@<remote>
 +#   systemctl --user enable rclone@dropbox
 +#   systemctl --user start rclone@dropbox
 +
 +[Unit]
 +Description=rclone: Remote FUSE filesystem for cloud storage config %i
 +Documentation=man:rclone(1)
 +After=network-online.target
 +Wants=network-online.target 
 +AssertPathIsDirectory=%h/mnt/%i
 +
 +[Service]
 +Type=notify
 +ExecStart= \
 +  /usr/bin/rclone mount \
 +    --config=%h/.config/rclone/rclone.conf \
 +    --fast-list \
 +    --vfs-cache-mode writes \
 +    --vfs-cache-max-size 100M \
 +    --log-level INFO \
 +    --log-file /tmp/rclone-%i.log \
 +    --umask 022 \
 +    --allow-other \
 +    %i: %h/mnt/%i
 +ExecStop=/bin/fusermount -u %h/mnt/%i
 +
 +[Install]
 +WantedBy=default.target
 +</code>
 +
 +To hide Sharepoint's Forms directories, add:
 +<code>
 +    --exclude "/Forms/" \
 +</code>
 +
 +
 +====== WebDAV2 process ======
 +
 +#https://shui.azurewebsites.net/2018/01/13/mount-onedrive-for-business-on-headless-linux-vps-through-webdav/
 +
 +<code>
 +sudo apt-get install -y davfs2
 +#unprivileged users: yes
 +sudo chmod 777 /etc/davfs2/davfs2.conf
 +echo "use_locks 0" >> /etc/davfs2/davfs2.conf
 +
 +wget https://raw.githubusercontent.com/yulahuyed/test/master/get-sharepoint-auth-cookie.py
 +
 +python get-sharepoint-auth-cookie.py https://SHAREPOINTSITE USERNAME PASSWORD > cookie.txt
 +
 +sed -i "s/ //g" cookie.txt
 +COOKIE=$(cat cookie.txt)
 +sudo chmod 777 /etc/davfs2/davfs2.conf
 +for MPATH in {Funds/Funds,IT/IT,Research/Research,SalesSP/Sales}
 +do
 +  echo "[${MPATH}]" >> /etc/davfs2/davfs2.conf
 +  echo "add_header Cookie ${COOKIE}" >> /etc/davfs2/davfs2.conf
 +  echo "" >> /etc/davfs2/davfs2.conf
 +done
 +
 +for MPATH in {Funds/Funds,IT/IT,Research/Research,SalesSP/Sales};
 +do
 +  echo "https://SITENAME.sharepoint.com/sites/${MPATH} USERNAME PASSWORD" >> /etc/davfs2/secrets
 +done
 +
 +sudo chmod 755 /etc/davfs2/davfs2.conf
 +
 +sudo usermod -a -G davfs2 $USER
 +
 +#apply the new group in the shell
 +su - $USER
 +
 +for PATH in {funds,it,research,sales};
 +do
 +  mkdir -p ~/sharepoint/SITE-${PATH}
 +  mount ~/sharepoint/SITE-${PATH}/
 +done;
 +</code>
 +
 +The cookie will become invalid after about 3 weeks of inactivity.
 +
 +fstab entry example
 +<code>
 +https://SITENAME.sharepoint.com/sites/sitename/foldername /home/USER/sharepoint/SITE-SITENAME davfs users,rw,_netdev 0 0
 +</code>
 +
 +https://wiki.archlinux.org/title/Davfs2
linux/sharepoint.1637548134.txt.gz · Last modified: (external edit)