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
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"
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 "$@"
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
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
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