-
Notifications
You must be signed in to change notification settings - Fork 2
/
init.ps1
64 lines (51 loc) · 1.66 KB
/
init.ps1
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Enter PSScriptRoot
cd $PSScriptRoot
# Select USB port
function Get-Port() {
if ($IsWindows) {
$global:port = new-Object System.IO.Ports.SerialPort COM$(Get-CimInstance Win32_PnPEntity | where {$_.Name -like 'USB Serial Port*' } |Select-Object Name | select-string \d+ | % { $_.matches.Value }), $BaudRate, None, 8, one
}
elseif ($IsLinux) {
$global:device = $(dmesg | grep tty | grep -oE '[^ ]+$' | tail -n 1)
$global:port = New-Object System.IO.Ports.SerialPort /dev/$device, $BaudRate, None, 8, one
}
elseif ($IsMacOS) {
Write-Host "MacOS"
# TODO - needs testing
}
}
# Define and create queue files
$Callfile = ".\queue\call.txt"
$SMSfile = ".\queue\sms.txt"
if (!(Test-Path $CALLfile)) {
New-Item -itemType File -Name $CALLfile -Force
}
if (!(Test-Path $SMSfile)) {
New-Item -itemType File -Name $SMSfile -Force
}
# Define and create logs folder
$LogsFolder = ".\logs"
if (!(Test-Path $LogsFolder)) {
New-Item -Type Directory -Name $LogsFolder -Force
}
# Date Formats
function logFileFormat() {
$(Get-Date -Format "dd.MM.yyyy")
}
function LogFormat() {
$( Get-Date -Format "HH:mm:ss dd.MM.yyyy" )
}
# Received SMS Log
$ReceivedSMSFileLog = ".\$LogsFolder\receivedSMS-$(logFileFormat).log"
# Error file
$ErrLogFile = ".\$LogsFolder\error-$(logFileFormat).log"
# Clean empty lines from queue
function CALLCleanEmptyLines() {
(Get-Content $Callfile) | ? { $_ } | Set-Content $Callfile
}
function SMSCleanEmptyLines() {
(Get-Content $SMSfile) | ? { $_ } | Set-Content $SMSfile
}
# Lock
$LockFilePath = ".\Instance.Lock"
$Locked = $null -ne (Get-Item -Path $LockFilePath -EA 0)