-
Notifications
You must be signed in to change notification settings - Fork 0
/
android-system-bin-wrapper.nix
105 lines (92 loc) · 2.24 KB
/
android-system-bin-wrapper.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
{ stdenvNoCC
, lib
, bash
, coreutils
}:
stdenvNoCC.mkDerivation rec {
name = "android-system-bin-wrapper";
installPhase = ''
mkdir -p "$out/bin"
cat <<EOF >"$out/bin/${name}"
#!${lib.getBin bash}/bin/bash
__help() {
cat <<HELP >&2
Usage: \$0 COMMAND [COMMAND OPTIONS]
HELP
}
__linker() {
local CMD_PATH="\$1"
shift
LD_LIBRARY_PATH=/apex/com.android.runtime/lib/ /android/system/bin/linker "\$CMD_PATH" "\$@"
}
__linker64() {
local CMD_PATH="\$1"
shift
LD_LIBRARY_PATH=/apex/com.android.runtime/lib64/ /android/system/bin/linker64 "\$CMD_PATH" "\$@"
}
__sh() {
__linker64 /android/system/bin/sh "\$@"
}
CMD_NAME="\$("${lib.getBin coreutils}/bin/basename" "\$0")"
if [[ \$CMD_NAME == "${name}" ]]; then
case \$# in
0)
__help
exit 1
;;
*)
CMD_NAME="\$1"
shift
;;
esac
fi
CMD_PATH="/android/system/bin/\$CMD_NAME"
if [[ ! -e "\$CMD_PATH" ]]; then
echo "Cannot execute '\$CMD_PATH' which does not exist." >&2
exit 1
fi
REAL_PATH="\$("${lib.getBin coreutils}/bin/realpath" "\$CMD_PATH")"
case "\$(__linker64 /android/system/bin/file "\$REAL_PATH")" in
*stripped*)
"\$CMD_PATH" "\$@"
;;
*/system/bin/linker64*)
__linker64 "\$CMD_PATH" "\$@"
;;
*/system/bin/linker*)
__linker "\$CMD_PATH" "\$@"
;;
*/system/bin/sh*)
__sh "\$CMD_PATH" "\$@"
;;
*"ASCII text"*)
echo "Cannot execute '\$CMD_PATH' which is a plain text file." >&2
exit 1
;;
*directory*)
echo "Cannot execute '\$CMD_PATH' which is a directory." >&2
exit 1
;;
*)
echo "Cannot execute '\$CMD_PATH' which is an unknown type of file." >&2
exit 1
;;
esac
EOF
chmod +x "$out/bin/${name}"
mapfile -t android_bin <"${./android-system-bin.list}"
for i in "''${android_bin[@]}"; do
ln -s "${name}" "$out/bin/$i"
done
'';
dontUnpack = true;
buildInputs = [
bash
coreutils
];
meta = {
maintainers = with lib.maintainers; [ MakiseKurisu ];
description = "Wrappers for /android/system/bin";
platforms = lib.platforms.unix;
};
}