From: Greg Burri Date: Thu, 24 Nov 2022 23:50:01 +0000 (+0100) Subject: Replace powershell script by nushell script X-Git-Url: http://git.euphorik.ch/?a=commitdiff_plain;ds=sidebyside;h=b3751b28bfc8bf5fd0d5406acc1d3543e6481ed1;p=recipes.git Replace powershell script by nushell script --- diff --git a/.gitignore b/.gitignore index 16dd006..da828e4 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ target **/*.rs.bk backend/data/recipes.sqlite backend/data/recipes.sqlite-journal -/deploy-to-pi.ps1 +/deploy-to-pi.nu style.css.map backend/static/style.css backend/file.db diff --git a/deploy.nu b/deploy.nu new file mode 100644 index 0000000..2e46351 --- /dev/null +++ b/deploy.nu @@ -0,0 +1,28 @@ +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" +} + diff --git a/deploy.ps1 b/deploy.ps1 deleted file mode 100644 index 9a47e6b..0000000 --- a/deploy.ps1 +++ /dev/null @@ -1,46 +0,0 @@ -# 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 " - 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"