From d180654589975e952ca008db66ba0ff9e99499f6 Mon Sep 17 00:00:00 2001 From: firefoxlover <78762110+firefoxlover@users.noreply.github.com> Date: Mon, 9 Oct 2023 21:48:37 +0000 Subject: [PATCH 1/6] Added immutability check to change install variables This was pretty easy. Everything sets up normally, even though the main program still has some hardcoded mutable-OS dependencies. If the system is mutable, everything will stay the same --- install.sh | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/install.sh b/install.sh index fef07dd..33dc965 100755 --- a/install.sh +++ b/install.sh @@ -1,12 +1,30 @@ #!/usr/bin/env bash +# Check if the system is immutable and set directory variables. +if touch sudo /bin/testfile 2>/dev/null; then + # System is not immutable + sudo rm -f /bin/testfile + maindir="/usr" + bindir="/usr/bin" + libdir="/usr/lib" + sharedir="/usr/share" + applicationsdir="/usr/share/applications" +else + # System is immutable + maindir="$HOME/.local/" + bindir="$HOME/.local/bin" + libdir="$HOME/.local/lib" + sharedir="$HOME/.local/share" + applicationsdir="$HOME/.local/share/applications" +fi + # Check if script is from cloned repo or just coppied from github if [ -n "$(git config --get remote.origin.url)" ]; then - echo "" + echo echo "Cloned repo" CLONED=true else - echo "" + echo echo "Copied from github" TEMPDIR=`mktemp -d` CLONED=false @@ -19,16 +37,16 @@ if [ "$CLONED" = false ]; then cd $TEMPDIR fi -echo "" +echo echo "Installing..." -sudo cp -r usr/* /usr/ -sudo chmod +x /usr/bin/waydroid-settings -sudo chmod +x /usr/bin/waydroid-helper -sudo update-desktop-database /usr/share/applications -sudo update-icon-caches /usr/share/icons/hicolor +sudo cp -r usr/* $maindir #what does this do +sudo chmod +x $bindir/waydroid-settings +sudo chmod +x $bindir/waydroid-helper +sudo update-desktop-database $applicationsdir +sudo update-icon-caches $maindir/icons/hicolor # if scripts/* exist, then copy those to ~/.local/share/waydroid-settings -echo "" +echo echo "Copying scripts to ~/.local/share/waydroid-settings" if [ -n "$(find scripts -maxdepth 1 -type f)" ]; then @@ -45,7 +63,7 @@ fi # if CLONEED == false, then cleanup ~/.local/share/waydroid-settings if [ "$CLONED" = false ]; then - echo "" + echo echo "Cleaning up" rm -rf $TEMPDIR -fi \ No newline at end of file +fi From e25467d98cf94fd4d390c9bf7791d21941777798 Mon Sep 17 00:00:00 2001 From: firefoxlover <78762110+firefoxlover@users.noreply.github.com> Date: Mon, 9 Oct 2023 21:57:20 +0000 Subject: [PATCH 2/6] variable immutable-friendly directories Unsure about the polkit rules. The immutable version is work in progress, the current way is unchanged, again. Afaik one should not write polkit rules to /usr but to /etc in general --- uninstall.sh | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/uninstall.sh b/uninstall.sh index 98df988..0357074 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -1,11 +1,27 @@ #!/usr/bin/env bash +# Check if the system is immutable and set directory variables. +if sudo touch /bin/testfile 2>/dev/null; then + # System is not immutable + sudo rm -f /bin/testfile + bindir="/usr/bin" + sharedir="/usr/share" + applicationsdir="/usr/share/applications" + polkitdir="/usr/share/polkit-1" +else + # System is immutable + bindir="$HOME/.local/bin" + sharedir="$HOME/.local/share" + applicationsdir="$HOME/.local/share/applications" + polkitdir="/etc/polkit-1/" +fi + sudo rm -rf $HOME/.local/share/waydroid-settings /usr/share/waydroid-settings /usr/lib/waydroid-settings -sudo rm -f /usr/bin/waydroid-settings -sudo rm -f /usr/bin/waydroid-helper -sudo rm -f /usr/share/applications/waydroid-settings.desktop -sudo rm -f /usr/share/applications/install-to-waydroid.desktop -sudo rm -f /usr/share/icons/hicolor/512x512/apps/cu.axel.WaydroidSettings.png -sudo rm -f /usr/share/polkit-1/actions/org.freedesktop.policykit.waydroid-helper.policy +sudo rm -f $bindir/waydroid-settings +sudo rm -f $bindir/waydroid-helper +sudo rm -f $applicationsdir/waydroid-settings.desktop +sudo rm -f $applicationsdir/install-to-waydroid.desktop +sudo rm -f $sharedir/icons/hicolor/512x512/apps/cu.axel.WaydroidSettings.png +sudo rm -f $polkitdir/actions/org.freedesktop.policykit.waydroid-helper.policy echo "Waydroid Settings has been uninstalled" From 02ee2ba7f51247090d14ae168635f8a1acb18624 Mon Sep 17 00:00:00 2001 From: firefoxlover <78762110+firefoxlover@users.noreply.github.com> Date: Mon, 9 Oct 2023 21:59:34 +0000 Subject: [PATCH 3/6] variable lib-dir --- usr/bin/waydroid-settings | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/usr/bin/waydroid-settings b/usr/bin/waydroid-settings index b9683f1..b529414 100755 --- a/usr/bin/waydroid-settings +++ b/usr/bin/waydroid-settings @@ -1,2 +1,12 @@ #!/usr/bin/env bash -/usr/lib/waydroid-settings/waydroid-settings.py "$@" + +# Check if the system is immutable and set directory variables. +if sudo touch /bin/testfile 2>/dev/null; then + # System is not immutable + libdir="/usr/lib" +else + # System is immutable + libdir="$HOME/.local/lib" +fi + +$libdir/waydroid-settings/waydroid-settings.py "$@" From f3bb753475b8b177300d9b228523c3c5b94238b8 Mon Sep 17 00:00:00 2001 From: firefoxlover <78762110+firefoxlover@users.noreply.github.com> Date: Mon, 9 Oct 2023 22:11:04 +0000 Subject: [PATCH 4/6] replaced all necessary paths with variables also used the python version of immutability detection. Looks good to me, should be checked. --- usr/lib/waydroid-settings/utils.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/usr/lib/waydroid-settings/utils.py b/usr/lib/waydroid-settings/utils.py index 8a63d2a..c6dbb6d 100644 --- a/usr/lib/waydroid-settings/utils.py +++ b/usr/lib/waydroid-settings/utils.py @@ -3,6 +3,28 @@ from pathlib import Path from gi.repository import GLib +# 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") + PROP_FREE_FORM = 'persist.waydroid.multi_windows' PROP_INVERT_COLORS = '' PROP_SUSPEND_INACTIVE = 'persist.waydroid.suspend' @@ -20,7 +42,7 @@ # System.img paths SYSTEM_IMAGE1 = '/var/lib/waydroid/images/system.img' -SYSTEM_IMAGE2 = '/usr/share/waydroid-extra/images/system.img' +SYSTEM_IMAGE2 = '{sharedir}/waydroid-extra/images/system.img' # Check whether the specified path exists # Depending on install type, this might change @@ -37,7 +59,7 @@ def run(command, as_root=False): try: if as_root: - subprocess.run(['pkexec', '/usr/bin/waydroid-helper', command]) + subprocess.run(['pkexec', '{bindir}/waydroid-helper', command]) else: subprocess.run(command, shell=True) return True @@ -68,7 +90,7 @@ def set_prop(name, value): def run_shell_command(command, as_root=False): try: if as_root: - subprocess.run('pkexec /usr/bin/waydroid-helper ' + '" | echo "' + command + '" | sudo -S waydroid shell"', text=True) + subprocess.run('pkexec {bindir}/waydroid-helper ' + '" | echo "' + command + '" | sudo -S waydroid shell"', text=True) else: subprocess.run(command, shell=True) return True From 5832e56b7ee938c6348c31eb1b963c2d07e2603f Mon Sep 17 00:00:00 2001 From: firefoxlover <78762110+firefoxlover@users.noreply.github.com> Date: Mon, 9 Oct 2023 22:14:43 +0000 Subject: [PATCH 5/6] removed sudo not needed --- usr/share/applications/install-to-waydroid.desktop | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr/share/applications/install-to-waydroid.desktop b/usr/share/applications/install-to-waydroid.desktop index 80b19a9..216cfad 100644 --- a/usr/share/applications/install-to-waydroid.desktop +++ b/usr/share/applications/install-to-waydroid.desktop @@ -2,7 +2,7 @@ Icon=cu.axel.WaydroidSettings Type=Application Name=Install to Waydroid -Exec=sudo waydroid app install %F +Exec=waydroid app install %F MimeType=application/vnd.android.package-archive Terminal=true NoDisplay=true From 481ec7faba72d1c5ae399bd2eb01ed8fe9ee4985 Mon Sep 17 00:00:00 2001 From: firefoxlover <78762110+firefoxlover@users.noreply.github.com> Date: Mon, 9 Oct 2023 22:18:27 +0000 Subject: [PATCH 6/6] added ~/.local/bin/ path to annotate keys this should just work normally --- .../actions/org.freedesktop.policykit.waydroid-helper.policy | 1 + 1 file changed, 1 insertion(+) diff --git a/usr/share/polkit-1/actions/org.freedesktop.policykit.waydroid-helper.policy b/usr/share/polkit-1/actions/org.freedesktop.policykit.waydroid-helper.policy index e3ccce7..21bef85 100644 --- a/usr/share/polkit-1/actions/org.freedesktop.policykit.waydroid-helper.policy +++ b/usr/share/polkit-1/actions/org.freedesktop.policykit.waydroid-helper.policy @@ -13,6 +13,7 @@ auth_admin_keep /usr/bin/waydroid-helper + $HOME/.local/bin/waydroid-helper true