[Replicant] [replicant-scripts][PATCH 2/8] modem.sh: warn users if executing without root permissions
Denis 'GNUtoo' Carikli
GNUtoo at cyberdimension.org
Fri Jun 19 04:08:43 UTC 2020
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo at cyberdimension.org>
---
networking/modem/device-files/modem.sh | 40 ++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/networking/modem/device-files/modem.sh b/networking/modem/device-files/modem.sh
index 626593b..b27aadd 100755
--- a/networking/modem/device-files/modem.sh
+++ b/networking/modem/device-files/modem.sh
@@ -34,10 +34,50 @@ usage()
exit 1
}
+check_permissions()
+{
+ modem_command="$1"
+ root_access="$(getprop persist.sys.root_access)"
+ uid="$(id -u)"
+
+ # 0: Root access: Disabled, 2: Root access: ADB only
+ # For both the terminal application and ADB we have something
+ # like that:
+ # shell at i9100:/ $ su
+ # 255|shell at i9100:/ $
+ # 1: Root access: Apps only
+ # From ADB:
+ # shell at i9100:/ $ su
+ # Permission denied
+ # 1|shell at i9100:/ $
+ # From the terminal application
+ # u0_a51 at i9100:/ $ su
+ # root at i9100:/ #
+ if [ "${uid}" != "0" ] ; then
+ echo ""
+ echo "This script requires root."
+ echo "To give it root:"
+ case "${root_access}" in
+ "0"|"1"|"2")
+ echo "- Go in Settings"
+ echo "- Go in Developer options"
+ echo "- Select Root access"
+ echo "- Set it to \"Apps and ADB\""
+ ;;
+ esac
+ echo "- Run these 2 commands:"
+ echo " su"
+ echo " modem.sh ${modem_command}"
+ exit 1
+ fi
+}
+
modem()
{
command="$1"
+ check_permissions "${command}"
+
echo "Remounting system partition as writable..."
mount -o rw,remount /system
--
2.27.0
More information about the Replicant
mailing list