sync_scripts_in_bin_via_nextcloud_between_linux_systems

Differences

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

Link to this comparison view

Next revision
Previous revision
sync_scripts_in_bin_via_nextcloud_between_linux_systems [01.07.2021 14:14] – created Pascal Sutersync_scripts_in_bin_via_nextcloud_between_linux_systems [01.07.2021 16:28] (current) Pascal Suter
Line 15: Line 15:
   sudo apt install fuse-posixovl   sudo apt install fuse-posixovl
  
-then created little startup script stored in ''~Nextcloud/homebin/self'' which moutns the posix overlay as soon as i log in +unfortunately though, posixovl does not provide a mount compatible ''/sbin/mount.posixovl''. Even worse, the ubuntu package at least provides this file, but it is the ''mount.posixovl'' which does not accept the kind of parametners that mount would call. So out of the box it is not possible to use posixovl via fstab which is cumbersome.  
-<code bash Nextcloud/homebin/self/mount.sh>+ 
 +Since I wanted this directory to be mounted automatically, frist tried to write a startup script that would mount the directory upon login to gnome. This works for logging in, however it fails miserably after a logout. The directory stays mounted and becomes inaccessible to the user. I tried to add an unmount in ''/etc/gdm/PostScripts/Default'' but that didn't work either.  
 + 
 +I found the solution on [[https://unix.stackexchange.com/questions/216727/mount-posixovl-using-fstab|stackexchange]] which almost worked.. there where to issues with the solution (at least that's what I thaught):  
 +  - the original binary had to be renamed --> cumbersome when doing updates in the future through apt 
 +  - mount.posixovl.orig was started as root, making the mount inaccessible to my user. passing the ''uid'' argument for fuse did not seem to make a difference 
 + 
 +so slightly modified the script and saved it to ''/sbin/mount.fuse-posixovl'' so that i can use a filesystem type ''fuse-posixovl'' in my fstab and did not need to rename the original file so updates will still work.  
 +<code bash mount.fuse-posixovl>
 #!/bin/bash #!/bin/bash
-cleanup .pxovl.* files for which the actual file has been deleted +wrapper for mount.posixovl to conform with common mount syntax 
-# this .pxovl.* files save access rights etc to files for the posix  +with this wrapper posixovl can be used in fstab
-augmentation, but if the actual file on the lower filesytem gets  +
-# deleted the .pxovl.* file remains there, which can lead to problems +
-# when a new file with the same name is created and immediately  +
-# takes the attributes of the old file+
  
-SOURCE=$HOME/Nextcloud/homebin +# location of the original mount.posixovl 
-TARGET=$HOME/bin+origposixovl="/sbin/mount.posixovl"
  
-if ! mountpoint -$TARGET; then +# gather inputs 
-  for i in $(find $SOURCE/./ -name ".pxovl.*| sed -e 's|^.*/\./||')do  +while [ $# -gt 0 ]; do 
-    if [ "$(basename $i)" == ".pxovl.-o -f $SOURCE/$(echo "$i" | sed -e 's/\.pxovl\.//') ]; then  +        if [[ "$1" == -* ]]; then 
-      echo "cleaning up posix info for $(basename $i)" +                # var is an input switch 
-      rm -f $SOURCE/$i;  +                # we can only use the -o or -F switches 
-    fi +                if [[ "$1== *F* ]]then 
-  done+                        optsF="-F" 
 +                else 
 +                        optsF="" 
 +                fi 
 +                if [[ "$1" == *o* ]]; then 
 +                        shift 
 +                        if [[ "$1== *uid=* ]]; then 
 +                                runas=$(getent passwd $(echo "$1" | sed -E -e 's/^.*uid=([^,]+)(,.*)?$/\1/'| cut -d: -f1) 
 +                        fi 
 +                        optsfuse="-- -o $1" 
 +                else 
 +                        optsfuse="" 
 +                fi 
 +                shift 
 +        else 
 +                # var is a main argument 
 +                sourcedir="$1" 
 +                shift 
 +                if [[ "$1" != -* ]]; then 
 +                        targetdir="$1
 +                        shift 
 +                else 
 +                        targetdir="$sourcedir" 
 +                fi 
 +        fi 
 +done
  
-  now mount the filesytem +verify inputs 
-  echo "mounting $SOURCE to $TARGET+if [ "$sourcedir" == "" ]; then 
-  mount.posixovl -S $SOURCE $TARGET+        echo "no source specified" 
 +        exit 1 
 +fi 
 +if [ "$targetdir== "" ]; then 
 +        echo "no target specified" 
 +        exit 1 
 +fi 
 + 
 +# build mount.posixovl command 
 +if [[ -n "$runas" ]]; then 
 +        su - "${runas}" -c "\"$origposixovl\" $optsF -S \"$sourcedir\" \"$targetdir\" $optsfuse" 
 +else 
 +        "$origposixovl" $optsF -S "$sourcedir" "$targetdir" $optsfuse
 fi fi
 </code> </code>
  
-now I simply added the script as a startup application in Gnome. Since we can't set the excutable bit on this script either, I used the following command to run it in my startup application config:  +now I added this line to fstab and voilà : 
-  /bin/bash -e /home/myuser/Nextcloud/homebin/self/mount.sh +  /home/myuser/Nextcloud/homebin            /home/myuser/bin fuse-posixovl   uid=1000,gid=1000    0 0
-which works like a charm. +
  
 +(i don't think the ''gid=1000'' is doing anything.. but i put it in there anyway)
 +  
 ===== "why didn't you..." ===== ===== "why didn't you..." =====
 ... simply create a startup script that runs ''chmod +x ~/Nextcloud/homebin/*'' on startup? Well, that would have worked and been easier, but i am not very good on shutting down my systems, so some of them run for months and laptops go to standby between active sessions, so the login scripts aren't executed all that often. If i add new scripts in the meantime, they will be synced via nextcloud but won't be executable then.  ... simply create a startup script that runs ''chmod +x ~/Nextcloud/homebin/*'' on startup? Well, that would have worked and been easier, but i am not very good on shutting down my systems, so some of them run for months and laptops go to standby between active sessions, so the login scripts aren't executed all that often. If i add new scripts in the meantime, they will be synced via nextcloud but won't be executable then. 
 +
 ... create a cron job that runs the above ''chmod'' every few minutes? That would have been possible and it probably would have solved the problem sufficiently for this specific case, but i have some other directories where I also want to be able to store posix properties, and there not all the files should be executable. The posixovl solution allows to "disalbe" scripts to make sure they are not accidently executed (they won't appear in tab completion either) and it works instantaneously, as soon as the script is synced it is also executable on all machines. so all in all just more flexible and elegant :)  ... create a cron job that runs the above ''chmod'' every few minutes? That would have been possible and it probably would have solved the problem sufficiently for this specific case, but i have some other directories where I also want to be able to store posix properties, and there not all the files should be executable. The posixovl solution allows to "disalbe" scripts to make sure they are not accidently executed (they won't appear in tab completion either) and it works instantaneously, as soon as the script is synced it is also executable on all machines. so all in all just more flexible and elegant :) 
  
  • sync_scripts_in_bin_via_nextcloud_between_linux_systems.1625141656.txt.gz
  • Last modified: 01.07.2021 14:14
  • by Pascal Suter