Skip to content

Commit 0339e16

Browse files
fix: fdroid builds (#1565)
* feat: use non-postional build arguments * fix: cancel build if fdroid.bool file not found
1 parent 32a1c68 commit 0339e16

File tree

4 files changed

+61
-27
lines changed

4 files changed

+61
-27
lines changed

hooks/post-process.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,27 @@ enableStaticContext();
3434
patchTargetSdkVersion();
3535

3636

37+
function getTmpDir() {
38+
const tmpdirEnv = process.env.TMPDIR;
39+
40+
if (tmpdirEnv) {
41+
try {
42+
fs.accessSync(tmpdirEnv, fs.constants.R_OK | fs.constants.W_OK);
43+
return tmpdirEnv;
44+
} catch {
45+
// TMPDIR exists but not accessible
46+
}
47+
}
48+
49+
try {
50+
fs.accessSync("/tmp", fs.constants.R_OK | fs.constants.W_OK);
51+
return "/tmp";
52+
} catch {
53+
console.error("Error: No usable temporary directory found (TMPDIR or /tmp not accessible).");
54+
process.exit(1);
55+
}
56+
}
57+
3758
function patchTargetSdkVersion() {
3859
const prefix = execSync('npm prefix').toString().trim();
3960
const gradleFile = path.join(prefix, 'platforms/android/app/build.gradle');
@@ -49,13 +70,16 @@ function patchTargetSdkVersion() {
4970

5071
if (sdkRegex.test(content)) {
5172
let api = "35";
52-
const froidFlag = path.join(prefix, 'fdroid.bool');
73+
const froidFlag = path.join(getTmpDir(), 'fdroid.bool');
5374

5475
if (fs.existsSync(froidFlag)) {
5576
const fdroid = fs.readFileSync(froidFlag, 'utf-8').trim();
5677
if (fdroid == "true") {
5778
api = "28";
5879
}
80+
} else {
81+
console.error(`${getTmpDir()}/fdroid.bool not found`);
82+
process.exit(1);
5983
}
6084

6185
content = content.replace(sdkRegex, 'targetSdkVersion ' + api);

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
"cordova-plugin-websocket": {},
3737
"cordova-plugin-buildinfo": {},
3838
"com.foxdebug.acode.rk.exec.terminal": {},
39-
"com.foxdebug.acode.rk.exec.proot": {},
4039
"cordova-plugin-browser": {},
4140
"cordova-plugin-system": {}
4241
},
@@ -63,7 +62,6 @@
6362
"@types/url-parse": "^1.4.11",
6463
"autoprefixer": "^10.4.21",
6564
"babel-loader": "^10.0.0",
66-
"com.foxdebug.acode.rk.exec.proot": "file:src/plugins/proot",
6765
"com.foxdebug.acode.rk.exec.terminal": "file:src/plugins/terminal",
6866
"cordova-android": "^14.0.1",
6967
"cordova-clipboard": "^1.3.0",

utils/scripts/build.sh

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,50 @@
1-
#! /bin/bash
1+
#!/bin/bash
22

3-
app="$1"
4-
mode="$2"
5-
fdroidFlag="$3"
3+
# Default values
4+
app="paid"
5+
mode="d"
6+
fdroidFlag=""
67
webpackmode="development"
78
cordovamode=""
89

10+
# Check all arguments for specific values
11+
for arg in "$@"; do
12+
case "$arg" in
13+
"free"|"paid")
14+
app="$arg"
15+
;;
16+
"p"|"prod"|"d"|"dev")
17+
mode="$arg"
18+
;;
19+
"fdroid")
20+
fdroidFlag="fdroid"
21+
;;
22+
*)
23+
echo "Warning: Unknown argument '$arg' ignored"
24+
;;
25+
esac
26+
done
27+
928
root=$(npm prefix)
1029

30+
if [ -n "$TMPDIR" ] && [ -r "$TMPDIR" ] && [ -w "$TMPDIR" ]; then
31+
tmpdir="$TMPDIR"
32+
elif [ -r "/tmp" ] && [ -w "/tmp" ]; then
33+
tmpdir="/tmp"
34+
else
35+
echo "Error: No usable temporary directory found (TMPDIR or /tmp not accessible)." >&2
36+
exit 1
37+
fi
1138

1239
if [[ "$fdroidFlag" == "fdroid" ]]; then
13-
echo "true" > "$root/fdroid.bool"
40+
echo "true" > "$tmpdir/fdroid.bool"
1441
cordova plugin remove com.foxdebug.acode.rk.exec.proot
15-
1642
else
17-
echo "false" > "$root/fdroid.bool"
43+
echo "false" > "$tmpdir/fdroid.bool"
1844
cordova plugin add src/plugins/proot/
1945
fi
2046

21-
if [ -z "$mode" ]
22-
then
23-
mode="d"
24-
fi
25-
26-
if [ -z "$app" ]
27-
then
28-
app="paid"
29-
fi
30-
47+
# Normalize mode values
3148
if [ "$mode" = "p" ] || [ "$mode" = "prod" ]
3249
then
3350
mode="p"
@@ -50,4 +67,4 @@ $script2&&
5067
# $script3;
5168
echo \"${RED}$script4${NC}\";
5269
$script4;
53-
"
70+
"

0 commit comments

Comments
 (0)