Skip to content

Instantly share code, notes, and snippets.

@DerGoogler
Created November 13, 2022 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DerGoogler/cd126c2b5e1f2527b205d4a8e34c829e to your computer and use it in GitHub Desktop.
Save DerGoogler/cd126c2b5e1f2527b205d4a8e34c829e to your computer and use it in GitHub Desktop.
Manage User via CLI in Android

Multi-User Manager

Manage User via CLI in Android

Running

curl -s https://gist.githubusercontent.com/DerGoogler/cd126c2b5e1f2527b205d4a8e34c829e/raw/188bb04be876a01181740ad72f0be47f4a3d0e42/multi-user.sh | /data/adb/magisk/busybox ash
#!/data/adb/magisk/busybox ash
# Please don't modify this!
MAX_USERS=5
printf "Checking if required binaries are available\n"
for bin in am pm setprop; do
if ! command -v $bin >/dev/null; then
printf "$bin was not found, script is without $bin not useable.\n"
exit 0
fi
done
printf "(1) Change user amount\n"
printf "(2) Create new user\n"
printf "(3) Remove user\n"
printf "(4) Switch current user\n"
read -p "Select option: " OPTION
case $OPTION in
'1' | *[!0-9]*) (
# Read count of users
read -p "Enter User Amount: " USER_AMOUNT
case $USER_AMOUNT in
'' | *[!0-9]*) (
printf "Please enter an number, not an text!\n"
exit 0
) ;;
*) (
if [ $MAX_USERS -lt $USER_AMOUNT ]; then
printf "You can't create more than 5 users!\n"
exit 0
fi
# Set new user amount
setprop fw.max_users $USER_AMOUNT
) ;;
esac
) ;;
'2' | *[!0-9]*) (
read -p "Enter Username: " USER_NAME
if [ -z $USER_NAME ]; then
printf "You can't create an empty username!\n"
exit 0
fi
# Create new user
pm create-user $USER_NAME
) ;;
'3' | *[!0-9]*) (
read -p "Enter User Id: " USER_ID
case $USER_ID in
'' | *[!0-9]*) (
printf "User Id can't be an string!\n"
exit 0
) ;;
*) (
# Remove user
pm remove-user $USER_ID
) ;;
esac
) ;;
'4' | *[!0-9]*) (
read -p "Enter User Id: " USER_ID
printf "Your current user id: \e[93m$(am get-current-user)\e[39m\n"
case $USER_ID in
'' | *[!0-9]*) (
printf "User Id can't be an string!\n"
exit 0
) ;;
*) (
# Switch to new user
am switch-user $USER_ID
) ;;
esac
) ;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment