axel358 / waydroid-settings

GTK app written in Python to control Waydroid settings
87 stars 12 forks source link

Remove hardcoding of install dirs for immutable OSses #11

Open secretmango opened 1 year ago

secretmango commented 1 year ago

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

secretmango commented 9 months ago
# 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.

secretmango commented 9 months ago

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:

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.

secretmango commented 9 months ago

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...
secretmango commented 9 months ago

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