Search This Blog

Thursday, October 16, 2025

20

Am I still here? This was scheduled long ago. 

Today is 20. Am I still here?

Wednesday, July 09, 2025

Renew getssl automatically

 run this on cron every 30 */13 - requires preshared ssh key between the webserver and router

 #!/bin/bash
exec 3>&1 4>&2
trap 'exec 2>&4 1>&3' 0 1 2 3 RETURN
exec 1>>/var/log/upd-gtssl.log 2>&1
echo "$(date) : Script - start" >&3 # This still shows on console

# make sure this runs every 89 days since the day the cert was renew. (in my case this happen to be "day 59 of a 89 days cycle")
if test $(( $(date +%s)/24/60/60%89 )) = 59; then
echo $(date) - renew cert.

#open port 80 in firewall, so getssl can be confirmed
ssh -x router -q 'iptables -t nat -I PREROUTING -d $(nvram get wan_ipaddr) -p tcp --dport 80 -j DNAT --to-destination webserver:80 && iptables -I FORWARD -p tcp -d webserver --dport 80 -j ACCEPT'

#renew cert
cd /usr/local/etc/getssl/
/usr/local/etc/getssl/getssl mydomain.tld
sleep 10

#close port 80 in firewall, we don't run plain http
ssh -x router -q 'iptables -t nat -D PREROUTING -d $(nvram get wan_ipaddr) -p tcp --dport 80 -j DNAT --to-destination webserver:80 && iptables -D FORWARD -p tcp -d webserver --dport 80 -j ACCEPT'
else
echo $(date) - Cert still good.
fi

Thursday, June 05, 2025

Make Win 10 or 11 Pro / Ent LTSC

@echo off

:: first go get the skus.zip - in the issues are the ones for W11 too
echo  Starting conversion to LTSC... 

:: If not launched as admin, relaunch
net.exe session 2>NUL 1>&2
if not %errorlevel%==0 (echo  You are NOT ADMIN. Relaunching... 
powershell Start -File "cmd '/K %~f0 runas'" -Verb RunAs
goto out)

:start
    pushd "%CD%"
    CD /D "%~dp0"
    echo  Take ownership of the skus subfolders 
    "%windir%\system32\takeown.exe" /F "%windir%\system32\spp\tokens\skus\csvlk-pack" /R /A /D Y
    "%windir%\system32\icacls.exe" "%windir%\system32\spp\tokens\skus\csvlk-pack" /T /grant Administrators:F
    "%windir%\system32\takeown.exe" /F "%windir%\system32\spp\tokens\skus\IoTEnterpriseS" /R /A /D Y
    "%windir%\system32\icacls.exe" "%windir%\system32\spp\tokens\skus\IoTEnterpriseS" /T /grant Administrators:F
    "%windir%\system32\takeown.exe" /F "%windir%\system32\spp\tokens\skus\IoTEnterpriseSK" /R /A /D Y
    "%windir%\system32\icacls.exe" "%windir%\system32\spp\tokens\skus\IoTEnterpriseSK" /T /grant Administrators:F
    "%windir%\system32\takeown.exe" /F "%windir%\System32\spp\tokens\EnterpriseS" /R /A /D Y
    "%windir%\system32\icacls.exe" "%windir%\system32\spp\tokens\skus\EnterpriseS" /T /grant Administrators:F
    echo. 

    echo  Extract and copy the new skus 
    FOR /F "tokens=1,2,3 delims= " %%A IN ('wmic os get Caption') DO @IF %%C EQU 10 "%windir%\System32\tar.exe" -v -x -f skus10.zip -C %windir%\system32\spp\tokens\skus
    FOR /F "tokens=1,2,3 delims= " %%A IN ('wmic os get Caption') DO @IF %%C EQU 11 "%windir%\System32\tar.exe" -v -x -f skus11.zip -C %windir%\system32\spp\tokens\skus
    
    echo  Reinstall the new licenses - be patient, this will take a minute 
    cscript.exe %windir%\system32\slmgr.vbs /rilc
    echo  Uninstall the actual product key 
    cscript.exe %windir%\system32\slmgr.vbs /upk
    echo  Remove the KMS 
    cscript.exe %windir%\system32\slmgr.vbs /ckms
    echo  Remove the old product key from registry 
    cscript.exe %windir%\system32\slmgr.vbs /cpky
    echo  Install LTSC Product key 
    :: use key from https://learn.microsoft.com/en-us/windows-server/get-started/kms-client-activation-keys - it requires a KMS Server, otherwise you will have to manually change the license from KMS to MAK
    cscript.exe %windir%\system32\slmgr.vbs /ipk M7XTQ-FN8P6-TTKYV-9D4CC-J462D
   

:end
    :: cleanup
    del /f /q "skus*.zip" 2>nul
    :: check the Windows version
    wmic os get Caption | findstr "Microsoft"
    echo  Now we should reboot... 
    choice /t 30 /c yn /d n /n /m "press  "Y"  in the next 30 seconds if you want to reboot"
    if errorlevel 2 goto :out
    if errorlevel 1 shutdown.exe -r -f -t 0

:out
    :: reset the colors
    echo.

Friday, May 02, 2025

Remove .appx from some newly converted to LTSC computers


$ErrorActionPreference= 'silentlycontinue'

$cred = Get-Credential -Message "Please enter admin credentials valid on target computers";
if($cred -isnot [PSCredential]) {Write-Host -ForegroundColor Red -BackgroundColor DarkBlue "No valid credentials provided. Exiting!" ; exit 1}

foreach($comp in Get-Content -Path C:\temp\complist.txt) {
 Write-Host -ForegroundColor Blue -NoNewline " `nStart on $comp : "
 $sess = New-PSSession -Credential $cred $comp
 if ($?) { Write-Host -ForegroundColor Green "session to $comp established";
  Invoke-Command -Session $sess -scriptblock { Get-AppxPackage -AllUsers | Remove-AppxPackage -ErrorAction Continue; Get-AppxProvisionedPackage -Online | Remove-AppxProvisionedPackage -Online; }
  if ($?) {  Write-Host -ForegroundColor Green "RAN on $sess" } else { Write-Host -ForegroundColor Red "FAIL on $sess" }
 }else{ Write-Host -ForegroundColor Red "Unable to connect to $comp" }
}

Write-Host -ForegroundColor Yellow -BackgroundColor DarkGreen "`nScript Done!`n"
exit

Friday, April 04, 2025

AHK Mousemover

 #Persistent
Menu, Tray, Icon, Shell32.dll, 174
Menu, Tray, Tip, MM-rnd
Menu, Tray, NoStandard
Menu, Tray, Add, Exit, Exit
return

loop {
Random, RandomSleep, 2000, 100000
sleep, %RandomSleep%
mousemove, 10, 0, 10, R
mousemove, -10, 0, 10, R
}

Exit:
ExitApp

Tuesday, March 04, 2025

Import multiple CSV files into separate Excel worksheets

 #import multiple CSV files into separate Excel worksheets
$wrkfldr='C:\temp'

$excel = New-Object -ComObject Excel.Application
$excel.Visible = $true
$wb = $excel.Workbooks.Add()

Get-ChildItem $wrkfldr\*.csv | ForEach-Object {
    if ((Import-Csv $_.FullName).Length -gt 0) {
        $csvBook = $excel.Workbooks.Open($_.FullName)
        $csvBook.ActiveSheet.Copy($wb.Worksheets($wb.Worksheets.Count))
        $csvBook.Close()
    }
}

Wednesday, February 05, 2025

RPI network reconnect

to be run */10 * * * * from cron

#!/bin/bash

wlan='wlan0'
gateway='192.168.1.1'

ping -c2 $gateway 2>&1 >/dev/null; rc=$?
if [[ $rc -eq 0 ]] ; then
        echo `date +"%b %d %T "`$0": The network is up."
else
        echo `date +"%b %d %T "`$0": Network down! Attempting reconnection."
        if [ -f /storage/.cache/nonet ]; then
                rm -f /storage/.cache/nonet
                reboot
        fi
        ifdown $wlan
        rmmod brcmfmac
        sleep 2
        modprobe brcmfmac brcmfmac_wcc
        ifup --force $wlan
        sleep 2
        connmanctl connect wifi_dc345a1743d_6e6545675289d3567_managed_psk &>/dev/null
        sleep 10
        ping -c2 $gateway 2>&1 >/dev/null; rc=$?
        if [[ $rc -ne 0 ]] ; then
                echo "1" > /storage/.cache/nonet
        fi
fi
exit 0