waydroid-settings
waydroid-settings copied to clipboard
Remove hardcoding of install dirs for immutable OSses
I dont know if there is a way to fix this, but this script currently doesnt work on ostree filesystems, where a lot is read-only or stored in /var/
Otherwise if I have the time I can fork it
# Check if the system is immutable
if touch /bin/testfile 2>/dev/null; then
# System is not immutable
bindir="/usr/bin"
libdir="/usr/lib"
sharedir="/usr/share"
else
# System is immutable
bindir="$HOME/.local/bin"
libdir="$HOME/.local/lib"
sharedir="$HOME/.local/share"
fi
Detect if the system is read only. Change the installscripts filepaths to ~/.local/$original-path
in that case.
See my pull which aims to fix it
detecting an immutable system filesystem is really easy. Just attempt to write a file to one of these dirs:
- usr
- sys
- bin
- sbin
and if it fails, its immutable OR the user has no sudo rights. In either way, it may be best to not install it to the system but to the users ~/.local/
directory. Actually, this should be the standard. I am just not sure if my implementation is the best.
If the app was packaged as an RPM, it could be installed to the root filesystem. But this is not needed probably.
Now the question is how to detect the immutability in python using the os
library. Some AI told me:
import os
# Function to check if a directory is writable
def is_writable(directory):
try:
with open(os.path.join(directory, 'testfile'), 'w'):
pass
os.remove(os.path.join(directory, 'testfile'))
return True
except IOError:
return False
# Check if the system is immutable
if is_writable('/bin'):
# System is not immutable
bindir = "/usr/bin"
libdir = "/usr/lib"
sharedir = "/usr/share"
else:
# System is immutable
bindir = os.path.expanduser("~/.local/bin")
libdir = os.path.expanduser("~/.local/lib")
sharedir = os.path.expanduser("~/.local/share")
# Rest of your script...
Current problem when installing:
mkdir: the directory „/home/user/.local/share/waydroid-settings/scripts“ could not be created, no permission
cp: destination '/home/user/.local/share/waydroid-settings/scripts': file or directory not found