Replace powershell script by nushell script
This commit is contained in:
parent
aedfae1d17
commit
b3751b28bf
3 changed files with 29 additions and 47 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -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
|
||||
|
|
|
|||
28
deploy.nu
Normal file
28
deploy.nu
Normal file
|
|
@ -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"
|
||||
}
|
||||
|
||||
46
deploy.ps1
46
deploy.ps1
|
|
@ -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 <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"
|
||||
Loading…
Add table
Add a link
Reference in a new issue