This is an old revision of the document!
sync scripts in ~/bin via Nextcloud between Linux systems
I use Nextcloud to store and synchronize my files between my devices. These also include a couple of Linux PC's. I'm not using a roaming profile, so my home
directory is local to every machine and that is okay, because they are different machines with different setups. However, over the time i've used linux, i have collected some handy bash scripts for my daily work which facilitate a couple of repeditive tasks and i would like to have those tools synced across all my linux machines, so they are updated on all of them if I add a new one or enhance an existing one.
I have therefore created a folder named homebin
in my Nextcloud account, which is then synced using the Nextcloud client to ~/Nextcloud/homebin
.
The Problem
The problem with Nextcloud is, that it does not sync permissions of files, so all the files in the ~/Nextcloud/hoembin
could be made executable locally, but when synced, would not be executable on the other machines. Initially, i created an alias for each script in my .bash_aliases
file but that became cumbersome as I have to add new entries for each script on all of my PC's.
My Solution
I recently found a tool called posixovl which stands probably for POSIX Overlay :)
this tool allows us to turn a non-posix capable directory into a posix capable mountpoint. Its main purpose is to add POSIX features to VFAT formatted filesystems, however, it also works on top of filesystems that are already posix capable (like in our case).
on ubuntu, posixovl is available via the repos, so it can simply be installed using
sudo apt install fuse-posixovl
I then created a little startup script stored in ~Nextcloud/homebin/self
which moutns the posix overlay as soon as i log in:
- Nextcloud/homebin/self/mount.sh
#!/bin/bash # cleanup .pxovl.* files for which the actual file has been deleted # this .pxovl.* files save access rights etc to files for the posix # 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 TARGET=$HOME/bin if ! mountpoint -q $TARGET; then for i in $(find $SOURCE/./ -name ".pxovl.*" | sed -e 's|^.*/\./||'); do if ! [ "$(basename $i)" == ".pxovl." -o -f $SOURCE/$(echo "$i" | sed -e 's/\.pxovl\.//') ]; then echo "cleaning up posix info for $(basename $i)"; rm -f $SOURCE/$i; fi; done # now mount the filesytem echo "mounting $SOURCE to $TARGET" mount.posixovl -S $SOURCE $TARGET fi
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:
/bin/bash -e /home/myuser/Nextcloud/homebin/self/mount.sh
which works like a charm.
"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.
… 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 :)