Skip to content

Instantly share code, notes, and snippets.

@bryanjhv
Created January 24, 2021 05:18
Show Gist options
  • Save bryanjhv/3b4fccdf0aa4472d3bff7bd518594bb8 to your computer and use it in GitHub Desktop.
Save bryanjhv/3b4fccdf0aa4472d3bff7bd518594bb8 to your computer and use it in GitHub Desktop.
#!/bin/bash
###################################
## ##
## TITLE: ##
## ADB `pm list users` to YAML ##
## ##
## USAGE: ##
## - Download this script. ##
## - Execute it (`bash ...`). ##
## ##
## REQUIREMENTS: ##
## - Bash 4+ (`/bin/bash`) ##
## - ADB (in `$PATH`) ##
## ##
###################################
declare -A FLAGS=(
[0001]=PRIMARY
[0002]=ADMIN
[0004]=GUEST
[0008]=RESTRICTED
[0010]=INITIALIZED
[0020]=MANAGED_PROFILE
[0040]=DISABLED
[0080]=QUIET_MODE
[0100]=EPHEMERAL
[0200]=DEMO
[0400]=FULL
[0800]=SYSTEM
[1000]=PROFILE
)
echo "users:"
while read -r user; do
[[ $user =~ \{(.*)\} ]] || continue
IFS=: read -r id name flags <<<"${BASH_REMATCH[1]}"
echo " - id: $id"
echo " name: $name"
[ "$flags" -eq 0 ] && continue
echo " flags:"
flags=$((16#$flags))
for value in "${!FLAGS[@]}"; do
dec=$((16#$value))
if [ $((flags & dec)) -eq "$dec" ]; then
((flags &= ~dec))
echo " - ${FLAGS[$value]}"
fi
done
done <<<"$(adb shell pm list users)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment