Skip to content

Commit

Permalink
Create servistatus
Browse files Browse the repository at this point in the history
  • Loading branch information
rompelhd authored May 27, 2024
1 parent 198e661 commit 8483932
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions system/etc/servistatus
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/sh

checkroot() {
if [ "$(id -u)" -ne 0 ]; then
echo "U need root for using. Exiting..."
exit 1
fi
}

list_services() {
echo "Listing all available services in table format:"
services=$(dumpsys -l)

sorted_services=$(echo "$services" | awk '{ print length, $0 }' | sort -n | cut -d" " -f2-)

column_count=4
current_column=0

for service in $sorted_services; do
printf "%-25s" "$service"
current_column=$((current_column + 1))

if [ $current_column -ge $column_count ]; then
echo
current_column=0
fi
done

if [ $current_column -ne 0 ]; then
echo
fi
}

show_service_info() {
local service_name=$1
if [ -z "$service_name" ]; then
echo "Please provide a service name to show details."
return 1
fi
dumpsys $service_name
}

if [ "$#" -eq 0 ]; then
checkroot
list_services
echo "Usage: $0 [service_name]"
elif [ "$1" = "--help" ]; then
echo "Usage: $0 [service_name]"
echo "Options:"
echo " service_name Display details of the specified service"
echo " --help Show this help message"
else
checkroot
show_service_info $1
fi

0 comments on commit 8483932

Please sign in to comment.