OPNsense Forum

English Forums => General Discussion => Topic started by: carrot on January 07, 2021, 03:34:38 PM

Title: Using API to perform Major Update / Upgrade
Post by: carrot on January 07, 2021, 03:34:38 PM
Hi everyone

I'm struggling to find a way to perform a Major update (e.g. from 19.1 to 19.7) using the API.  Is there anyone who has successfully done this using the API or other programmatic method?
Title: Re: Using API to perform Major Update / Upgrade
Post by: carrot on January 07, 2021, 04:43:29 PM
I found the answer to make it go via cmd:
sudo --user=nobody  /usr/local/sbin/configctl firmware auto-update ALLOW_RISKY_MAJOR_UPGRADE

Title: Re: Using API to perform Major Update / Upgrade
Post by: carrot on February 04, 2021, 05:41:47 PM
Here is the Powershell version (including ignoring ssl error)

add-type @"
    using System.Net;
    using System.Security.Cryptography.X509Certificates;
    public class TrustAllCertsPolicy : ICertificatePolicy {
        public bool CheckValidationResult(
            ServicePoint srvPoint, X509Certificate certificate,
            WebRequest request, int certificateProblem) {
            return true;
        }
    }
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy

$user = 'APIKEY'
$pass = 'APISECRET'

$pair = "$($user):$($pass)"

$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))

$basicAuthValue = "Basic $encodedCreds"

$Headers = @{
    Authorization = $basicAuthValue
}

$URL = "https://IPOFROUTER/api/core/firmware/upgrade"
Invoke-WebRequest -uri $url -method post -Headers $Headers -Body '{"upgrade":"maj"}' -ContentType "application/json"