feat: add Apatch support
This commit is contained in:
parent
1c3dbd565d
commit
8734722cc3
3 changed files with 88 additions and 19 deletions
|
|
@ -158,6 +158,18 @@ for d in ${module_dirs}; do
|
|||
ui_print " ✓ Installed: $d/"
|
||||
done
|
||||
|
||||
if [ "x$KSU" = "xtrue" ] && [ "x$APATCH" = "xtrue" ]; then
|
||||
abort "err"
|
||||
elif [ "x$KSU" = "xtrue" ]; then
|
||||
AOK="KSU"
|
||||
echo "AOK=KSU" > "$MODPATH/aok"
|
||||
elif [ "x$APATCH" = "xtrue" ]; then
|
||||
AOK="APATCH"
|
||||
ui_print "AOK=APATCH" > "$MODPATH/aok"
|
||||
else
|
||||
abort "err"
|
||||
fi
|
||||
|
||||
ui_print "- Initializing configuration"
|
||||
|
||||
# Create data directory
|
||||
|
|
@ -179,6 +191,9 @@ if [ ! -f "$module_data_dir/mm.conf" ]; then
|
|||
else
|
||||
ui_print " ℹ Existing configuration preserved"
|
||||
fi
|
||||
if [ "$AOK" = "APATCH" ]; then
|
||||
sed -i '/^[[:space:]]*umount=true[[:space:]]*$/d' "$module_data_dir/mm.conf"
|
||||
fi
|
||||
|
||||
ui_print "- Managing metamodule status"
|
||||
|
||||
|
|
|
|||
|
|
@ -10,12 +10,17 @@
|
|||
let message = null;
|
||||
let partitionsInput = "";
|
||||
|
||||
let hideUmount = false;
|
||||
|
||||
const CONFIG_FILE_PATH = "/data/adb/magic_mount/mm.conf";
|
||||
|
||||
async function load() {
|
||||
loading = true;
|
||||
message = null;
|
||||
try {
|
||||
const aok = await utils.loadAOK();
|
||||
hideUmount = aok === "APATCH";
|
||||
|
||||
config = await utils.loadConfig();
|
||||
partitionsInput = config.partitions.join(", ");
|
||||
message = $L.config.loadSuccess;
|
||||
|
|
@ -35,7 +40,8 @@
|
|||
.split(",")
|
||||
.map((s) => s.trim())
|
||||
.filter(Boolean);
|
||||
await utils.saveConfig(config);
|
||||
|
||||
await utils.saveConfig(config, { omitUmount: hideUmount });
|
||||
message = $L.config.saveSuccess;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
|
|
@ -70,6 +76,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
{#if !hideUmount}
|
||||
<div class="field">
|
||||
<span class="field-label">{$L.config.umountLabel}</span>
|
||||
<div class="loglevel-switch">
|
||||
|
|
@ -85,6 +92,7 @@
|
|||
>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="field">
|
||||
<label class="field-label" for="inp-moduledir">{$L.config.moduleDir}</label>
|
||||
|
|
|
|||
|
|
@ -12,6 +12,18 @@ export const DEFAULT_CONFIG = {
|
|||
};
|
||||
|
||||
const CONFIG_PATH = "/data/adb/magic_mount/mm.conf";
|
||||
const AOK_PATH = "/data/adb/metamodule/aok";
|
||||
|
||||
function stripQuotes(s) {
|
||||
const t = String(s).trim();
|
||||
if (
|
||||
(t.startsWith('"') && t.endsWith('"')) ||
|
||||
(t.startsWith("'") && t.endsWith("'"))
|
||||
) {
|
||||
return t.slice(1, -1);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
function isTrueValue(v) {
|
||||
const s = String(v).trim().toLowerCase();
|
||||
|
|
@ -69,24 +81,31 @@ export async function loadConfig() {
|
|||
return result;
|
||||
}
|
||||
|
||||
export async function saveConfig(cfg) {
|
||||
export async function saveConfig(cfg, opts = {}) {
|
||||
if (import.meta.env.DEV) {
|
||||
return MockAPI.saveConfig(cfg);
|
||||
}
|
||||
|
||||
const omitUmount = !!opts.omitUmount;
|
||||
|
||||
const lines = [
|
||||
"# Magic Mount Configuration File",
|
||||
"# Generated by Web UI",
|
||||
"",
|
||||
];
|
||||
|
||||
lines.push(`module_dir=${cfg.moduledir || DEFAULT_CONFIG.moduledir}`);
|
||||
if (cfg.tempdir) lines.push(`temp_dir=${cfg.tempdir}`);
|
||||
lines.push(`mount_source=${cfg.mountsource || DEFAULT_CONFIG.mountsource}`);
|
||||
if (cfg.logfile) lines.push(`log_file=${cfg.logfile}`);
|
||||
lines.push(`debug=${cfg.verbose ? "true" : "false"}`);
|
||||
|
||||
if (!omitUmount) {
|
||||
lines.push(`umount=${cfg.umount ? "true" : "false"}`);
|
||||
if (cfg.partitions.length > 0)
|
||||
lines.push(`partitions=${cfg.partitions.join(",")}`);
|
||||
}
|
||||
|
||||
const parts = Array.isArray(cfg.partitions) ? cfg.partitions : [];
|
||||
if (parts.length > 0) lines.push(`partitions=${parts.join(",")}`);
|
||||
|
||||
const content = lines.join("\n").replace(/'/g, "'\\''");
|
||||
const shell = `mkdir -p "$(dirname "${CONFIG_PATH}")" && printf '%s\n' '${content}' > "${CONFIG_PATH}"`;
|
||||
|
|
@ -157,3 +176,30 @@ export async function toggleModuleSkip(moduleDir, modName, shouldSkip) {
|
|||
const { errno, stderr } = await exec(cmd);
|
||||
if (errno !== 0) throw new Error(stderr);
|
||||
}
|
||||
|
||||
export async function loadAOK() {
|
||||
if (import.meta.env.DEV) {
|
||||
return "KSU";
|
||||
}
|
||||
|
||||
const { errno, stdout } = await exec(
|
||||
`[ -f "${AOK_PATH}" ] && cat "${AOK_PATH}" || echo ""`,
|
||||
);
|
||||
if (errno !== 0) throw new Error("Read AOK failed");
|
||||
|
||||
const lines = (stdout || "").split("\n");
|
||||
for (let line of lines) {
|
||||
line = line.trim();
|
||||
if (!line || line.startsWith("#")) continue;
|
||||
|
||||
const [key, ...vals] = line.split("=");
|
||||
if (!key || !vals.length) continue;
|
||||
|
||||
if (key.trim() === "AOK") {
|
||||
const value = stripQuotes(vals.join("=").trim());
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue