Automatische Installation: Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
 
Zeile 175: Zeile 175:
 
                 PATH = str(line).split("=")[-1].strip()
 
                 PATH = str(line).split("=")[-1].strip()
 
                 PATH = PATH + "/QEMU/"
 
                 PATH = PATH + "/QEMU/"
 +
                break
 +
    return PATH
 +
 +
def get_gns3_symbol_path():
 +
    conf = glob.glob("/home/**/.config/GNS3/**/gns3_server.conf",recursive=True)
 +
    conf = "".join(conf)
 +
    with open(str(conf)) as server_conf:
 +
        for line in server_conf.readlines():
 +
            if str(line).startswith("symbols"):
 +
                PATH = str(line).split("=")[-1].strip()
 
                 break
 
                 break
 
     return PATH
 
     return PATH

Aktuelle Version vom 26. Oktober 2021, 14:13 Uhr

Nutzung

  • Scripte in einen Ordner ablegen
  • Run.sh Script ausführen
  • Installation durchführen
  • Qemu schließen und warten

Run.sh

#!/bin/bash




Basepath=$PWD
GNS3_IMAGE_PATH=$(python3 $Basepath/get_gns3_path.py 2>&1)                                                                                                                    


function donwload () {
    if [ -f "$GNS3_IMAGE_PATH/OVMF_CODE.fd" ]; then
        echo "Die Datei OVMF_CODE.fd existiert bereits"
    else
        wget -O $GNS3_IMAGE_PATH/OVMF_CODE.fd https://raw.githubusercontent.com/kholia/OSX-KVM/master/OVMF_CODE.fd 
    fi
    if [ -f "$GNS3_IMAGE_PATH/OpenCore.qcow2" ]; then
        echo "Die Datei OVMF_CODE.fd existiert bereits"
    else
        wget -O $GNS3_IMAGE_PATH/OpenCore.qcow2 https://raw.githubusercontent.com/kholia/OSX-KVM/master/OpenCore/OpenCore.qcow2
    fi
    if [ -d "$Basepath/OSX-KVM" ]; then
        echo "Der Ordner OSX-KVM existiert bereits"
    else
        git clone https://github.com/kholia/OSX-KVM.git
    fi
    
}

function prepare () {
    cd OSX-KVM

    if [ -f "BaseSystem.dmg" ]; then
        
        echo "Die Datei \"BaseSystem.dmg\" exisitiert schon"
        
        else
        python3 fetch-macOS-v2.py

    fi
    if [ -f "BaseSystem.img" ]; then
        
        echo "Die Datei \"BaseSystem.img\" exisitiert schon"
    else
        qemu-img convert BaseSystem.dmg -O raw BaseSystem.img
        
    fi

    qemu-img create -f qcow2 mac_hdd_ng.img 128G
}


function get_checksum () {
    for Name in $1 $2 $3
        do
        echo $GNS3_IMAGE_PATH$Name
            if [ -f "$GNS3_IMAGE_PATH$Name" ]; then
                Name=${Name##*/}
                md5sum=$(md5sum $GNS3_IMAGE_PATH$Name)
                echo $Name
                if [ $Name == $1 ]; then
                    OVMF_CODE=("$Name $md5sum")
                fi
                if [ $Name == $2 ]; then
                    OpenCore=("$Name $md5sum")
                fi
                if [ $Name == $3 ]; then
                    MacOS=("$Name $md5sum")
                fi
                echo $NameChecksum

            fi
            
            
    done
}



sudo apt-get install qemu uml-utilities virt-manager git \
    wget libguestfs-tools p7zip-full make -y

sudo usermod -aG kvm $(whoami)
donwload
prepare
./OpenCore-Boot.sh

mv mac_hdd_ng.img MacOS.img
mv -v  MacOS.img $GNS3_IMAGE_PATH
sleep 30
if [ -f "$GNS3_IMAGE_PATH/MacOS.img" ]; then
    get_checksum OVMF_CODE.fd OpenCore.qcow2 MacOS.img
fi
 

echo "$OVMF_CODE" 
echo "$OpenCore" 
echo "$MacOS"

python3 $Basepath/replace_arguments.py ["$OVMF_CODE", "$OpenCore", "$MacOS"]
sleep 5
cd ..
gns3 Macosx.gns3a

Replace-Arguments

import json
import get_gns3_path
import os, sys





def replace_PATH():
        with open(f"{os.path.dirname(os.path.abspath(__file__))}/Macosx-GNS3.json") as file:
                config = json.load(file)
                print(config["qemu"]["options"])
                config["qemu"].update(options=str(config["qemu"]["options"]).replace('$PATH',get_gns3_path.get_gns3_image_path()))



                with open(os.path.dirname(os.path.abspath(__file__)) + "/Macosx" + ".gns3a", 'w') as f:
                        json.dump(config,f, indent=4)

def replace_icon():
        with open(f"{os.path.dirname(os.path.abspath(__file__))}/Macosx-GNS3.json") as file:
                config = json.load(file)
                os.popen(f"wget -O {get_gns3_path.get_gns3_symbol_path()}/apple.svg https://raw.githubusercontent.com/simple-icons/simple-icons/develop/icons/apple.svg" )
                config["symbol"] = f"{get_gns3_path.get_gns3_symbol_path()}/apple.svg"

                with open(os.path.dirname(os.path.abspath(__file__)) + "/Macosx-GNS3.json", 'w') as f:
                        json.dump(config,f, indent=4)

def replace_md5sum(argv):
        with open(f"{os.path.dirname(os.path.abspath(__file__))}/Macosx.json") as file:
                config = json.load(file)
                
                for index,useless in enumerate(config["images"]):
                        for file in argv:
                                try:
                                        file = file.replace("[","")
                                except:
                                        pass
                                if file.split(" ")[0] in str(config["images"][index]["filename"]):
                                        config["images"][index].update({"md5sum":file.split(" ")[1]})

                with open(os.path.dirname(os.path.abspath(__file__)) + "/Macosx-GNS3" + ".json", 'w') as f:
                        json.dump(config,f, indent=4)

if __name__ == "__main__":
        replace_md5sum(sys.argv)
        replace_icon()
        replace_PATH()

Get-GNS3-Path

import glob

def get_gns3_image_path():
    conf = glob.glob("/home/**/.config/GNS3/**/gns3_server.conf",recursive=True)
    conf = "".join(conf)
    with open(str(conf)) as server_conf:
        for line in server_conf.readlines():
            if str(line).startswith("images_path"):
                PATH = str(line).split("=")[-1].strip()
                PATH = PATH + "/QEMU/"
                break
    return PATH

def get_gns3_symbol_path():
    conf = glob.glob("/home/**/.config/GNS3/**/gns3_server.conf",recursive=True)
    conf = "".join(conf)
    with open(str(conf)) as server_conf:
        for line in server_conf.readlines():
            if str(line).startswith("symbols"):
                PATH = str(line).split("=")[-1].strip()
                break
    return PATH


if __name__ == "__main__":
    print(get_gns3_image_path())

Mac OSX Standart Json

{
    "appliance_id": "02235367-3e98-4b36-99d5-ca66918570d0",
    "name": "macOS",
    "category": "guest",
    "description": "macOS",
    "vendor_name": "Apple",
    "vendor_url": "https://www.apple.com/mac/",
    "documentation_url": "https://xinux.net/index.php/Big_Sur#Configure_template",
    "product_name": "macOS",
    "product_url": "https://www.apple.com/mac/",
    "registry_version": 5,
    "status": "experimental",
    "availability": "service-contract",
    "maintainer": "mario",
    "maintainer_email": "mario.zimmermann@xinux.de",
    "usage": "***",
    "symbol": "$SYMBOL",
    "first_port_name": "a",
    "qemu": {
        "adapter_type": "vmxnet3",
        "adapters": 1,
        "ram": 4096,
        "cpus": 4,
        "hdb_disk_interface": "sata",
        "arch": "x86_64",
        "console_type": "vnc",
        "boot_priority": "dc",
        "kvm": "require",
        "options": "-machine accel=kvm -m \"4092\" -cpu Penryn,kvm=on,vendor=GenuineIntel,+invtsc,vmware-cpuid-freq=on,\"+ssse3,+sse4.2,+popcnt,+avx,+aes,+xsave,+xsaveopt,check\" -machine q35 -usb -device usb-kbd -device usb-tablet -smp \"4\",cores=\"4\",sockets=\"1\" -device usb-ehci,id=ehci -device isa-applesmc,osk=\"ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc\" -drive if=pflash,format=raw,readonly,file=\"$PATHOVMF_CODE.fd\" -smbios type=2 -device ich9-intel-hda -device hda-duplex -device ich9-ahci,id=sata -drive id=OpenCoreBoot,if=none,snapshot=on,format=qcow2,file=\"$PATHOpenCore.qcow2\" -device ide-hd,bus=sata.2,drive=OpenCoreBoot  -netdev user,id=net0 -device vmxnet3,netdev=net0,id=net0,mac=52:54:00:c9:18:27 -monitor stdio -device VGA,vgamem_mb=128"
    },
    "images": [
        {
            "filename": "MacOS.img",
            "version": "MacOS",
            "md5sum": "MD5SUM",
            "filesize": 2966534800,
            "download_url": "https://app.xinux.org/nextcloud/s/GdBLbS2FdLM7Jfw"
        },
        {
            "filename": "OVMF_CODE.fd",
            "version": "MacOS",
            "md5sum": "MD5SUM",
            "filesize": 1920000,
            "download_url": "https://raw.githubusercontent.com/kholia/OSX-KVM/master/OVMF_CODE.fd"
        },
        {
            "filename": "OpenCore.qcow2",
            "version": "MacOS",
            "md5sum": "MD5SUM",
            "filesize": 402653184,
            "download_url": "https://raw.githubusercontent.com/kholia/OSX-KVM/master/OpenCore/OpenCore.qcow2"
        }
        ],
        "versions": [
        
        {
            "name": "MacOS",
            "images": {
                "bios_image": "OVMF_CODE.fd",
                "hdb_disk_image": "MacOS.img",
                "hdc_disk_image": "OpenCore.qcow2"
            }
        }
    ]
}