-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReset-WebOsDeveloperMode.ps1
54 lines (48 loc) · 1.77 KB
/
Reset-WebOsDeveloperMode.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
function Reset-WebOsDeveloperMode {
<#
.SYNOPSIS
Script to auto reset the webos developer mode in LG televisions
.NOTES
The passphrase needs to be already added to the SSH agent or the script will stop to ask for it.
Requires Send-TelegramBotMsg to send a warning message in case of error
Based on: /~https://github.com/webosbrew/dev-goodies/blob/main/reset-devmode-timer.sh
.ToDo
- que el script se ejecute cada vez que se reinicie el pc o cada 25 h, lo que pase antes
- Cambiar la implementación de sendErrorToTelegram por el cmdlet send-telegram
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]$Address,
[string]$User = "prisoner",
[string]$Port = "9922",
[string]$SshKeyPath = "${HOME}\.ssh\tv_webos",
[string]$SessionToken,
[string]$TelegramToken,
[string]$TelegramChatId
)
begin {
if ([string]::IsNullOrEmpty($sessionToken)) {
$sessionToken = ssh -i $sshKeyPath -o ConnectTimeout=3 -o StrictHostKeyChecking=no -p $port "$user@$address" cat /var/luna/preferences/devmode_enabled
}
}
process {
# Telegram warning
if ([string]::IsNullOrEmpty($sessionToken)) {
sendErrorToTelegram("Token de sesión vacío")
return
}
$session = ConvertFrom-Json (curl --max-time 3 -s "https://developer.lge.com/secure/ResetDevModeSession.dev?sessionToken=${sessionToken}")
}
end {
if ($session.result -ne "success") {
$msg = "Error extending developer mode in WebOs: `r Error $($session.errorCode): $($session.errorMsg)"
if ([string]::IsNullOrEmpty($TelegramToken) -or [string]::IsNullOrEmpty($TelegramChatId)) {
Write-Error $msg
return
}
Send-TelegramBotMsg -Token $TelegramToken -ChatId $TelegramChatId -Message $msg
}
}
}