Skip to content

Commit 16a7785

Browse files
feat. run alpine without shizuku or root
1 parent 027b9b3 commit 16a7785

File tree

30 files changed

+260
-561
lines changed

30 files changed

+260
-561
lines changed

app/build.gradle.kts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
import java.util.Properties
2+
import com.android.build.gradle.internal.tasks.factory.dependsOn
3+
import java.io.BufferedOutputStream
4+
import java.io.FileInputStream
5+
import java.io.FileOutputStream
6+
import java.net.URI
7+
import java.security.DigestInputStream
8+
import java.security.MessageDigest
29

310
plugins {
411
alias(libs.plugins.androidApplication)
@@ -108,6 +115,69 @@ android {
108115
}
109116
}
110117

118+
fun downloadFile(localUrl: String, remoteUrl: String, expectedChecksum: String) {
119+
val digest = MessageDigest.getInstance("SHA-256")
120+
121+
val file = File(projectDir, localUrl)
122+
if (file.exists()) {
123+
val buffer = ByteArray(8192)
124+
val input = FileInputStream(file)
125+
while (true) {
126+
val readBytes = input.read(buffer)
127+
if (readBytes < 0) break
128+
digest.update(buffer, 0, readBytes)
129+
}
130+
var checksum = BigInteger(1, digest.digest()).toString(16)
131+
while (checksum.length < 64) { checksum = "0$checksum" }
132+
if (checksum == expectedChecksum) {
133+
return
134+
} else {
135+
logger.warn("Deleting old local file with wrong hash: $localUrl: expected: $expectedChecksum, actual: $checksum")
136+
file.delete()
137+
}
138+
}
139+
140+
logger.quiet("Downloading $remoteUrl ...")
141+
142+
file.parentFile.mkdirs()
143+
val out = BufferedOutputStream(FileOutputStream(file))
144+
145+
val connection = URI(remoteUrl).toURL().openConnection()
146+
val digestStream = DigestInputStream(connection.inputStream, digest)
147+
digestStream.transferTo(out)
148+
out.close()
149+
150+
var checksum = BigInteger(1, digest.digest()).toString(16)
151+
while (checksum.length < 64) { checksum = "0$checksum" }
152+
if (checksum != expectedChecksum) {
153+
file.delete()
154+
throw GradleException("Wrong checksum for $remoteUrl:\n Expected: $expectedChecksum\n Actual: $checksum")
155+
}
156+
}
157+
158+
tasks.register("downloadPrebuilt") {
159+
doLast {
160+
val prootTag = "proot-2025.01.15-r2"
161+
val prootVersion = "5.1.107-66"
162+
var prootUrl = "https://github.com/termux-play-store/termux-packages/releases/download/${prootTag}/libproot-loader-ARCH-${prootVersion}.so"
163+
164+
downloadFile("src/main/jniLibs/armeabi-v7a/libproot-loader.so", prootUrl.replace("ARCH", "arm"), "eb1d64e9ef875039534ce7a8eeffa61bbc4c0ae5722cb48c9112816b43646a3e")
165+
downloadFile("src/main/jniLibs/arm64-v8a/libproot-loader.so", prootUrl.replace("ARCH", "aarch64"), "8814b72f760cd26afe5350a1468cabb6622b4871064947733fcd9cd06f1c8cb8")
166+
downloadFile("src/main/jniLibs/x86_64/libproot-loader.so", prootUrl.replace("ARCH", "x86_64"), "1a52cc9cc5fdecbf4235659ffeac8c51e4fefd7c75cc205f52d4884a3a0a0ba1")
167+
prootUrl = "https://github.com/termux-play-store/termux-packages/releases/download/${prootTag}/libproot-loader32-ARCH-${prootVersion}.so"
168+
downloadFile("src/main/jniLibs/arm64-v8a/libproot-loader32.so", prootUrl.replace("ARCH", "aarch64"), "ff56a5e3a37104f6778420d912e3edf31395c15d1528d28f0eb7d13a64481b99")
169+
downloadFile("src/main/jniLibs/x86_64/libproot-loader32.so", prootUrl.replace("ARCH", "x86_64"), "5460a597e473f57f0d33405891e35ca24709173ca0a38805d395e3544ab8b1b4")
170+
}
171+
}
172+
173+
afterEvaluate {
174+
android.applicationVariants.all { variant ->
175+
variant.javaCompileProvider.dependsOn("downloadPrebuilt")
176+
true
177+
}
178+
}
179+
180+
111181
dependencies {
112182
//coreLibraryDesugaring(libs.desugar.jdk.libs)
113183
implementation(project(":core:main"))
5.87 KB
Binary file not shown.
6.23 KB
Binary file not shown.
5.55 KB
Binary file not shown.
5.91 KB
Binary file not shown.
5.86 KB
Binary file not shown.

core/main/build.gradle.kts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,8 @@ dependencies {
110110
api(libs.okhttp)
111111
api(libs.anrwatchdog)
112112
api(libs.androidx.palette)
113-
api("com.google.accompanist:accompanist-systemuicontroller:0.36.0")
113+
api(libs.accompanist.systemuicontroller)
114114

115115
api(project(":core:resources"))
116116
api(project(":core:components"))
117-
118-
api(project(":core:rish"))
119117
}

core/main/src/main/assets/exec.sh

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
ALPINE_DIR=$PREFIX/local/alpine
2+
3+
mkdir -p $ALPINE_DIR
4+
5+
if [ -z "$(ls -A "$ALPINE_DIR")" ]; then
6+
echo "Extracting files..."
7+
tar -xf $PREFIX/files/alpine.tar.gz -C $ALPINE_DIR
8+
fi
9+
10+
[ ! -e "$PREFIX/local/bin/proot" ] && cp "$PREFIX/files/proot" "$PREFIX/local/bin"
11+
12+
for sofile in "$PREFIX/files/"*.so.2; do
13+
dest="$PREFIX/local/lib/$(basename "$sofile")"
14+
[ ! -e "$dest" ] && cp "$sofile" "$dest"
15+
done
16+
17+
18+
ARGS="--kill-on-exit"
19+
ARGS="$ARGS -w /"
20+
21+
for system_mnt in /apex /odm /product /system /system_ext /vendor \
22+
/linkerconfig/ld.config.txt \
23+
/linkerconfig/com.android.art/ld.config.txt \
24+
/plat_property_contexts /property_contexts; do
25+
26+
if [ -e "$system_mnt" ]; then
27+
system_mnt=$(realpath "$system_mnt")
28+
ARGS="$ARGS -b ${system_mnt}"
29+
fi
30+
done
31+
unset system_mnt
32+
33+
ARGS="$ARGS -b /sdcard"
34+
ARGS="$ARGS -b /storage"
35+
ARGS="$ARGS -b /dev"
36+
ARGS="$ARGS -b /data"
37+
ARGS="$ARGS -b /dev/urandom:/dev/random"
38+
ARGS="$ARGS -b /proc"
39+
ARGS="$ARGS -b $PREFIX"
40+
ARGS="$ARGS -b $PREFIX/local/stat:/proc/stat"
41+
ARGS="$ARGS -b $PREFIX/local/vmstat:/proc/vmstat"
42+
43+
if [ -e "/proc/self/fd" ]; then
44+
ARGS="$ARGS -b /proc/self/fd:/dev/fd"
45+
fi
46+
47+
if [ -e "/proc/self/fd/0" ]; then
48+
ARGS="$ARGS -b /proc/self/fd/0:/dev/stdin"
49+
fi
50+
51+
if [ -e "/proc/self/fd/1" ]; then
52+
ARGS="$ARGS -b /proc/self/fd/1:/dev/stdout"
53+
fi
54+
55+
if [ -e "/proc/self/fd/2" ]; then
56+
ARGS="$ARGS -b /proc/self/fd/2:/dev/stderr"
57+
fi
58+
59+
60+
ARGS="$ARGS -b $PREFIX"
61+
ARGS="$ARGS -b /sys"
62+
63+
if [ ! -d "$PREFIX/local/alpine/tmp" ]; then
64+
mkdir -p "$PREFIX/local/alpine/tmp"
65+
chmod 1777 "$PREFIX/local/alpine/tmp"
66+
fi
67+
ARGS="$ARGS -b $PREFIX/local/alpine/tmp:/dev/shm"
68+
69+
ARGS="$ARGS -r $PREFIX/local/alpine"
70+
ARGS="$ARGS -0"
71+
ARGS="$ARGS --link2symlink"
72+
ARGS="$ARGS --sysvipc"
73+
ARGS="$ARGS -L"
74+
75+
$LINKER $PREFIX/local/bin/proot $ARGS sh $PREFIX/local/bin/init "$@"

core/main/src/main/assets/init.sh

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,36 @@
1-
set -e
1+
set -e # Exit immediately on Failure
22

3-
if [ "$1" = "0" ]; then
4-
result=$(sh "$PREFIX/local/bin/rish" -c "/system/bin/app_process -Djava.class.path=\"$PKG_PATH\" /system/bin com.rk.shell.Installer" "$2")
5-
6-
sh "$PREFIX/local/bin/rish" -c "
7-
mkdir -p /data/local/tmp/ReTerminal/$2
8-
export LD_LIBRARY_PATH=/data/local/tmp/ReTerminal
9-
export PROOT_TMP_DIR=/data/local/tmp/ReTerminal/$2
10-
/data/local/tmp/ReTerminal/proot $result /bin/login -f root
11-
"
12-
13-
elif [ "$1" = "1" ]; then
14-
sh "$PREFIX/local/bin/rish"
15-
elif [ "$1" = "2" ]; then
16-
sh
17-
elif [ "$1" = "3" ]; then
18-
result=$(su -c "/system/bin/app_process -Djava.class.path=\"$PKG_PATH\" /system/bin com.rk.shell.Installer" "$2")
19-
su -c "
20-
mkdir -p /data/local/tmp/ReTerminal/$2
21-
export LD_LIBRARY_PATH=/data/local/tmp/ReTerminal
22-
export PROOT_TMP_DIR=/data/local/tmp/ReTerminal/$2
23-
/data/local/tmp/ReTerminal/proot $result /bin/login -f root
24-
"
25-
else
26-
echo "Unknown working mode $1"
3+
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/share/bin:/usr/share/sbin:/usr/local/bin:/usr/local/sbin:/system/bin:/system/xbin
4+
export HOME=/root
5+
cd "$XPWD"
6+
export PS1="\[\e[38;5;46m\]\u\[\033[39m\]@karbon \[\033[39m\]\w \[\033[0m\]\\$ "
7+
# shellcheck disable=SC2034
8+
export PIP_BREAK_SYSTEM_PACKAGES=1
9+
required_packages="bash gcompat glib git nano sudo file"
10+
missing_packages=""
11+
for pkg in $required_packages; do
12+
if ! apk info -e $pkg >/dev/null 2>&1; then
13+
missing_packages="$missing_packages $pkg"
14+
fi
15+
done
16+
if [ -n "$missing_packages" ]; then
17+
echo -e "\e[34;1m[*] \e[37mInstalling Important packages\e[0m"
18+
apk update && apk upgrade
19+
apk add $missing_packages
20+
if [ $? -eq 0 ]; then
21+
echo -e "\e[32;1m[+] \e[37mSuccessfully Installed\e[0m"
22+
fi
23+
echo -e "\e[34m[*] \e[37mUse \e[32mapk\e[37m to install new packages\e[0m"
2724
fi
2825

26+
#fix linker warning
27+
if [[ ! -f /linkerconfig/ld.config.txt ]];then
28+
mkdir -p /linkerconfig
29+
touch /linkerconfig/ld.config.txt
30+
fi
2931

32+
if [ "$#" -eq 0 ]; then
33+
/bin/login -f root
34+
else
35+
exec "$@"
36+
fi

0 commit comments

Comments
 (0)