Skip to content

Commit

Permalink
orbit command
Browse files Browse the repository at this point in the history
  • Loading branch information
sinamics committed Aug 20, 2024
1 parent 0714195 commit 88aeeab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/components/adminPage/controller/privateRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ const PrivateRoot = () => {
toast.error(error.message);
});
};

// generate the moon id from the first node that has ismoon set to true
const isMoonIdentity = getPlanet?.rootNodes?.filter((node) => node.isMoon);
const moonId = isMoonIdentity?.[0]?.identity.trim().split(":")[0];

return (
<div className="space-y-4">
<div>
Expand Down Expand Up @@ -165,7 +170,9 @@ const PrivateRoot = () => {
<p className="tracking-wide font-medium">Root #{i + 1}</p>
{node.isMoon ? (
<kbd className="kbd px-2 py-1 rounded text-sm font-mono">
{`zerotier-cli orbit ztnet ${node.identity.split(":")[0]}`}
{`zerotier-cli orbit ${moonId} ${
node.identity.split(":")[0]
}`}
</kbd>
) : null}
</div>
Expand Down
7 changes: 4 additions & 3 deletions src/server/api/services/adminService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ export async function createMoon(nodes: RootNode[], moonPath: string) {
.readFileSync(publicIdentityPath, "utf-8")
.trim()
.split(":")[0];

// Filter nodes that are marked as moons
const moonNodes = nodes.filter((node) => node.isMoon);
const moonId = moonNodes[0].identity.trim().split(":")[0];

const moonConfig = {
id: currentControllerId,
id: moonId,
roots: moonNodes.map((node) => ({
identity: node.identity,
endpoints: node.endpoints,
})),
};

// Generate the initial moon file
const initMoonFilePath = `${moonPath}/initmoon_${currentControllerId}.json`;
const initMoonFilePath = `${moonPath}/initmoon_${moonId}.json`;
execSync(`${ZT_IDTOOL} initmoon ${identityPath} > ${initMoonFilePath}`);

// Read the initmoon.json file
Expand All @@ -61,6 +61,7 @@ export async function createMoon(nodes: RootNode[], moonPath: string) {
const isCurrentControllerMoon = moonNodes.some((node) =>
node.identity.includes(currentControllerId),
);

if (isCurrentControllerMoon) {
// Find the generated moon file
const moonFiles = fs.readdirSync(moonPath);
Expand Down

0 comments on commit 88aeeab

Please sign in to comment.