milestone 1

This commit is contained in:
Fierelier 2019-12-26 07:20:41 +01:00
parent 4016c95243
commit acb5120de3
32 changed files with 429 additions and 25 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
desktop.ini
*.iso
*.zip
*.log
iso/*
tmp/*
bin/*

38
scripts/api/detection.py Normal file
View File

@ -0,0 +1,38 @@
opus.detect = Munch()
def _detectOS(osPath):
opus.main.output("detecting OS at " +osPath+ "...")
osInfo = Munch()
osInfo.version = Munch()
osInfo.version.major = 0
osInfo.version.minor = 0
osInfo.tags = []
opus.reg.mount(pJoin(osPath,"Windows","System32","config","SOFTWARE"))
osInfo.version.key = opus.reg.getKey(opus.reg.path + opus.reg.sep + "Microsoft" +opus.reg.sep+ "Windows NT" +opus.reg.sep + "CurrentVersion")
opus.reg.unmount()
try:
osInfo.version.major = int(osInfo.version.key.CurrentMajorVersionNumber.value)
osInfo.version.minor = int(osInfo.version.key.CurrentMinorVersionNumber.value)
except:
version = osInfo.version.key.CurrentVersion.value
osInfo.version.major = int(version.split(".")[0])
osInfo.version.minor = int(version.split(".")[1])
osInfo.version.string = str(osInfo.version.major) + "." + str(osInfo.version.minor)
if osInfo.version.string == "0.0": raise Exception("version unknown")
opus.main.output("\ndetected: Windows NT " +osInfo.version.string,1)
if osInfo.version.major > 5 and osInfo.version.major < 11: osInfo.tags.append("longhorn-series")
if osInfo.version.string == "6.0": osInfo.tags.append("vista")
if osInfo.version.string == "6.1": osInfo.tags.append("seven")
if osInfo.version.string == "6.2": osInfo.tags.append("eight")
if osInfo.version.string == "6.3": osInfo.tags.append("eightone"); osInfo.tags.append("nine")
if osInfo.version.string == "10.0": osInfo.tags.append("ten")
opus.main.output("tags: " +str(osInfo.tags),1)
return osInfo
opus.detect.os = _detectOS

View File

@ -1,24 +1,21 @@
def _func(msg,verbosity = 0):
opus.main = Munch()
def _mainOutput(msg,verbosity = 0):
if opus.verbosity > verbosity - 1:
print(msg)
opus.output = _func
with open('opus-nt.log','a') as file:
file.write(msg + "\n")
opus.main.output = _mainOutput
def _func(_scriptPath):
opus.output("executing: " +_scriptPath,1)
opus.script = Munch()
def _mainExecPy(_scriptPath):
opus.main.output("script -> execute -> " +_scriptPath,1)
_return = True
with open(_scriptPath) as _scriptFile:
exec(_scriptFile.read())
opus.main.output("done.",2)
return _return
opus.execPy = _func
def _func(_scriptPath):
opus.output("executing: " +_scriptPath,1)
_return = True
with open(_scriptPath) as _scriptFile:
exec(_scriptFile.read())
return _return
opus.execPy = _func
opus.script.execute = _mainExecPy

25
scripts/api/path.py Normal file
View File

@ -0,0 +1,25 @@
global os
import os
def _pathWalklevel(some_dir, level=0):
if level < 0:
for root, dirs, files in os.walk(some_dir):
yield root,dirs,files
return
some_dir = some_dir.rstrip(os.path.sep)
assert os.path.isdir(some_dir)
num_sep = some_dir.count(os.path.sep)
for root, dirs, files in os.walk(some_dir):
yield root, dirs, files
num_sep_this = root.count(os.path.sep)
if num_sep + level <= num_sep_this:
del dirs[:]
opus.path.walklevel = _pathWalklevel
def _pathEasywalk(dir,depth = 0):
for root, dirs, files in opus.files.walklevel(dir,depth):
for file in files:
yield p(root,file)
opus.path.easywalk = _pathEasywalk

53
scripts/api/registry.py Normal file
View File

@ -0,0 +1,53 @@
global subprocess
import subprocess
global winreg
import winreg
opus.reg = Munch()
opus.reg.sep = "\\"
opus.reg.path = "OPUS_TMP"
def _regUnmount():
opus.main.output("registry > unmount",2)
rtn = subprocess.call(["reg","unload","HKLM" + opus.reg.sep + opus.reg.path])
if rtn > 0: raise Exception("reg")
opus.reg.unmount = _regUnmount
def _regMount(i):
try:
opus.reg.unmount()
except:
opus.main.output("unmount failed, probably already unmounted",2)
opus.main.output("registry > mount > " +i,2)
rtn = subprocess.call(["reg","load","HKLM" + opus.reg.sep + opus.reg.path,i])
if rtn > 0: raise Exception("reg")
opus.reg.mount = _regMount
def _regImport(rp):
opus.main.output("registry > import > " +rp,2)
rtn = subprocess.call(["reg","import",rp])
if rtn > 0: raise Exception("reg")
opus.reg.imprt = _regImport
def _getValue(kp,v):
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,kp) as key:
return winreg.QueryValueEx(key,v)
opus.reg.getValue = _getValue
def _getKey(kp):
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,kp) as key:
rtn = Munch()
index = 0
length = winreg.QueryInfoKey(key)[1]
while index < length:
valueInfo = winreg.EnumValue(key,index)
rtn[valueInfo[0]] = Munch()
rtn[valueInfo[0]].value = valueInfo[1]
rtn[valueInfo[0]].type = valueInfo[2]
index = index + 1
return rtn
opus.reg.getKey = _getKey
def _setValue(kp,key,vt,value):
print("owo")

1
scripts/api/tweak.py Normal file
View File

@ -0,0 +1 @@
opus.tweak = Munch()

42
scripts/api/wim.py Normal file
View File

@ -0,0 +1,42 @@
global subprocess
import subprocess
global shutil
import shutil
opus.wim = Munch()
opus.wim.index = 0
opus.wim.location = ""
def _wimPath(p = ""):
if p == "": return pJoin(opus.path.wim,str(opus.wim.index))
return pJoin(opus.path.wim,str(opus.wim.index),p)
opus.wim.path = _wimPath
def _wimExtractFiles(filePaths):
fileList = []
for filePath in filePaths:
fileList.append("-i!" +pJoin(str(opus.wim.index),filePath))
opus.main.output("extracting " +str(len(filePaths))+ " files from " +opus.wim.location+ "...")
rtn = subprocess.call(
["7z","x",opus.wim.location, #wim path
"-o" +opus.path.wim, #out path
"NONE"] #in path
+fileList+ #files
["-aos","-bso0","-bsp1","-bb1"]
)
if rtn > 0: raise Exception("wim")
opus.wim.extractFiles = _wimExtractFiles
def _wimReadyFile(inPath,outPath):
if os.path.isfile(opus.wim.path(outPath)): os.remove(opus.wim.path(outPath))
shutil.copyfile(inPath,opus.wim.path(outPath))
opus.wim.readyFile = _wimReadyFile
def _wimUpdate():
opus.main.output("adding changed files to wim...")
rtn = subprocess.call(
["wimlib-imagex","update",opus.wim.location,str(opus.wim.index),
"--command=add '" +opus.wim.path("")+ "' '\\'"]
)
opus.wim.update = _wimUpdate

View File

@ -1 +1 @@
opus.output("welcome to " +opus.version.string+ "!\n")
opus.main.output("welcome to " +opus.version.string+ "!")

View File

@ -1,4 +1,6 @@
import sys
import os
import shutil
pJoin = os.path.join
@ -18,18 +20,97 @@ opus.version.string = \
opus.path = Munch()
opus.path.main = os.path.dirname(os.path.realpath(__file__))
opus.path.api = pJoin(opus.path.main,"scripts","api")
opus.path.tweaks = pJoin(opus.path.main,"scripts","tweaks")
opus.path.tweaks = pJoin(opus.path.main,"tweaks")
opus.path.temp = pJoin(opus.path.main,"tmp")
opus.path.wim = pJoin(opus.path.temp,"wim")
opus.path.target = sys.argv[1]
opus.verbosity = 1
opus.verbosity = 2
with open(pJoin(opus.path.main,"scripts","api","main.py")) as script:
exec(script.read())
if opus.verbosity > 0:
opus.output("-- paths --")
for path in opus.path:
opus.output(path + ": " +opus.path[path])
opus.output("")
opus.main.output("\nmain-api loaded!",1)
opus.script.execute(pJoin(opus.path.main,"scripts","hello.py"))
opus.main.output("",1)
opus.execPy(pJoin(opus.path.main,"scripts","hello.py"))
if opus.verbosity > 0:
opus.main.output("-- paths --")
for path in opus.path:
opus.main.output(path + ": " +opus.path[path])
opus.main.output("")
opus.main.output("-- loading misc APIs --", 1)
opus.script.execute(pJoin(opus.path.api,"path.py"))
opus.script.execute(pJoin(opus.path.api,"wim.py"))
opus.script.execute(pJoin(opus.path.api,"registry.py"))
opus.script.execute(pJoin(opus.path.api,"detection.py"))
opus.script.execute(pJoin(opus.path.api,"tweak.py"))
opus.main.output("",1)
opus.script.execute(pJoin(opus.path.main,"scripts","path.py"))
opus.main.output("",1)
if os.path.isdir(opus.path.temp):
opus.main.output("clearing temp directory...",1)
try:
opus.reg.unmount()
except:
pass
shutil.rmtree(opus.path.temp)
os.makedirs(opus.path.temp)
opus.wim.location = pJoin(opus.path.target,"sources","install.wim")
opus.wim.index = int(input("\nwim index: "))
opus.main.output("",1)
opus.wim.extractFiles([
pJoin("Windows","System32","config","SOFTWARE"),
pJoin("Windows","System32","config","SYSTEM"),
pJoin("Users","Default","NTUSER.DAT")
])
opus.main.output("",1)
opus.os = opus.detect.os(opus.wim.path())
for tag in opus.os.tags:
if not os.path.isdir(pJoin(opus.path.tweaks,tag)): continue
rtgName = "SOFTWARE"
rtgFile = pJoin("Windows","System32","config","SOFTWARE")
opus.main.output("\n>> [" +tag+ "] applying tweaks: registry -> " +rtgName, 1)
opus.reg.mount(opus.wim.path(rtgFile))
for tweakRoot,tweaks,_ in opus.path.walklevel(pJoin(opus.path.tweaks,tag)):
for tweak in tweaks:
ftweak = os.path.join(tweakRoot,tweak)
if not os.path.isfile(pJoin(ftweak,"reg",rtgName + ".REG")): continue
opus.reg.imprt(pJoin(ftweak,"reg",rtgName + ".REG"))
rtgName = "SYSTEM"
rtgFile = pJoin("Windows","System32","config","SYSTEM")
opus.main.output("\n>> [" +tag+ "] applying tweaks: registry -> " +rtgName, 1)
opus.reg.mount(opus.wim.path(rtgFile))
for tweakRoot,tweaks,_ in opus.path.walklevel(pJoin(opus.path.tweaks,tag)):
for tweak in tweaks:
ftweak = os.path.join(tweakRoot,tweak)
if not os.path.isfile(pJoin(ftweak,"reg",rtgName + ".REG")): continue
opus.reg.imprt(pJoin(ftweak,"reg",rtgName + ".REG"))
rtgName = "NTUSER"
rtgFile = pJoin("Users","Default","NTUSER.DAT")
opus.main.output("\n>> [" +tag+ "] applying tweaks: registry -> " +rtgName, 1)
opus.reg.mount(opus.wim.path(rtgFile))
for tweakRoot,tweaks,_ in opus.path.walklevel(pJoin(opus.path.tweaks,tag)):
for tweak in tweaks:
ftweak = os.path.join(tweakRoot,tweak)
if not os.path.isfile(pJoin(ftweak,"reg",rtgName + ".REG")): continue
opus.reg.imprt(pJoin(ftweak,"reg",rtgName + ".REG"))
opus.main.output("\nif you'd like to make manual changes, please do so now. press enter to finalize or ctrl+c to cancel.")
input()
opus.reg.unmount()
opus.wim.update()

7
scripts/path.py Normal file
View File

@ -0,0 +1,7 @@
global os
import os
opus.main.output("expanding path...",1)
for root,dirs,files in opus.path.walklevel(pJoin(opus.path.main,"bin")):
for dir in dirs:
opus.main.output("adding: " +dir,1)
os.environ["Path"] = os.environ["Path"] + ";" + pJoin(root,dir)

View File

@ -0,0 +1,5 @@
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\OPUS_TMP\ControlSet001\Control\Session Manager\Power]
"HibernateEnabled"=dword:00000000

View File

@ -0,0 +1,11 @@
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\OPUS_TMP\ControlSet001\Control\Power\User\PowerSchemes\381b4222-f694-41f0-9685-ff5bb260df2e\e73a048d-bf27-4f12-9731-8b2076e8891f\637ea02f-bbcb-4015-8e2c-a1c7b9c0b546]
"ACSettingIndex"=dword:00000000
[HKEY_LOCAL_MACHINE\OPUS_TMP\ControlSet001\Control\Power\User\PowerSchemes\8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c\e73a048d-bf27-4f12-9731-8b2076e8891f\637ea02f-bbcb-4015-8e2c-a1c7b9c0b546]
"ACSettingIndex"=dword:00000000
[HKEY_LOCAL_MACHINE\OPUS_TMP\ControlSet001\Control\Power\User\PowerSchemes\a1841308-3541-4fab-bc81-f71556f20b4a\e73a048d-bf27-4f12-9731-8b2076e8891f\637ea02f-bbcb-4015-8e2c-a1c7b9c0b546]
"ACSettingIndex"=dword:00000000

View File

@ -0,0 +1,5 @@
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\OPUS_TMP\ControlSet001\Services\SysMain]
"Start"=dword:00000004

View File

@ -0,0 +1,5 @@
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\OPUS_TMP\ControlSet001\Services\WSearch]
"Start"=dword:00000004

View File

@ -0,0 +1,5 @@
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\OPUS_TMP\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced]
"HideFileExt"=dword:00000000

View File

@ -0,0 +1,5 @@
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\OPUS_TMP\Microsoft\Windows\CurrentVersion\RunOnce]
"opus-nt-setupcomplete"="cmd /c call \"C:\\opus-nt-setupcomplete\\setupcomplete.bat\""

View File

@ -0,0 +1,14 @@
@echo off
setlocal EnableDelayedExpansion
cd /d %~dp0
set outputFile=%SystemDrive%\opus-nt-setupcomplete.log
for %%i in (scripts\*) do (
echo - %%i - >> "%outputFile%"
call "%%i" 1>> "%outputFile%" 2>>&1
echo. >> "%outputFile%"
)
start notepad.exe "%outputFile%"
cd /d %SystemDrive%\
rmdir /s /q "%~dp0"

View File

@ -0,0 +1,8 @@
Windows Registry Editor Version 5.00
; this sets the update channel to semi-annual, and additionally defers the updates for half a year
[HKEY_LOCAL_MACHINE\OPUS_TMP\Microsoft\WindowsUpdate\UX\Settings]
"BranchReadinessLevel"=dword:00000020
"DeferFeatureUpdates"=dword:00000001
"DeferFeatureUpdatesPeriodInDays"=dword:000000b7

View File

@ -0,0 +1,8 @@
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\OPUS_TMP\Policies\Microsoft\Windows\System]
"AllowCrossDeviceClipboard"=dword:00000000
"EnableActivityFeed"=dword:00000000
"PublishUserActivities"=dword:00000000
"UploadUserActivities"=dword:00000000

View File

@ -0,0 +1,11 @@
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\OPUS_TMP\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced]
"ShowSyncProviderNotifications"=dword:00000000 ; no explorer "suggestions"
[HKEY_LOCAL_MACHINE\OPUS_TMP\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager]
"SystemPaneSuggestionsEnabled"=dword:00000000 ; no start menu "suggestions"
"SoftLandingEnabled"=dword:00000000 ; no "tips", "tricks" and "suggestions"
"SubscribedContent-338393Enabled"=dword:00000000 ; no settings "suggestions"
"SilentInstalledAppsEnabled"=dword:00000000 ; no automatic advert app downloads

View File

@ -0,0 +1,5 @@
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\OPUS_TMP\Microsoft\Windows\CurrentVersion\Policies\System]
"DisableAutomaticRestartSignOn"=dword:00000001

View File

@ -0,0 +1,5 @@
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\OPUS_TMP\Policies\Microsoft\Windows\Windows Search]
"AllowCortana"=dword:00000000

View File

@ -0,0 +1,5 @@
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\OPUS_TMP\Microsoft\Windows\CurrentVersion\DeliveryOptimization\Config]
"DODownloadMode"=dword:00000000

View File

@ -0,0 +1,6 @@
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\OPUS_TMP\Policies\Microsoft\Windows\WindowsUpdate]
"ExcludeWUDriversInQualityUpdate"=dword:00000001

View File

@ -0,0 +1,5 @@
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\OPUS_TMP\ControlSet001\Control\Session Manager\Power]
"HiberbootEnabled"=dword:00000000

View File

@ -0,0 +1,6 @@
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\OPUS_TMP\Policies\Microsoft\Windows\Personalization]
"NoLockScreen"=dword:00000001

View File

@ -0,0 +1,5 @@
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\OPUS_TMP\ControlSet001\Control\Memory Management]
"SwapfileControl"=dword:00000000

View File

@ -0,0 +1,5 @@
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\OPUS_TMP\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
"OneDriveSetup"=""

View File

@ -0,0 +1,9 @@
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\OPUS_TMP\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer] ; disables recent/frequent items in the explorer (quick access for example), taskbar context menus, etc...
"ShowRecent"=dword:00000000
"ShowFrequent"=dword:00000000
[HKEY_LOCAL_MACHINE\OPUS_TMP\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced] ; [windows 7 and older] disables recently opened documents in the start menu
"Start_TrackDocs"=dword:00000000

View File

@ -0,0 +1,5 @@
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\OPUS_TMP\Policies\Microsoft\Windows\DataCollection]
"AllowTelemetry"=dword:00000000

View File

@ -0,0 +1,8 @@
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\OPUS_TMP\Microsoft\Windows Defender\Features]
"TamperProtection"=dword:00000000
[HKEY_LOCAL_MACHINE\OPUS_TMP\Policies\Microsoft\Windows Defender]
"DisableAntiSpyware"=dword:00000001

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
<settings pass="windowsPE">
<component name="Microsoft-Windows-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
</component>
</settings>
<settings pass="oobeSystem">
<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<OOBE>
<HideEULAPage>true</HideEULAPage>
<HideOnlineAccountScreens>true</HideOnlineAccountScreens>
<HideOEMRegistrationScreen>true</HideOEMRegistrationScreen>
<ProtectYourPC>3</ProtectYourPC>
<HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE>
</OOBE>
</component>
</settings>
</unattend>