Script compatible all languages, ModifyConf ps1

master
c.soylu 11 months ago
parent 6351af0385
commit 86628469a2
Signed by: c.soylu
GPG Key ID: 5C6DD95082155A23
  1. 0
      localscripts/00ActivateDHCP.py
  2. 31
      localscripts/01ActivateAdministrator.py
  3. 0
      localscripts/99EjectDrive.py
  4. 16
      powershell/FixUserService.ps1
  5. 17
      powershell/ModifyConf.ps1

@ -1,4 +1,4 @@
import os,json,sys,subprocess
import os,json,sys,subprocess,configparser,platform
def find_drive(file_path):
for number in range(65,91):
@ -32,19 +32,40 @@ def enable_administrator_account():
print("\n Administrator account is activated by localscript")
return run.stdout
def is_os_64bit():
return platform.machine().endswith('64')
def get_data(variable,path):
configParser = configparser.RawConfigParser()
configParser.read(path)
data = configParser.get('DEFAULT',variable)
return data
# variables
meta_data_path = find_drive(":\OPENSTACK\LATEST\META_DATA.json")
admin_name = get_administrator_name()
# execute
if meta_data_path != "False":
if (meta_data_path) and ("admin_username" in load_json_file(meta_data_path,"meta")):
meta_data = load_json_file(meta_data_path,"meta")
meta_username = meta_data["admin_username"]
print("Meta_Data admin_username is :" + meta_username)
else:
sys.exit(0)
if is_os_64bit():
conf_path = r'C:\Program Files\Cloudbase Solutions\Cloudbase-Init\conf\cloudbase-init.conf'
print("System architecture is 64 bit.")
if meta_data["admin_username"] in admin_name and "False" in get_administrator_status():
else:
conf_path = r'C:\Program Files (x86)\Cloudbase Solutions\Cloudbase-Init\conf\cloudbase-init.conf'
print("System architecture is 32 bit.")
meta_username = get_data('username', conf_path)
print("Conf username:"+meta_username)
if meta_username in admin_name and "False" in get_administrator_status():
run = enable_administrator_account()
sys.exit(1001)
else:
print("Cloud-init user is not Administrateur/Administrator or Admin account is already enabled, script aborted.")
sys.exit(0)
sys.exit(0)

@ -1,7 +1,21 @@
# Install OpenSSH Server from Windows' optional features
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Serv*' | Select-Object -ExpandProperty Name | %{Add-WindowsCapability -Online -Name $_}
Set-Service -Name sshd -StartupType 'Automatic'
# Delete cloudbase-init User
net user cloudbase-init /delete
# Attribute service to local system
sc.exe config cloudbase-init obj= .\LocalSystem
# Modify executon path of Service
$newtext = Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\cloudbase-init' -Name 'ImagePath' | Select-Object -ExpandProperty ImagePath | %{$_.replace(" cloudbase-init ", " NT-AUTHORITY\SYSTEM ")}
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\cloudbase-init' -Name 'ImagePath' -Value $newtext
Get-AppxPackage | Where-Object {$_.name -Like "*Language*"} | Remove-AppxPackage
# Remove a microsoft store language package that causes generelazing issues
Get-AppxPackage | Where-Object {$_.name -Like "*Language*"} | Remove-AppxPackage

@ -0,0 +1,17 @@
# Replace in conf file Administrator username and group by the system's local language
$adminname = 'username=' + (Get-WmiObject win32_useraccount | Where-Object{$_.SID -like "S-1-5-*-500"}).Name
$admingroupname = 'groups=' + (Get-WmiObject win32_group | Where-Object{$_.SID -like "S-1-5-32-544"}).Name
if ((gwmi win32_operatingsystem | select osarchitecture).osarchitecture.Contains('64'))
{
$fileNames = Get-ChildItem "C:\Program Files\Cloudbase Solutions\Cloudbase-Init\conf" -Recurse | select -expand fullname
foreach ($filename in $filenames) { (Get-Content $fileName) -replace 'username=Administrator', $adminname | Set-Content $fileName }
foreach ($filename in $filenames) { (Get-Content $fileName) -replace 'groups=Administrators', $admingroupname | Set-Content $fileName }
}
elseif ((gwmi win32_operatingsystem | select osarchitecture).osarchitecture.Contains('32'))
{
$fileNames = Get-ChildItem "C:\Program Files (x86)\Cloudbase Solutions\Cloudbase-Init\conf" -Recurse | select -expand fullname
foreach ($filename in $filenames) { (Get-Content $fileName) -replace 'username=Administrator', $adminname | Set-Content $fileName }
foreach ($filename in $filenames) { (Get-Content $fileName) -replace 'groups=Administrators', $admingroupname | Set-Content $fileName }
}
Loading…
Cancel
Save