• Operand
  • de ploy? ed.

gram:build

> ./config/nushell/machine.nu

Lenses
(coming soon!)


def "machine norm" [ number: int ] { {
  login: root,
  address: $"10.0.0.($number)",
  key: ~/.ssh/id_ed25519.pub,
} }

def "machine cycle" [ machine: record ] { try { shell $machine reboot }; ping $machine.address }

let machines = {
  base: {login: root, address: "172.233.194.84", name: base },
  rebase: {login: root, address: "10.0.0.220", name: rebase },
  beacon: { login: root, address: "172.233.232.194", name: beacon },

# # mobile lab
genkan: { login: admin, address: "10.0.0.1" },
harbor: { login: access, address: "10.0.0.192" },
pier: { login: access, address: "10.0.0.201" },
# 201 share.operand.space
hill: { login: root, address: "10.0.0.210" },
prox: { login: root, channel: 21, address: "10.0.0.2" },
proxy: { login: root, channel: 21, address: "96.66.46.225" },
mesh: { login: calliope, channel: 22, address: "96.66.46.225" },
# share: { login: root, channel: 21, address: "96.66.46.225" },
  share: {login: root, address: "172.233.194.84", name: base },
# 2 assemble.press
press     : (machine norm 2),
# pulse.operand.online
pulse     : (machine norm 121),
# 103 paper.garden
paper     : (machine norm 103),
# 106 session.place
session   : (machine norm 106),
# 202 assembled.app
assembled : (machine norm 202),
# 209 backlog.space
# 105 backlog.space
backlog   : (machine norm 105),
calcom    : (machine norm 204),
# 194 silicon.am
carbon    : (machine norm 194),
# 205 deploy.guide
deploy    : (machine norm 205),
gym       : (machine norm 104),
# 208 labori.us
labori    : (machine norm 208),
# 207 padlock.space
lock      : (machine norm 207),
# 200 picogr.am
pico      : (machine norm 200),
pagemark  : (machine norm 202),
pain      : (machine norm 203),
space     : (machine norm 209),

}; let m = $machines

def announce [ message: any,
    -s: record = { size: 1 }, # shape (displayed message)
] {
  print "\n"
# for x in 1..$s.size { print "\n" }

# if (($message | describe) == 'string' ) {
# for x in 1..$s.size { print --no-newline "  " }; }; # print $message } # | lines | each { .... }

  if (($message | describe) == 'table') {
    print ($message | table --expand | into string) }

  # else { print $message }
  print $message
  print "\n"
}

def "machine address" [mach:record] { $"($mach.login)@($mach.address)" }

# let mach = $machines | transpose | find column0 = $m | get column1

let names = $machines | transpose | get column0

def console --wrapped [mach: record, ...command] {
  let chan = if not ($mach | get -i channel | is-empty) { $mach | get channel } else { 22 }
  ssh -t -p ($chan) (machine address $mach) ($command | str join ' ') }

def prox [mach: record, ...command] {
  let chan = if ($mach | transpose | get column0 | find channel | length) > 0 { $mach | get channel } else { 22 }
  console $m.proxy ssh -t -p $chan (machine address $mach) ($command | str join ' ')
}

def shell --wrapped [mach: record, ...command] {
  let chan = if ($mach | transpose | get column0 | find channel | length) > 0 { $mach | get channel } else { 22 }
  ssh -p ($chan) (machine address $mach) ($command | str join ' ') }

# hacdc
def amnesia-sh [] { ssh hacdcadmin@205.196.222.120; } #amnesia.dreamhost.com; }
def wiki-sh [] { ssh -t root@10.11.3.206; }

# # program local domains
def on [address:int]   { ssh -t $"root@10.0.0.($address)"; }

def proxy-cycle []  {
  console $m.proxy ./cycle.sh
  shell $m.proxy systemctl status caddy
  shell $m.proxy journalctl -fu caddy }

def proxy --wrapped [machine: record, ...call] {
  console $m.proxy $"ssh (machine address $machine) ($call | str join ' ')"
}

def assembled-c []     { ssh -t root@10.0.0.202 'dokku run assembled rails c'; }
def assembled-cycle [] { ssh -t root@10.0.0.202 'dokku ps:restart assembled'; }
def assembled-log []   { ssh -t root@10.0.0.202 'dokku logs -t assembled'; }

def pico-cycle [] { cd; bind backup backup;
  let node = $"backup/log/(clock | str trim).picogram.log"
  ssh root@10.0.0.200 'cd /pico && docker compose logs' | save $node;
  ssh root@10.0.0.200 bash /root/cycle.sh }

def lock-cycle [] { cd; bind backup backup;
  let node = $"backup/log/(clock | str trim).padlock.log"
  ssh root@10.0.0.207 'cd /root/passbolt && docker compose logs' | save $node;
  ssh root@10.0.0.207 bash /root/cycle.sh;
}

def "mach kernel" [] { ((uname).kernel-version | split column -r '[ \-]').column2.0 }