Skip to content

A hardened Linux desktop, rebuilt from scratch, with your Windows apps built in. Free and open source.

Fixes for the first reports from testing

Danc712758ad19e
diff --git a/build/hooks/10-locale.sh b/build/hooks/10-locale.sh
index 0caba17..8a052ba 100644
--- a/build/hooks/10-locale.sh
+++ b/build/hooks/10-locale.sh
@@ -1,7 +1,11 @@
-# English (US) is the fallback until the installer asks; the live session needs
-# a generated UTF-8 locale or Plasma and Qt apps fall back to ASCII.
+# English (UK) until someone picks another language, the same default the
+# installer, first start and Settings use (the start-up menu passes no
+# language yet). The installer takes the live session's LANG, so an en_US
+# here installed every PC with a US keyboard and New York time. The live
+# session needs a generated UTF-8 locale or Plasma and Qt apps fall back to
+# ASCII.
sed -i 's/^# *\(en_US.UTF-8 UTF-8\)/\1/; s/^# *\(en_GB.UTF-8 UTF-8\)/\1/' /etc/locale.gen
locale-gen
-update-locale LANG=en_US.UTF-8
+update-locale LANG=en_GB.UTF-8
echo wildos > /etc/hostname
diff --git a/build/patches/calamares/wildos-disk-page.patch b/build/patches/calamares/wildos-disk-page.patch
index 5eb1aa6..cb5c467 100644
--- a/build/patches/calamares/wildos-disk-page.patch
+++ b/build/patches/calamares/wildos-disk-page.patch
@@ -782,7 +782,7 @@ Forwarded: no
if ( tableType != PartitionTable::unknownTableType && !matchTableType )
{
m_messageLabel->setText( tr( "This storage device already has an operating system on it, "
-@@ -1616,13 +1769,177 @@ ChoicePage::updateSwapChoicesTr()
+@@ -1616,13 +1769,189 @@ ChoicePage::updateSwapChoicesTr()
}
}
@@ -958,7 +958,19 @@ Forwarded: no
+ visit( QModelIndex() );
+ if ( best.isValid() )
+ {
-+ m_beforePartitionBarsView->selectionModel()->setCurrentIndex( best, QItemSelectionModel::ClearAndSelect );
++ // Going back to Alongside after another choice builds the page
++ // twice, the second time once that plan is undone, each with a new
++ // splitter. The second finds this partition already current, and
++ // Qt only signals a change, so that splitter is set up here.
++ auto* selection = m_beforePartitionBarsView->selectionModel();
++ if ( selection->currentIndex() == best )
++ {
++ doAlongsideSetupSplitter( best, QModelIndex() );
++ }
++ else
++ {
++ selection->setCurrentIndex( best, QItemSelectionModel::ClearAndSelect );
++ }
}
}
diff --git a/packages/wildos-branding/debian/postinst b/packages/wildos-branding/debian/postinst
index 6cfbb25..ddeb4e8 100644
--- a/packages/wildos-branding/debian/postinst
+++ b/packages/wildos-branding/debian/postinst
@@ -26,6 +26,19 @@ if [ "$1" = "configure" ]; then
dracut --regenerate-all --force >/dev/null 2>&1 || echo "wildos-branding: could not rebuild the initramfs; the new boot screen shows after the next kernel update" >&2
fi
+ # USBGuard blocks new devices by switching each USB controller's
+ # authorized_default to 0, and by default leaves it there when it stops.
+ # Turning USB protection off in Settings stops the service, so without
+ # this every device plugged in afterwards stayed blocked until a restart.
+ conf=/etc/usbguard/usbguard-daemon.conf
+ if [ -f "$conf" ]; then
+ if grep -q '^RestoreControllerDeviceState=' "$conf"; then
+ sed -i 's/^RestoreControllerDeviceState=.*/RestoreControllerDeviceState=true/' "$conf"
+ else
+ echo 'RestoreControllerDeviceState=true' >> "$conf"
+ fi
+ fi
+
# grub.cfg names the theme, so a system that had none picks it up here.
# The image has no grub.cfg (the installer makes one).
if [ -e /boot/grub/grub.cfg ] && command -v update-grub >/dev/null; then
diff --git a/packages/wildos-desktop-view/qml/DesktopView.qml b/packages/wildos-desktop-view/qml/DesktopView.qml
index 503e4e9..28d7b25 100644
--- a/packages/wildos-desktop-view/qml/DesktopView.qml
+++ b/packages/wildos-desktop-view/qml/DesktopView.qml
@@ -1,6 +1,7 @@
pragma ComponentBehavior: Bound
import QtQuick
+import QtQuick.Templates as T
import QtQuick.Window
import WildOS.UI as UI
@@ -666,9 +667,14 @@ FocusScope {
}
}
+ // A window of its own, like the taskbar's menus. Drawn inside the
+ // desktop's window it sat in the desktop layer, under every open
+ // window it overlapped. Outside that window the wallpaper can no longer
+ // be blurred through it, so it takes the taskbar menus' glass too.
UI.Menu {
id: menu
- backdrop: view.backdrop
+ popupType: T.Popup.Window
+ panelColor: UI.Style.glassMenu
// Menus stay clear of the taskbar, which is a window of its own
// above this one.
topMargin: view.area.y + 6
diff --git a/packages/wildos-files/qml/FilesView.qml b/packages/wildos-files/qml/FilesView.qml
index 06a249d..5e062ea 100644
--- a/packages/wildos-files/qml/FilesView.qml
+++ b/packages/wildos-files/qml/FilesView.qml
@@ -203,8 +203,9 @@ Item {
return;
}
// Each Properties is a window of its own, as on Windows, kept above
- // the Files window it came from.
- const window = propertiesComponent.createObject(null, { view: root, urls: list, transientParent: root.Window.window });
+ // the Files window it came from. It needs an owner: with none, the
+ // JavaScript garbage collector deleted it moments after it opened.
+ const window = propertiesComponent.createObject(root,{ view: root, urls: list, transientParent: root.Window.window });
window.show();
}
diff --git a/packages/wildos-files/src/drives.cpp b/packages/wildos-files/src/drives.cpp
index 206c27d..431eb53 100644
--- a/packages/wildos-files/src/drives.cpp
+++ b/packages/wildos-files/src/drives.cpp
@@ -149,7 +149,12 @@ QList<Drive> Drives::scan() const
auto access = device.as<Solid::StorageAccess>();
auto volume = device.as<Solid::StorageVolume>();
auto block = device.as<Solid::Block>();
- if (!access || access->isIgnored()) {
+ // Solid's StorageAccess::isIgnored() also says yes to every volume
+ // that isn't mounted (its path is empty, so not under /media), which
+ // hid a USB stick allowed through USBGuard until something mounted
+ // it. Hidden volumes are caught by StorageVolume::isIgnored() below,
+ // and mounts outside the user's paths by userMountPath().
+ if (!access || (access->isAccessible() && access->isIgnored())) {
continue;
}
if (volume && (volume->isIgnored() || volume->usage() != Solid::StorageVolume::FileSystem)) {
diff --git a/packages/wildos-overlays/screenshot/qml/Main.qml b/packages/wildos-overlays/screenshot/qml/Main.qml
index e1dc2cb..dda8d4d 100644
--- a/packages/wildos-overlays/screenshot/qml/Main.qml
+++ b/packages/wildos-overlays/screenshot/qml/Main.qml
@@ -21,12 +21,12 @@ QtObject {
Connections {
target: ScreenshotApp
function onMarkupRequested(file) {
- const window = markupWindow.createObject(null, { file: file });
+ const window = markupWindow.createObject(root, { file: file });
window.show();
window.requestActivate();
}
function onShareRequested(file) {
- const window = shareWindow.createObject(null, { file: file });
+ const window = shareWindow.createObject(root, { file: file });
window.show();
window.requestActivate();
}
diff --git a/packages/wildos-system-dialogs/data/wildos-dialogs.service b/packages/wildos-system-dialogs/data/wildos-dialogs.service
index 067a1e9..2d5f3cd 100644
--- a/packages/wildos-system-dialogs/data/wildos-dialogs.service
+++ b/packages/wildos-system-dialogs/data/wildos-dialogs.service
@@ -5,7 +5,7 @@ After=plasma-core.target
[Service]
ExecStart=/usr/libexec/wildos/wildos-dialogs --session
-BusName=org.wildos.Dialogs
+BusName=org.wildos.SystemDialogs
Slice=session.slice
TimeoutStopSec=5sec
Restart=on-failure
diff --git a/packages/wildos-system-dialogs/src/session.h b/packages/wildos-system-dialogs/src/session.h
index 0044a93..ad7a691 100644
--- a/packages/wildos-system-dialogs/src/session.h
+++ b/packages/wildos-system-dialogs/src/session.h
@@ -15,7 +15,7 @@ QString id();
QDBusObjectPath path();
}
-// org.wildos.Dialogs on the session bus, served by the long-running
+// org.wildos.SystemDialogs on the session bus, served by the long-running
// "wildos-dialogs --session". Ctrl+Alt+Del and Settings start a short-lived
// "wildos-dialogs security" or "restart", which asks this to show the
// screen that is already loaded, so it appears at once.
@@ -27,12 +27,12 @@ QDBusObjectPath path();
class DialogsService : public QObject, protected QDBusContext
{
Q_OBJECT
- Q_CLASSINFO("D-Bus Interface", "org.wildos.Dialogs")
+ Q_CLASSINFO("D-Bus Interface", "org.wildos.SystemDialogs")
public:
using QObject::QObject;
- static constexpr const char *serviceName = "org.wildos.Dialogs";
+ static constexpr const char *serviceName = "org.wildos.SystemDialogs";
static constexpr const char *objectPath = "/Dialogs";
// Asks the running service; false when there is none or it did not
diff --git a/packages/wildos-winmode/guest/api.txt b/packages/wildos-winmode/guest/api.txt
index bd4f435..3cbae14 100644
--- a/packages/wildos-winmode/guest/api.txt
+++ b/packages/wildos-winmode/guest/api.txt
@@ -95,7 +95,9 @@ member [mscorlib]System.IO.File.ReadAllText :: string(string)
member [mscorlib]System.IO.File.WriteAllText :: void(string, string)
member [mscorlib]System.IO.FileInfo..ctor :: instance void(string)
member [mscorlib]System.IO.FileInfo.get_Length :: instance int64()
+member [mscorlib]System.IO.FileSystemInfo.get_Attributes :: instance valuetype [mscorlib]System.IO.FileAttributes()
member [mscorlib]System.IO.FileSystemInfo.get_Exists :: instance bool()
+member [mscorlib]System.IO.FileSystemInfo.set_Attributes :: instance void(valuetype [mscorlib]System.IO.FileAttributes)
member [mscorlib]System.IO.IOException..ctor :: instance void(string)
member [mscorlib]System.IO.MemoryStream..ctor :: instance void()
member [mscorlib]System.IO.MemoryStream.ToArray :: instance unsigned int8[]()
@@ -391,6 +393,7 @@ type [mscorlib]System.IO.BinaryWriter
type [mscorlib]System.IO.Directory
type [mscorlib]System.IO.DirectoryInfo
type [mscorlib]System.IO.File
+type [mscorlib]System.IO.FileAttributes
type [mscorlib]System.IO.FileInfo
type [mscorlib]System.IO.FileSystemInfo
type [mscorlib]System.IO.IOException
diff --git a/packages/wildos-winmode/guest/setup.ps1 b/packages/wildos-winmode/guest/setup.ps1
index ef87517..c9e6481 100644
--- a/packages/wildos-winmode/guest/setup.ps1
+++ b/packages/wildos-winmode/guest/setup.ps1
@@ -253,6 +253,8 @@ Step 'updates' $false {
# 6. Known folders point at the shared folders, so Save in any Windows app
# lands on Wild OS. These are the values Explorer's own Location tab writes.
+# The drive only exists while a RemoteApp connection is open (wild-guest maps
+# it on connect), and none is open during setup, so nothing here may touch it.
Step 'known-folders' $true {
$usf = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders'
$map = [ordered]@{
@@ -263,20 +265,16 @@ Step 'known-folders' $true {
}
foreach ($folder in $settings.folders) {
$target = "$($drive):\$folder"
- if (-not (Test-Path $target)) { New-Item -ItemType Directory -Force $target | Out-Null }
foreach ($value in $map[$folder]) { Set-Value $usf $value $target 'ExpandString' }
}
}
# 7. Office, once installed, saves to this PC rather than OneDrive and keeps
# its AutoRecover files beside the documents (brief 5.4 and 5.7). Policy
-# values can be set before Office exists.
+# values can be set before Office exists. wild-guest makes the AutoRecover
+# folder once the drive is mapped.
Step 'office-policies' $false {
$autorecover = "$($drive):\Documents\.autorecover"
- if (-not (Test-Path $autorecover)) {
- $d = New-Item -ItemType Directory -Force $autorecover
- $d.Attributes = $d.Attributes -bor [IO.FileAttributes]::Hidden
- }
$op = 'HKCU:\Software\Policies\Microsoft\Office\16.0'
Set-Value "$op\Common\General" 'PreferCloudSaveLocations' 0
Set-Value "$op\Word\Options" 'DOC-PATH' "$($drive):\Documents" 'ExpandString'
@@ -363,7 +361,7 @@ $settings = Get-Content "$state\settings.json" -Raw | ConvertFrom-Json
$deadline = (Get-Date).AddSeconds(180)
while ((Get-Date) -lt $deadline) {
$rdp = Get-NetTCPConnection -LocalPort 3389 -State Listen -ErrorAction SilentlyContinue
- if ($rdp -and (Test-Path "$($settings.drive):\Documents")) { break }
+ if ($rdp) { break }
Start-Sleep -Seconds 2
}
$cv = Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
@@ -375,7 +373,6 @@ $cv = Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
rdp_listening = [bool](Get-NetTCPConnection -LocalPort 3389 -State Listen -ErrorAction SilentlyContinue)
shared_folder = [bool](Test-Path "$($settings.drive):\Documents")
guest_agent = (Get-Service QEMU-GA).Status.ToString()
- virtiofs = (Get-Service VirtioFsSvc).Status.ToString()
boot = (Get-CimInstance Win32_OperatingSystem).LastBootUpTime.ToString('s')
} | ConvertTo-Json | Set-Content -Encoding UTF8 "$state\ready.json"
'@
diff --git a/packages/wildos-winmode/guest/wild-guest/Session.cs b/packages/wildos-winmode/guest/wild-guest/Session.cs
index ca62d99..706751a 100644
--- a/packages/wildos-winmode/guest/wild-guest/Session.cs
+++ b/packages/wildos-winmode/guest/wild-guest/Session.cs
@@ -155,6 +155,7 @@ namespace WildOS.Guest
if (result == 0)
{
Log.Write("mapped " + drive + " to " + share);
+ MakeAutoRecover(drive);
return;
}
Thread.Sleep(1000);
@@ -162,6 +163,23 @@ namespace WildOS.Guest
Log.Write("couldn't map " + drive + " to " + share + ": error " + result);
}
+ // Setup points Office's AutoRecover at this hidden folder but can't
+ // make it, since the drive doesn't exist until a connection does.
+ static void MakeAutoRecover(string drive)
+ {
+ try
+ {
+ string documents = drive + @"\Documents";
+ if (!Directory.Exists(documents)) return;
+ var dir = Directory.CreateDirectory(documents + @"\.autorecover");
+ dir.Attributes |= FileAttributes.Hidden;
+ }
+ catch (Exception e)
+ {
+ Log.Write("autorecover folder: " + e.Message);
+ }
+ }
+
static long ConnectTime()
{
IntPtr buffer;
diff --git a/packages/wildos-winmode/setup/qml/StepLicence.qml b/packages/wildos-winmode/setup/qml/StepLicence.qml
index e25e6a3..ea17640 100644
--- a/packages/wildos-winmode/setup/qml/StepLicence.qml
+++ b/packages/wildos-winmode/setup/qml/StepLicence.qml
@@ -3,15 +3,16 @@ import QtQuick.Layouts
import WildOS.UI as UI
import WildOS.WinMode.Backend
-// 9.2 (WinModeHome.dc) when the licence is for Windows 11 Home, and 9.3
-// (WinModeNoLicence.dc) when there is none to use.
+// 9.3 (WinModeNoLicence.dc) when there is no licence Windows mode can use:
+// none built in, one still in use by Windows on this PC, or one for Windows
+// 11 Home. Windows mode always installs Pro; a Home key can't activate it.
Page {
id: page
// home, none or inuse
property string kind: "none"
- // licence: firmware, key or none; homeChoice: upgrade or home
+ // licence: key or none; homeChoice is always empty now
signal chosen(string licence, string key, string homeChoice)
signal skipped()
signal back()
@@ -19,15 +20,13 @@ Page {
readonly property bool home: kind === "home"
title: "Set up Windows mode"
- text: home ? "Windows apps can run on this PC. How smoothly depends on the edition of Windows it came with."
- : "Windows programs can still work on this PC. Choose how you'd like to handle the Windows licence."
- note: home ? "You can switch from Home to Pro later without setting anything up again."
- : "Your choice only affects Windows mode. The rest of Wild OS is free."
+ text: "Windows programs can still work on this PC. Choose how you'd like to handle the Windows licence."
+ note: "Windows mode needs Windows 11 Pro. A Home key won't activate it."
Banner {
- tone: page.home ? "accent" : "warning"
- title: page.home ? "Windows 11 Home found" : page.kind === "inuse" ? "Windows is still installed on this PC" : "No Windows licence built into this PC"
- text: page.home ? "Your licence works with Windows mode. Pro has a feature built in that shows each app as a normal window; Home doesn't, so on Home we use our own method instead."
+ tone: "warning"
+ title: page.home ? "This PC came with Windows 11 Home" : page.kind === "inuse" ? "Windows is still installed on this PC" : "No Windows licence built into this PC"
+ text: page.home ? "Windows mode needs Windows 11 Pro, so this licence can't activate it. Set it up without activating, or with a Pro key."
: page.kind === "inuse" ? "Its licence covers one copy of Windows at a time, and that copy is still on this PC. A key from another licence works for Windows mode."
: "Common on self-built PCs and older machines. A key from a previous PC often still works."
}
@@ -35,44 +34,6 @@ Page {
ColumnLayout {
Layout.fillWidth: true
spacing: 10
- visible: page.home
- Accessible.role: Accessible.Grouping
- Accessible.name: "Windows edition"
-
- RadioCard {
- id: upgrade
- checked: true
- title: "Upgrade to Windows 11 Pro"
- chip: "Recommended"
- description: "Fully supported. Apps open quickly and look and behave like the rest of your desktop. Microsoft sells the upgrade, and it uses the licence you already have."
-
- UI.LinkButton {
- text: "See the price on Microsoft's site"
- onClicked: Setup.openUrl("https://www.microsoft.com/en-gb/d/windows-11-pro/dg7gmgf0d7fv")
- }
- }
-
- RadioCard {
- id: useHome
- enabled: false
- title: "Use Windows 11 Home"
- chip: "Experimental"
- chipTone: "warning"
- description: "Free with your licence and works for most apps, but it's still being developed and isn't supported yet. Apps can be slower to draw, and some, including parts of Office, may look or behave oddly."
- reason: "Not ready yet. Upgrade to Pro, or skip for now."
- }
-
- RadioCard {
- id: skipHome
- title: "Skip Windows mode for now"
- description: "Many Windows programs still run on the desktop without it, and Office works in the browser."
- }
- }
-
- ColumnLayout {
- Layout.fillWidth: true
- spacing: 10
- visible: !page.home
Accessible.role: Accessible.Grouping
Accessible.name: "Windows licence"
@@ -80,7 +41,7 @@ Page {
id: withKey
checked: true
title: "Enter a product key"
- description: "From a sticker, an email or a licence you bought for another PC."
+ description: "A Windows 11 Pro key, from a sticker, an email or a licence you bought for another PC."
RowLayout {
spacing: 8
@@ -100,7 +61,7 @@ Page {
UI.LinkButton {
text: "Where to buy a licence"
- onClicked: Setup.openUrl("https://www.microsoft.com/en-gb/d/windows-11-home/dg7gmgf0krt0")
+ onClicked: Setup.openUrl("https://www.microsoft.com/en-gb/d/windows-11-pro/dg7gmgf0d7fv")
}
}
@@ -133,15 +94,9 @@ Page {
UI.Button {
kind: "primary"
text: "Continue"
- enabled: page.home || !withKey.checked || Setup.keyShapeValid(keyField.text)
+ enabled: !withKey.checked || Setup.keyShapeValid(keyField.text)
onClicked: {
- if (page.home) {
- if (skipHome.checked) {
- page.skipped();
- } else {
- page.chosen("firmware", "", upgrade.checked ? "upgrade" : "home");
- }
- } else if (skipNone.checked) {
+ if (skipNone.checked) {
page.skipped();
} else if (noKey.checked) {
page.chosen("none", "", "");
diff --git a/packages/wildos-winmode/winmode/agent.py b/packages/wildos-winmode/winmode/agent.py
index 5976610..560c438 100644
--- a/packages/wildos-winmode/winmode/agent.py
+++ b/packages/wildos-winmode/winmode/agent.py
@@ -500,7 +500,7 @@ class Agent:
self.dialogs("HideWindowsStarting", None)
def dialogs(self, method, args):
- self.session.call("org.wildos.Dialogs", "/Dialogs", "org.wildos.Dialogs", method, args, None,
+ self.session.call("org.wildos.SystemDialogs", "/Dialogs", "org.wildos.SystemDialogs", method, args, None,
Gio.DBusCallFlags.NO_AUTO_START, 2000, None, None, None)
def launch_in_session(self, path, args, name, app_id, started, done, wake):
diff --git a/packages/wildos-winmode/winmode/setup.py b/packages/wildos-winmode/winmode/setup.py
index 1735a45..9f5ca53 100644
--- a/packages/wildos-winmode/winmode/setup.py
+++ b/packages/wildos-winmode/winmode/setup.py
@@ -63,8 +63,13 @@ WINFSP_URL = "https://github.com/winfsp/winfsp/releases/download/v2.1/winfsp-2.1
WINFSP_SHA256 = "073a70e00f77423e34bed98b86e600def93393ba5822204fac57a29324db9f7a"
VIRTIO_BASE = "https://fedorapeople.org/groups/virt/virtio-win/direct-downloads"
# Microsoft's published generic installation key for Pro: installs Pro but
-# never activates, for "carry on without activating" (brief 5.4).
+# never activates. Every setup installs with it, so Windows is always Pro,
+# the edition with the Remote Desktop host Windows mode needs. The person's
+# own key, from the firmware or typed in, goes in at the activate stage,
+# where Windows turns down one for Home, instead of an hour of setup ending
+# on an edition that can't work.
GENERIC_PRO_KEY = "VK7JG-NPHTM-C97JM-9MPGT-3V66T"
+ACTIVATION_KEY = "activation-key"
KEY_ALPHABET = "BCDFGHJKMNPQRTVWXY2346789"
GUEST_MAC = "52:54:00:57:4f:01"
OFFICE_PRODUCTS = {"personal": "O365HomePremRetail", "family": "O365HomePremRetail",
@@ -423,9 +428,9 @@ class Setup:
os.makedirs(SECRETS, mode=0o700, exist_ok=True)
os.chmod(SECRETS, 0o700)
if source == "key":
- with open(os.path.join(SECRETS, "key"), "w") as f:
+ with open(os.path.join(SECRETS, ACTIVATION_KEY), "w") as f:
f.write(key + "\n")
- os.chmod(os.path.join(SECRETS, "key"), 0o600)
+ os.chmod(os.path.join(SECRETS, ACTIVATION_KEY), 0o600)
self.svc.state["setup"] = {}
self.save(running=True, started=int(time.time()), owner=owner_uid, options=options,
licence={"source": source, "edition": lic.get("edition") or ""},
@@ -467,7 +472,8 @@ class Setup:
if virsh.state(domain) != "":
virsh.run("destroy", domain, check=False)
virsh.run("undefine", domain, "--nvram", "--managed-save", check=False)
- for path in (DISK, os.path.join(CACHE, "payload.iso"), os.path.join(SECRETS, "key"), MARKER):
+ for path in (DISK, os.path.join(CACHE, "payload.iso"), os.path.join(SECRETS, "key"),
+ os.path.join(SECRETS, ACTIVATION_KEY), MARKER):
try:
os.remove(path)
except OSError:
@@ -638,12 +644,12 @@ class Setup:
os.chmod(msdm_copy, 0o640)
_apparmor_allow(msdm_copy)
elif lic.get("source") == "key":
- with open(os.path.join(SECRETS, "key")) as f:
+ with open(os.path.join(SECRETS, ACTIVATION_KEY)) as f:
key = f.read().strip()
else:
key = GENERIC_PRO_KEY
with open(os.path.join(SECRETS, "key"), "w") as f:
- f.write(key + "\n")
+ f.write(GENERIC_PRO_KEY + "\n")
os.chmod(os.path.join(SECRETS, "key"), 0o600)
lic["last5"] = key[-5:]
self.save(licence=lic)
@@ -950,6 +956,36 @@ class Setup:
return
self.set_stage("activate", "active", 10)
domain = self.cfg["domain"]
+ key = self.activation_key(lic)
+ if not key:
+ raise Problem("failed", "This PC's licence couldn't be read. Go back and add a product key instead.")
+ taken = None
+ for _ in range(3):
+ self.check()
+ try:
+ _, out, _ = qga.powershell(domain, (
+ f"try {{ Get-CimInstance SoftwareLicensingService | Invoke-CimMethod -MethodName InstallProductKey "
+ f"-Arguments @{{ProductKey='{key}'}} -ErrorAction Stop | Out-Null; 'taken' }} catch {{ 'refused' }}"), 120)
+ last = out.strip().splitlines()[-1] if out.strip() else ""
+ taken = True if last == "taken" else False if last == "refused" else None
+ except (virsh.VirshError, KeyError, TimeoutError, IndexError) as e:
+ log("product key:", e)
+ if taken is not None:
+ break
+ time.sleep(10)
+ if taken is False:
+ # Not a Windows 11 Pro key, most often one for Home. Windows
+ # stays Pro, unactivated, and works the same.
+ lic.update(activated=False, refused=True)
+ self.save(licence=lic)
+ self.forget_activation_key()
+ self.set_stage("activate", "done", 100,
+ ("This PC's licence is for another edition of Windows, usually Home, which Windows mode can't use. "
+ if lic.get("source") == "firmware" else
+ "Windows didn't accept that key. It may be for Home, which Windows mode can't use. ")
+ + "Windows works without activating; add a Windows 11 Pro key any time in Settings.")
+ self.mark("activate")
+ return
code = None
# The network may come up a moment after the agent does.
for _ in range(6):
@@ -967,12 +1003,33 @@ class Setup:
time.sleep(30)
lic["activated"] = code == 1
self.save(licence=lic)
+ if taken:
+ self.forget_activation_key()
# Not activating is not a failure: Windows works, and a key can be
# added in Settings (board 9.8).
self.set_stage("activate", "done", 100,
None if code == 1 else "Not activated yet. Windows works; add a key any time in Settings.")
self.mark("activate")
+ def activation_key(self, lic):
+ if lic.get("source") == "firmware":
+ try:
+ with open(os.path.join(SECRETS, "msdm.bin"), "rb") as f:
+ return parse_msdm(f.read())
+ except OSError:
+ return None
+ try:
+ with open(os.path.join(SECRETS, ACTIVATION_KEY)) as f:
+ return f.read().strip() or None
+ except OSError:
+ return None
+
+ def forget_activation_key(self):
+ try:
+ os.remove(os.path.join(SECRETS, ACTIVATION_KEY))
+ except OSError:
+ pass
+
def set_key(self, key):
"""For Settings, any time after setup. The key goes into Windows over
the guest agent and is never written to disk here."""
@@ -994,11 +1051,14 @@ class Setup:
return "That doesn't look like a Windows product key. Check it and try again."
try:
_, out, _ = qga.powershell(domain, (
- f"$s = Get-CimInstance SoftwareLicensingService; $s | Invoke-CimMethod -MethodName InstallProductKey "
- f"-Arguments @{{ProductKey='{key}'}} | Out-Null; $s | Invoke-CimMethod -MethodName RefreshLicenseStatus | Out-Null; "
+ f"$s = Get-CimInstance SoftwareLicensingService; try {{ $s | Invoke-CimMethod -MethodName InstallProductKey "
+ f"-Arguments @{{ProductKey='{key}'}} -ErrorAction Stop | Out-Null }} catch {{ 'refused'; exit }}; "
+ "$s | Invoke-CimMethod -MethodName RefreshLicenseStatus | Out-Null; "
r"cscript //nologo $env:SystemRoot\System32\slmgr.vbs /ato | Out-Null; "
"(Get-CimInstance SoftwareLicensingProduct -Filter \"ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f'"
" and PartialProductKey is not null\" | Select-Object -First 1).LicenseStatus"), 240)
+ if out.strip().endswith("refused"):
+ return "Windows didn't accept that key. Check it, and that it's for Windows 11 Pro: Windows mode can't use a Home key."
code = int(out.strip().splitlines()[-1]) if out.strip() else None
except (virsh.VirshError, ValueError, KeyError, TimeoutError, IndexError) as e:
log("product key:", e)