Remove the logger (for the moment) and update the deployment script.
[recipes.git] / deploy.ps1
index 6f0b534..da77557 100644 (file)
@@ -1,28 +1,43 @@
-if ($args.Count -lt 1) {
+# 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]
-   echo "Usage: $scriptName <destination>"
+   Write-Output "Usage: $scriptName <address: string> <remote director: string> <key file: openssh format>"
    exit 1
 }
 
-cargo build --release
+$address=$args[0]
+$destination=$args[1]
+$ssh_key=$args[2]
 
-systemctl --user stop www-recipes.service
+$ssh_command = "ssh -i $ssh_key $address"
+$scp_command = "scp -r -i $ssh_key"
 
-$destination=$args[0]
+function Invoke-SSH([string]$command)
+{
+   $expression = "$ssh_command $command"
+   Write-Output "Executing: $expression"
+   Invoke-Expression $expression | Write-Output
+}
 
-if (!(Test-Path -Path $destination)) {
-   New-Item -ItemType directory -Path $destination
+function Copy-SSH([string]$source, [string]$destination)
+{
+   $expression = "$scp_command $source ${address}:$destination"
+   Write-Output "Executing: $expression"
+   Invoke-Expression $expression
 }
 
-strip target/release/recipes
-Copy-Item target/release/recipes -Destination $destination
+cargo build --target arm-unknown-linux-gnueabihf --release
 
-Copy-Item backend/static -Destination $destination -Recurse -Force
+# $a = Invoke-Expression ($ssh_command + "ls")
+Invoke-SSH("sudo systemctl stop recipes")
 
-# Do not overwrite the configuration.
-if (!(Test-Path -Path $destination/conf.ron)) {
-   Copy-Item backend/conf.ron -Destination $destination
-}
+Copy-SSH -source "./target/arm-unknown-linux-gnueabihf/release/recipes" -destination "~/recipes/"
+Copy-SSH -source "./backend/static/" -destination "~/recipes/"
 
-systemctl --user start www-recipes.service
+Invoke-SSH("chmod u+x recipes/recipes")
+Invoke-SSH("sudo systemctl start recipes")
 
+Write-Output "Deployment finished"