[OpenWrt-Devel] [PATCH] base-files: add list-enabled/disabled to service function in /etc/profile

Stan Grishin stangri at melmac.net
Wed Jun 3 07:42:30 EDT 2020


Implement service list-enabled and service list-disabled to provide an easy way
for users to list enabled/disabled services from CLI.

Signed-off-by: Stan Grishin <stangri at melmac.net>
---
 package/base-files/files/etc/profile | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/package/base-files/files/etc/profile
b/package/base-files/files/etc/profile
index 0beff1608f..e8350cfd6a 100644
--- a/package/base-files/files/etc/profile
+++ b/package/base-files/files/etc/profile
@@ -38,3 +38,24 @@ in order to prevent unauthorized SSH logins.
 --------------------------------------------------
 EOF
 fi
+
+service() {
+        if [ "$1" = "list-enabled" ]; then
+                for F in /etc/init.d/* ; do
+                        $F enabled && echo "$F enabled"
+                done;
+        elif [ "$1" = "list-disabled" ]; then
+                for F in /etc/init.d/* ; do
+                        $F enabled || echo "$F disabled"
+                done;
+        elif [ -f "/etc/init.d/$1" ]; then
+                /etc/init.d/$@
+        else
+                echo "Usage: service
list-disabled|list-enabled|<service> [command]"
+                if [ -n "$1" ]; then
+                        echo "service "'"'"$1"'"'" not found, the
following services are available:"
+                        ls "/etc/init.d"
+                fi
+                return 1
+        fi
+}
-- 
2.25.1

_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list