[Toybox] Tilde expansion test on android?

enh enh at google.com
Wed Jan 8 22:02:00 PST 2020


On Wed, Jan 8, 2020 at 9:38 PM Rob Landley <rob at landley.net> wrote:
>
> On 1/8/20 5:41 PM, enh wrote:
> >> And I'm going... ok, I can get away with just saying ~ and comparing it with
> >> $HOME (which I did in the previous two tests), but if I want an actual username,
> >> the only one guaranteed-ish to be on the system is "root". But though root's
> >> home directory has been "/root" on every Linux distro I've used for the past
> >> decade, it's not actually _required_ by anything?
> >
> > yeah, and it's just / for all users on Android, and /data for all uids
> > that correspond to apps (which is: all uids >= 10000).
>
> I can work with that... except it doesn't?  In the terminal app with mksh:
>
>   $ echo ~
>   /data/user/0/jackpal.androidterm/app_HOME

well, if you set $HOME, you get whatever you set for ~ --- that's a
special case in the shell:

  blueline:/ # HOME="/your/mum's/house"
  blueline:/ # echo ~
  /your/mum's/house
  blueline:/ #

> I do get / from echo ~root though. I can also do whoami and ~ that string to
> compare against $HOME... except echo ~u0_a174 is giving me /data and $HOME is
> giving me the app_HOME path. But then ~ is always basically printing out $HOME,
> so it sounds like an .rc file or something set $HOME weirdly...

more likely your terminal app when it execed, but, yeah, something like that.

> >> Anyway, tl;dr: ~root isn't guaranteed to expand to /root but nothing _else_ is
> >> likely to consistently expand to anything, and I wanna write tilde expansion
> >> tests. Suggestions?
> >
> > slap in another of our "wait, is this Android?" checks and skip this
> > test there? `[ $(id -u shell) -eq 2000 ]` would be an appropriately
> > uid-themed check.
>
> What _is_ a "wait, is this Android" check? (I can ANDROID_NDK in C but in a
> shell script, _not_ checking ? uname -s says Linux... [ -d /system/bin ] maybe?)

we've tended to use something specific to what we're testing. stuff
like "if you don't have X". i think the only _literal_ OS test we have
is actually for macOS. but, yeah, checking for /system/bin/ isn't
unreasonable. i sometimes have that on my host for testing x86-64
Android binaries locally, but that's also true for /data/local/tmp or
checking whether $ANDROID_DATA is set, or whether there's a dalvikvm
on your path. `getprop ro.build.fingerprint`, or even just checking
whether there's a getprop on the path?

it looks like debian says /nonexistent for ~nobody, and macOS says
/var/empty. so that's probably good enough for non-Android? oh, but
~root works on macOS too anyway --- /var/root.

> Rob



More information about the Toybox mailing list