<?php
header('Content-Type: application/json; charset=utf-8');
$Id = $Lin->PN("id", "3", "1", "Id");
$OS = $Lin->PN("os", "1", "0", "系统");
$LinDB->OpenConn();
$Bash = $LinDB->Sel("SELECT Bash_Content, Bash_Name, Bash_OS FROM tvbox_bash WHERE Id = ? AND Bash_State = '1' AND Bash_Types = '1' AND Bash_OS LIKE '%$OS%' LIMIT 1", [$Id]);
if ($Bash && !empty($Bash["Bash_Content"])) {
    $content = $Bash["Bash_Content"];
    // 仅获取第一行来检查解释器声明
    $firstLine = strtok($content, "\n");
    // 精确检查第一行是否以#!/开头
    if (strpos($firstLine, "#!/") !== 0) {
        if ($OS == 'android') {
            $content = "#!/system/bin/sh\n" . $content;
        } else {
            $content = "#!/bin/sh\n" . $content;
        }
    }
    // 标准化换行符
    $content = str_replace("\r\n", "\n", $content);
    $content = $LinKey->Encode($content);
    die($LinJson->ok("脚本获取成功", $content));
} else {
    die($LinJson->err("未找到脚本或脚本内容为空或不支持的系统"));
}
$LinDB->CloseConn();
?>