--- /dev/null
+def main [host: string, destination: string, ssh_key: path] {
+ let ssh_args = [-i $ssh_key $host]
+ let scp_args = [-r -i $ssh_key]
+ let target = "aarch64-unknown-linux-gnu" # For raspberry pi zero 1: "arm-unknown-linux-gnueabihf"
+
+ def invoke_ssh [command: list] {
+ let args = $ssh_args ++ $command
+ print $"Executing: ssh ($args)"
+ ssh $args
+ }
+
+ def copy_ssh [source: string, destination: string] {
+ let args = $scp_args ++ [$source $"($host):($destination)"]
+ print $"Executing: scp ($args)"
+ scp $args
+ }
+
+ cargo build --target $target --release
+ invoke_ssh [sudo systemctl stop recipes]
+ copy_ssh ./target/($target)/release/recipes $destination
+ invoke_ssh [rm -rf recipes/static]
+ copy_ssh ./backend/static/ $destination
+ copy_ssh ./backend/sql/ $destination
+ invoke_ssh [chmod u+x recipes/recipes]
+ invoke_ssh [sudo systemctl start recipes]
+ print "Deployment finished"
+}
+
+++ /dev/null
-# TODO:
-# * copy the conf if it doesn't exist
-# * create the destination directory if doesn't exist
-
-if ($args.Count -lt 3) {
- $scriptName = [Environment]::GetCommandLineArgs()[1]
- Write-Output "Usage: $scriptName <address: string> <remote director: string> <key file: openssh format>"
- exit 1
-}
-
-$address=$args[0]
-$destination=$args[1]
-$ssh_key=$args[2]
-
-$ssh_command = "ssh -i $ssh_key $address"
-$scp_command = "scp -r -i $ssh_key"
-
-function Invoke-SSH([string]$command)
-{
- $expression = "$ssh_command $command"
- Write-Output "Executing: $expression"
- Invoke-Expression $expression | Write-Output
-}
-
-function Copy-SSH([string]$source, [string]$destination)
-{
- $expression = "$scp_command $source ${address}:$destination"
- Write-Output "Executing: $expression"
- Invoke-Expression $expression
-}
-
-cargo build --target arm-unknown-linux-gnueabihf --release
-
-Invoke-SSH "sudo systemctl stop recipes"
-
-Copy-SSH -source "./target/arm-unknown-linux-gnueabihf/release/recipes" -destination "~/recipes/"
-
-Invoke-SSH "rm -rf recipes/static"
-Copy-SSH -source "./backend/static/" -destination "~/recipes/"
-
-Copy-SSH -source "./backend/sql/" -destination "~/recipes/"
-
-Invoke-SSH "chmod u+x recipes/recipes"
-Invoke-SSH "sudo systemctl start recipes"
-
-Write-Output "Deployment finished"