-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuildAndDeploy.ps1
More file actions
46 lines (40 loc) · 1.62 KB
/
buildAndDeploy.ps1
File metadata and controls
46 lines (40 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#Requires -Modules Posh-SSH
param([switch]$enableService=$false, [switch]$runService=$false, $c='Debug')
$rsaKeyFile = '~/.ssh/personal'
# Posh-SSH will use password to decrypt key with passphrase
# SSH Session to run bash commands over SSH
$sshSession = Get-SSHSession
# SFTP Session to copy build result
$sftpSession = Get-SFTPSession
if (!$sshSession -Or !$sshSession.Connected -Or !$sftpSession -Or !$sftpSession.Connected)
{
$credentials = (Get-Credential pi)
}
if(!$sshSession)
{
$sshSession = New-SSHSession -Computer raspberrypi.local -Credential $credentials -KeyFile $rsaKeyFile
}
if(!$sftpSession)
{
$sftpSession = New-SFTPSession -Computer raspberrypi.local -Credential $credentials -KeyFile $rsaKeyFile
}
dotnet publish RpiProbeLogger\RpiProbeLogger.csproj --self-contained -r linux-arm -f net6.0 -c $c
# Copy build result if no errors
if ($?) {
Set-SFTPFolder -SFTPSession $sftpSession -RemotePath '/home/pi/RpiProbeLogger' -LocalFolder "RpiProbeLogger\bin\$($c)\net5.0\linux-arm\publish" -Overwrite
Invoke-SSHCommand -Command 'chmod +x /home/pi/RpiProbeLogger/RpiProbeLogger' -SSHSession $sshSession
if ($enableService)
{
Invoke-SSHCommand -Command 'sudo systemctl enable /home/pi/RpiProbeLogger/probelogger.service' -SSHSession $sshSession
}
else {
Invoke-SSHCommand -Command 'sudo systemctl disable /home/pi/RpiProbeLogger/probelogger.service' -SSHSession $sshSession
}
if ($enableService -And $runService)
{
Invoke-SSHCommand -Command 'sudo systemctl start probelogger.service' -SSHSession $sshSession
}
else {
Invoke-SSHCommand -Command 'sudo systemctl stop probelogger.service' -SSHSession $sshSession
}
}