Skip to content

Commit 1791ff3

Browse files
fix: Terminal in F-Droid flavour (#1478)
* fix. terminal in fdroid flavour * feat. cleanup before installing
1 parent da47d95 commit 1791ff3

File tree

5 files changed

+77
-33
lines changed

5 files changed

+77
-33
lines changed

package-lock.json

Lines changed: 1 addition & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
},
3737
"cordova-plugin-websocket": {},
3838
"cordova-plugin-buildinfo": {},
39-
"com.foxdebug.acode.rk.exec.proot": {},
4039
"cordova-plugin-system": {},
4140
"com.foxdebug.acode.rk.exec.terminal": {}
4241
},
@@ -64,7 +63,6 @@
6463
"@types/url-parse": "^1.4.11",
6564
"autoprefixer": "^10.4.19",
6665
"babel-loader": "^9.1.3",
67-
"com.foxdebug.acode.rk.exec.proot": "file:src/plugins/proot",
6866
"com.foxdebug.acode.rk.exec.terminal": "file:src/plugins/terminal",
6967
"cordova-android": "^13.0.0",
7068
"cordova-clipboard": "^1.3.0",

src/plugins/terminal/scripts/init-alpine.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ fi
3333
ln -sf /bin/bash /bin/login
3434

3535
if [ "$1" = "--installing" ]; then
36+
mkdir -p $PREFIX/.configured
3637
echo "Installation completed."
3738
exit 0
3839
fi

src/plugins/terminal/scripts/init-sandbox.sh

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,35 @@
11
export LD_LIBRARY_PATH=$PREFIX
22
export PROOT_TMP_DIR=$PREFIX/tmp
33

4+
mkdir -p "$PREFIX/tmp"
45

5-
if [ -f "$NATIVE_DIR/libproot.so" ]; then
6-
export PROOT_LOADER="$NATIVE_DIR/libproot.so"
7-
fi
6+
if [ "$FDROID" = "true" ]; then
87

9-
if [ -f "$NATIVE_DIR/libproot32.so" ]; then
10-
export PROOT_LOADER32="$NATIVE_DIR/libproot32.so"
11-
fi
8+
if [ -f "$PREFIX/libproot.so" ]; then
9+
export PROOT_LOADER="$PREFIX/libproot.so"
10+
fi
11+
12+
if [ -f "$PREFIX/libproot32.so" ]; then
13+
export PROOT_LOADER32="$PREFIX/libproot32.so"
14+
fi
1215

13-
mkdir -p "$PREFIX/tmp"
1416

15-
if [ "$FDROID" = "true" ]; then
1617
export PROOT="$PREFIX/libproot-xed.so"
17-
chmod +x $PROOT
18-
chmod +x $PREFIX/libtalloc.so.2
18+
chmod +x $PREFIX/*
1919
else
20+
if [ -f "$NATIVE_DIR/libproot.so" ]; then
21+
export PROOT_LOADER="$NATIVE_DIR/libproot.so"
22+
fi
23+
24+
if [ -f "$NATIVE_DIR/libproot32.so" ]; then
25+
export PROOT_LOADER32="$NATIVE_DIR/libproot32.so"
26+
fi
27+
28+
2029
if [ -e "$PREFIX/libtalloc.so.2" ] || [ -L "$PREFIX/libtalloc.so.2" ]; then
2130
rm "$PREFIX/libtalloc.so.2"
2231
fi
32+
2333
ln -s "$NATIVE_DIR/libtalloc.so" "$PREFIX/libtalloc.so.2"
2434
export PROOT="$NATIVE_DIR/libproot-xed.so"
2535
fi

src/plugins/terminal/www/Terminal.js

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,15 @@ const Terminal = {
9191
* @returns {Promise<boolean>} - Returns true if installation completes with exit code 0
9292
*/
9393
async install(logger = console.log, err_logger = console.error) {
94-
if (await this.isInstalled()) return true;
9594
if (!(await this.isSupported())) return false;
9695

96+
try {
97+
//cleanup before insatll
98+
await this.uninstall();
99+
} catch (e) {
100+
//supress error
101+
}
102+
97103
const filesDir = await new Promise((resolve, reject) => {
98104
system.getFilesDir(resolve, reject);
99105
});
@@ -107,18 +113,25 @@ const Terminal = {
107113
let axsUrl;
108114
let prootUrl;
109115
let libTalloc;
116+
let libproot = null;
117+
let libproot32 = null;
110118

111119
if (arch === "arm64-v8a") {
120+
libproot = "https://raw.githubusercontent.com/Acode-Foundation/Acode/main/src/plugins/proot/libs/arm64/libproot.so";
121+
libproot32 = "https://raw.githubusercontent.com/Acode-Foundation/Acode/main/src/plugins/proot/libs/arm64/libproot32.so";
112122
libTalloc = "https://raw.githubusercontent.com/Acode-Foundation/Acode/main/src/plugins/proot/libs/arm64/libtalloc.so";
113123
prootUrl = "https://raw.githubusercontent.com/Acode-Foundation/Acode/main/src/plugins/proot/libs/arm64/libproot-xed.so";
114124
axsUrl = `https://github.com/bajrangCoder/acodex_server/releases/latest/download/axs-musl-android-arm64`;
115125
alpineUrl = "https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/aarch64/alpine-minirootfs-3.21.0-aarch64.tar.gz";
116126
} else if (arch === "armeabi-v7a") {
127+
libproot = "https://raw.githubusercontent.com/Acode-Foundation/Acode/main/src/plugins/proot/libs/arm32/libproot.so";
117128
libTalloc = "https://raw.githubusercontent.com/Acode-Foundation/Acode/main/src/plugins/proot/libs/arm32/libtalloc.so";
118129
prootUrl = "https://raw.githubusercontent.com/Acode-Foundation/Acode/main/src/plugins/proot/libs/arm32/libproot-xed.so";
119130
axsUrl = `https://github.com/bajrangCoder/acodex_server/releases/latest/download/axs-musl-android-armv7`;
120131
alpineUrl = "https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/armhf/alpine-minirootfs-3.21.0-armhf.tar.gz";
121132
} else if (arch === "x86_64") {
133+
libproot = "https://raw.githubusercontent.com/Acode-Foundation/Acode/main/src/plugins/proot/libs/x64/libproot.so";
134+
libproot32 = "https://raw.githubusercontent.com/Acode-Foundation/Acode/main/src/plugins/proot/libs/x64/libproot32.so";
122135
libTalloc = "https://raw.githubusercontent.com/Acode-Foundation/Acode/main/src/plugins/proot/libs/x64/libtalloc.so";
123136
prootUrl = "https://raw.githubusercontent.com/Acode-Foundation/Acode/main/src/plugins/proot/libs/x64/libproot-xed.so";
124137
axsUrl = `https://github.com/bajrangCoder/acodex_server/releases/latest/download/axs-musl-android-x86_64`;
@@ -166,6 +179,27 @@ const Terminal = {
166179
resolve, reject
167180
);
168181
});
182+
183+
if (libproot != null) {
184+
await new Promise((resolve, reject) => {
185+
cordova.plugin.http.downloadFile(
186+
libproot, {}, {},
187+
cordova.file.dataDirectory + "libproot.so",
188+
resolve, reject
189+
);
190+
});
191+
}
192+
193+
if (libproot32 != null) {
194+
await new Promise((resolve, reject) => {
195+
cordova.plugin.http.downloadFile(
196+
libproot32, {}, {},
197+
cordova.file.dataDirectory + "libproot32.so",
198+
resolve, reject
199+
);
200+
});
201+
}
202+
169203
}
170204

171205
logger("✅ All downloads completed");
@@ -198,9 +232,9 @@ const Terminal = {
198232
return installResult;
199233

200234
} catch (e) {
201-
err_logger("Installation failed:", e);
202-
console.error("Installation failed:", e);
203-
return false;
235+
err_logger("Installation failed:", e);
236+
console.error("Installation failed:", e);
237+
return false;
204238
}
205239
},
206240

@@ -232,7 +266,13 @@ const Terminal = {
232266
}, reject);
233267
});
234268

235-
resolve(alpineExists && downloaded && extracted);
269+
const configured = alpineExists && await new Promise((resolve, reject) => {
270+
system.fileExists(`${filesDir}/.configured`, false, (result) => {
271+
resolve(result == 1);
272+
}, reject);
273+
});
274+
275+
resolve(alpineExists && downloaded && extracted && configured);
236276
});
237277
},
238278

@@ -358,10 +398,10 @@ const Terminal = {
358398
* console.error(`Uninstall failed: ${error}`);
359399
* }
360400
*/
361-
uninstall(){
401+
uninstall() {
362402
return new Promise(async (resolve, reject) => {
363-
if(await this.isAxsRunning()){
364-
await this.stopAxs()
403+
if (await this.isAxsRunning()) {
404+
await this.stopAxs();
365405
}
366406

367407
const cmd = `
@@ -378,13 +418,13 @@ const Terminal = {
378418
done
379419
380420
echo "ok"
381-
`
382-
const result = await Executor.execute(cmd)
383-
if(result === "ok"){
384-
resolve(result)
385-
}else{
386-
reject(result)
387-
}
421+
`;
422+
const result = await Executor.execute(cmd);
423+
if (result === "ok") {
424+
resolve(result);
425+
} else {
426+
reject(result);
427+
}
388428
});
389429
}
390430
};

0 commit comments

Comments
 (0)