Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion hooks/post-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,27 @@ enableStaticContext();
patchTargetSdkVersion();


function getTmpDir() {
const tmpdirEnv = process.env.TMPDIR;

if (tmpdirEnv) {
try {
fs.accessSync(tmpdirEnv, fs.constants.R_OK | fs.constants.W_OK);
return tmpdirEnv;
} catch {
// TMPDIR exists but not accessible
}
}

try {
fs.accessSync("/tmp", fs.constants.R_OK | fs.constants.W_OK);
return "/tmp";
} catch {
console.error("Error: No usable temporary directory found (TMPDIR or /tmp not accessible).");
process.exit(1);
}
}

function patchTargetSdkVersion() {
const prefix = execSync('npm prefix').toString().trim();
const gradleFile = path.join(prefix, 'platforms/android/app/build.gradle');
Expand All @@ -49,13 +70,16 @@ function patchTargetSdkVersion() {

if (sdkRegex.test(content)) {
let api = "35";
const froidFlag = path.join(prefix, 'fdroid.bool');
const froidFlag = path.join(getTmpDir(), 'fdroid.bool');

if (fs.existsSync(froidFlag)) {
const fdroid = fs.readFileSync(froidFlag, 'utf-8').trim();
if (fdroid == "true") {
api = "28";
}
} else {
console.error(`${getTmpDir()}/fdroid.bool not found`);
process.exit(1);
}

content = content.replace(sdkRegex, 'targetSdkVersion ' + api);
Expand Down
7 changes: 1 addition & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"cordova-plugin-websocket": {},
"cordova-plugin-buildinfo": {},
"com.foxdebug.acode.rk.exec.terminal": {},
"com.foxdebug.acode.rk.exec.proot": {},
"cordova-plugin-browser": {},
"cordova-plugin-system": {}
},
Expand All @@ -63,7 +62,6 @@
"@types/url-parse": "^1.4.11",
"autoprefixer": "^10.4.21",
"babel-loader": "^10.0.0",
"com.foxdebug.acode.rk.exec.proot": "file:src/plugins/proot",
"com.foxdebug.acode.rk.exec.terminal": "file:src/plugins/terminal",
"cordova-android": "^14.0.1",
"cordova-clipboard": "^1.3.0",
Expand Down
53 changes: 35 additions & 18 deletions utils/scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,50 @@
#! /bin/bash
#!/bin/bash

app="$1"
mode="$2"
fdroidFlag="$3"
# Default values
app="paid"
mode="d"
fdroidFlag=""
webpackmode="development"
cordovamode=""

# Check all arguments for specific values
for arg in "$@"; do
case "$arg" in
"free"|"paid")
app="$arg"
;;
"p"|"prod"|"d"|"dev")
mode="$arg"
;;
"fdroid")
fdroidFlag="fdroid"
;;
*)
echo "Warning: Unknown argument '$arg' ignored"
;;
esac
done

root=$(npm prefix)

if [ -n "$TMPDIR" ] && [ -r "$TMPDIR" ] && [ -w "$TMPDIR" ]; then
tmpdir="$TMPDIR"
elif [ -r "/tmp" ] && [ -w "/tmp" ]; then
tmpdir="/tmp"
else
echo "Error: No usable temporary directory found (TMPDIR or /tmp not accessible)." >&2
exit 1
fi

if [[ "$fdroidFlag" == "fdroid" ]]; then
echo "true" > "$root/fdroid.bool"
echo "true" > "$tmpdir/fdroid.bool"
cordova plugin remove com.foxdebug.acode.rk.exec.proot

else
echo "false" > "$root/fdroid.bool"
echo "false" > "$tmpdir/fdroid.bool"
cordova plugin add src/plugins/proot/
fi

if [ -z "$mode" ]
then
mode="d"
fi

if [ -z "$app" ]
then
app="paid"
fi

# Normalize mode values
if [ "$mode" = "p" ] || [ "$mode" = "prod" ]
then
mode="p"
Expand All @@ -50,4 +67,4 @@ $script2&&
# $script3;
echo \"${RED}$script4${NC}\";
$script4;
"
"