8 lines
2.5 KiB
PHP
8 lines
2.5 KiB
PHP
<?php
|
|
function run($a){$p=proc_open($a,[1=>['pipe','w'],2=>['pipe','w']],$ps);$o=stream_get_contents($ps[1]);$e=stream_get_contents($ps[2]);foreach($ps as$s)fclose($s);$c=proc_close($p);if($c)throw new Exception('Command failed exit '.$c);return $o;}
|
|
$root='/mnt/nvme-storage/appdata/librechat';$xp='/boot/config/plugins/dockerMan/templates-user/my-LibreChat.xml';$x=simplexml_load_file($xp);$back=$root.'/install-backups/mcp-'.gmdate('Ymd-His');mkdir($back,0700,true);copy($xp,$back.'/my-LibreChat.xml');chmod($back.'/my-LibreChat.xml',0600);copy($root.'/librechat.yaml',$back.'/librechat.yaml');
|
|
run(['docker','cp','/tmp/librechat-mcp-servers.json','LibreChat:/tmp/librechat-mcp-servers.json']);run(['docker','cp','/tmp/librechat-mcp-configure.js','LibreChat:/tmp/librechat-mcp-configure.js']);echo run(['docker','exec','LibreChat','node','-e','eval(require("fs").readFileSync("/tmp/librechat-mcp-configure.js","utf8"))']);run(['docker','cp','LibreChat:/tmp/librechat-mcp.yaml',$root.'/librechat.yaml']);
|
|
$rows=json_decode(file_get_contents('/tmp/librechat-mcp-servers.json'),true);foreach($rows as$s){if($s['auth']!=='bearer')continue;$key='MCP_KEY_'.strtoupper(preg_replace('/[^a-zA-Z0-9]/','_',$s['id']));$found=false;foreach($x->Config as$c)if((string)$c['Target']===$key)$found=true;if(!$found){$c=$x->addChild('Config','FAKE_KEY_REPLACE_ME_'.$s['id']);foreach(['Name'=>'MCP API-Key: '.$s['name'],'Target'=>$key,'Type'=>'Variable','Mode'=>'','Display'=>'always','Required'=>'false','Mask'=>'true','Description'=>'Platzhalter durch echten MCP-Bearer-Key ersetzen.']as$a=>$z)$c->addAttribute($a,$z);}}$x->asXML($xp);chmod($xp,0600);
|
|
$a=['docker','create','--name','LibreChat','--network','bridge','--restart','unless-stopped','--pids-limit','2048','-l','net.unraid.docker.managed=dockerman'];foreach(['WebUI'=>'net.unraid.docker.webui','Icon'=>'net.unraid.docker.icon']as$k=>$v)if((string)$x->$k!='')array_push($a,'-l',$v.'='.(string)$x->$k);foreach($x->Config as$c){$v=(string)$c;$target=(string)$c['Target'];$type=(string)$c['Type'];if($type==='Variable')array_push($a,'-e',$target.'='.$v);elseif($type==='Port')array_push($a,'-p',$v.':'.$target.'/'.(string)$c['Mode']);elseif($type==='Path')array_push($a,'-v',$v.':'.$target.':'.(string)$c['Mode']);else throw new Exception('Unknown template config');}$a[]=(string)$x->Repository;
|
|
run(['docker','stop','--time','30','LibreChat']);run(['docker','rm','LibreChat']);run($a);run(['docker','start','LibreChat']);echo json_encode(['installed'=>true,'backup'=>$back])."\n";
|