Commit 70bde0a5 authored by Petar Kulić's avatar Petar Kulić
Browse files

Nadogradnja QemuStarterSetupa

Izmjena setupa (nudi instalaciju, nadogradnju, odinstalaciju ili izlaz)
Sve exit naredbe imaju vrijednost 1 ili 0
Preimenovana funkcija RAM_SIZE_AND_CPU_CORES u CHIPSET_SOUND_CPU_RAM
Postavljanje chipseta na defaultnu vrijednost "pc" (dodan je izbor ali i zakomentiran, u planu je dodavanje izbora čim riješim problem s mrežom)
Postavljanje automatski detektiranog broja threadova po jezgri CPU-a
Bolja detekcija CPU-a
Popravljen problem sa single-core CPU-om
Uklonjen nepotreban if uvjet kod odabira zvučne kartice
Klik na 'Otkaži' kod odabira zvučne kartice sada gasi skriptu
Širi početni dialog (poklapa se veličinom s dialoga na odabiru zvučne kartice (i Chipseta u skoroj budućnosti, nadam se))
parent b3c79f0d
......@@ -7,31 +7,41 @@
. ~/.config/user-dirs.dirs
if [ -f ~/.local/QemuStarter ]; then # Uklanjanje stare skripte
zenity --question --width 300 --title "QEMU Starter Setup $Version" --text "Želite li odinstalirati Qemu Starter skriptu?"
if [ $? = 0 ]; then
rm -f ~/.local/QemuStarter
rm -f "$XDG_DESKTOP_DIR"/QemuStarter.desktop
rm -f "$HOME/Qemu Starter"
zenity --info --width 300 --title "QEMU Starter Setup $Version" --text "Qemu Starter skripta je odinstalirana!" --timeout 2
zenity --question --width 300 --title "QEMU Starter Setup $Version" --text "Već imate instaliranu QEMU Starter skriptu.\n\nŠto želite napraviti?" --cancel-label "Nešto drugo..." --ok-label "Nadogradi QS"
if [ $? = 1 ]; then
zenity --question --width 300 --title "QEMU Starter Setup $Version" --text "Što želite napraviti?" --cancel-label "Izađi" --ok-label "Odinstaliraj QS"
if [ $? = 0 ]; then
rm -f ~/.local/QemuStarter
rm -f "$XDG_DESKTOP_DIR"/QemuStarter.desktop
rm -f "$HOME/Qemu Starter"
zenity --info --width 300 --title "QEMU Starter Setup $Version" --text "Qemu Starter skripta je odinstalirana!" --timeout 2
exit 0
else
exit 1
fi
fi
exit
elif [ -f ~/.local/QemuStarter/QemuStarter ]; then # Uklanjanje nove skripte
zenity --question --width 300 --title "QEMU Starter Setup $Version" --text "Želite li odinstalirati Qemu Starter skriptu?"
if [ $? = 0 ]; then
rm -f "$XDG_DESKTOP_DIR"/QemuStarter.desktop
rm -f "$HOME/Qemu Starter"
rm -rf ~/.local/QemuStarter/
zenity --info --width 300 --title "QEMU Starter Setup $Version" --text "Qemu Starter skripta je odinstalirana!" --timeout 2
zenity --question --width 300 --title "QEMU Starter Setup $Version" --text "Već imate instaliranu QEMU Starter skriptu.\n\nŠto želite napraviti?" --cancel-label "Nešto drugo..." --ok-label "Nadogradi QS"
if [ $? = 1 ]; then
zenity --question --width 300 --title "QEMU Starter Setup $Version" --text "Što želite napraviti?" --cancel-label "Izađi" --ok-label "Odinstaliraj QS"
if [ $? = 0 ]; then
rm -f "$XDG_DESKTOP_DIR"/QemuStarter.desktop
rm -f "$HOME/Qemu Starter"
rm -rf ~/.local/QemuStarter/
zenity --info --width 300 --title "QEMU Starter Setup $Version" --text "Qemu Starter skripta je odinstalirana!" --timeout 2
exit 0
else
exit 1
fi
fi
exit
else
zenity --question --width 300 --title "QEMU Starter Setup $Version" --text "Prije instalacije ove skripte, provjerite imate li instaliran qemu paket.\n\nŽelite li instalirati Qemu Starter skriptu?"
if [ $? != 0 ]; then
exit
exit 1
fi
fi
Version="v1.6"
Version="v1.7"
if ! [ -d ~/.local/QemuStarter ]; then
mkdir ~/.local/QemuStarter
fi
......@@ -47,7 +57,7 @@ QEMUvirtualMachine=\"\${QEMUvirtualMachine//i?86/i386}\" # Fix za i486, i586 i i
which \$QEMUvirtualMachine
if [ \$? != 0 ]; then
zenity --error --width 300 --title \"\$ScriptName\" --text \"Prvo instalirajte qemu paket kako bi mogli koristiti ovu skriptu!\"
exit
exit 1
fi
# Import user dirs
......@@ -60,15 +70,15 @@ function CREATE_HDD {
# Ne dopusti da se disk zapuni, miminum je 5 GiB free
if [ \"\$MAXstorage\" -lt 5 ]; then
zenity --error --width 300 --title \"\$ScriptName\" --text \"Preostalo vam je manje od 5 GiB slobodnog prostora na disku.\\\nNe možete nastaviti dalje s radom. Žao mi je :(\"
exit
exit 1
fi
HDDsize=\`zenity --scale --title \"\$ScriptName - Odaberi veličinu virtualog diska\" --text \"Veličina virtualnog HDD-a kojeg želite stvoriti (u GiB):\\\t\\\t\\\t\\\t\" --min-value 1 --max-value \$MAXstorage --value \$(( MAXstorage / 2 )) --step 1\`
if [ \$? != 0 ]; then
exit
exit 1
fi
SaveHDD=\`zenity --title \"\$ScriptName - Spremi datoteku virtualnog diska (.qvd)\" --file-selection --save --file-filter 'QEMU virtualni disk | *.[Qq][Vv][Dd]'\`
if [ \$? != 0 ]; then
exit
exit 1
fi
qemu-img create -f raw \"\$SaveHDD.qvd\" \${HDDsize}G
SelectHDD=\"\$SaveHDD.qvd\" # Bitno za eventualnu instalaciju
......@@ -80,67 +90,83 @@ function CREATE_HDD {
function SELECT_HDD {
SelectHDD=\`zenity --title \"\$ScriptName - Odaberi virtualni HDD\" --file-selection --file-filter 'Svi podržani virtualni diskovi (*.cow, *.img, *.vdi, *.vhd, *.qcow, *.qcow2, *.qed, *.qvd) | *.[Cc][Oo][Ww] *.[Ii][Mm][Gg] *.[Vv][Dd][Ii] *.[Vv][Hh][Dd] *.[Qq][Cc][Oo][Ww] *.[Qq][Cc][Oo][Ww]2 *.[Qq][Ee][Dd] *.[Qq][Vv][Dd]' --file-filter 'QEMU virtualni diskovi (*.cow, *.qcow, *.qcow2, *.qed, *.qvd) | *.[Cc][Oo][Ww] *.[Qq][Cc][Oo][Ww] *.[Qq][Cc][Oo][Ww]2 *.[Qq][Ee][Dd] *.[Qq][Vv][Dd]' --file-filter 'Ostali virtualni diskovi (*.img, *.vdi, *.vhd) | *.[Ii][Mm][Gg] *.[Vv][Dd][Ii] *.[Vv][Hh][Dd]'\`
if [ \$? != 0 ]; then
exit
exit 1
fi
}
function SELECT_ISO {
SelectISO=\`zenity --title \"\$ScriptName - Odaberi .iso datoteku\" --file-selection --file-filter 'ISO | *.[Ii][Ss][Oo]'\`
if [ \$? != 0 ]; then
exit
exit 1
fi
}
function RAM_SIZE_AND_CPU_CORES {
function CHIPSET_SOUND_CPU_RAM {
if [ -f \"\${SelectHDD%.*}\".cfg ]; then # Postoji .cfg datoteka
. \"\${SelectHDD%.*}\".cfg # Učitaj postavke iz .cfg datoteke
if [ \"\$Chipset\" = \"\" ]; then
Chipset=\"pc\" # Default
sed -i \"s/Chipset=\\\"\\\"/Chipset=\\\"\$Chipset\\\"/\" \"\${SelectHDD%.*}\".cfg # Popuni praznu varijablu u .cfg datoteci defaultnom vrijednosti
fi
if [ \"\$SoundDevice\" = \"\" ]; then
SoundDevice=\"hda\" # Default za audio
sed -i \"s/SoundDevice=\\\"\\\"/SoundDevice=\\\"\$SoundDevice\\\"/\" \"\${SelectHDD%.*}\".cfg # Popuni praznu varijablu u .cfg datoteci defaultnom vrijednosti
fi
if [ \"\$ThreadsPerCore\" = \"\" ]; then
ThreadsPerCore=\`lscpu | grep -i \"thread(s)\" | awk '{print \$4}'\`
sed -i \"s/ThreadsPerCore=\\\"\\\"/ThreadsPerCore=\\\"\$ThreadsPerCore\\\"/\" \"\${SelectHDD%.*}\".cfg # Popuni praznu varijablu u .cfg datoteci detektiranom vrijednošću
fi
RUN_VM
exit
exit 0
else # Ne postoji .cfg datoteka
if [ \"\$SelectHDD\" = \"\" ]; then
SelectHDD=\"/dev/null\"
fi
if [ \"\$SoundDevice\" = \"\" ]; then # Odabir za audio-karticu
SoundDevice=\`zenity --list --radiolist --width 420 --height 300 --title \"\$ScriptName - Odaberi zvučnu karticu\" --text \"Odaberite emulaciju zvučne kartice\" --column \"?\" --column \"Kratka oznaka\" --column \"Vrsta kartice\" FALSE sb16 \"Creative Sound Blaster 16\" FALSE es1370 \"ENSONIQ AudioPCI ES1370\" FALSE ac97 \"Intel 82801AA AC97 Audio\" FALSE adlib \"Yamaha YM3812 (OPL2)\" FALSE gus \"Gravis Ultrasound GF1\" FALSE cs4231a \"CS4231A\" TRUE hda \"Intel HD Audio\" FALSE pcspk \"PC zvučnik\"\`
# Chipset=\`zenity --list --radiolist --width 420 --height 300 --title \"\$ScriptName - Odaberi chipset\" --text \"Odaberite emulaciju x86 chipseta\" --column \"?\" --column \"Kratka oznaka\" --column \"Vrsta chipseta\" FALSE Q35 \"Q35 + ICH9, 2009.\" TRUE PC \"i440FX + PIIX, 1996.\"\`
# if [ \$? != 0 ]; then
# exit 1
# else
# Chipset=\"\${Chipset,,}\"
# fi
Chipset=\"pc\" # Default, q35 radi puno sporije i ne radi mreža pa je zasad disablean odabir
SoundDevice=\`zenity --list --radiolist --width 420 --height 300 --title \"\$ScriptName - Odaberi zvučnu karticu\" --text \"Odaberite emulaciju zvučne kartice\" --column \"?\" --column \"Kratka oznaka\" --column \"Vrsta kartice\" FALSE sb16 \"Creative Sound Blaster 16\" FALSE es1370 \"ENSONIQ AudioPCI ES1370\" FALSE ac97 \"Intel 82801AA AC97 Audio\" FALSE adlib \"Yamaha YM3812 (OPL2)\" FALSE gus \"Gravis Ultrasound GF1\" FALSE cs4231a \"CS4231A\" TRUE hda \"Intel HD Audio\" FALSE pcspk \"PC zvučnik\"\`
if [ \$? != 0 ]; then
exit 1
fi
CPUcores=\`lscpu | grep -i \"core(s)\" | awk '{print \$4}'\`
if [ \$CPUcores -gt 1 ]; then # Fix za single-core CPU
CPUcores=\`zenity --scale --title \"\$ScriptName - Odaberi broj jezgri CPU-a\" --text \"Broj jezgri CPU-a za virtualnu mašinu:\\\t\\\t\\\t\\\t\\\t\\\t\\\t\\\t\" --min-value 1 --max-value \$CPUcores --value 1 --step 1\`
if [ \$? != 0 ]; then
SoundDevice=\"hda\" # Default za audio
exit 1
fi
fi
CPUcores=\`cat /proc/cpuinfo | grep cores | awk '{print \$4}' | tail -n 1\`
CPUcores=\`zenity --scale --title \"\$ScriptName - Odaberi broj jezgri CPU-a\" --text \"Broj jezgri CPU-a za virtualnu mašinu:\\\t\\\t\\\t\\\t\\\t\\\t\\\t\\\t\" --min-value 1 --max-value \$CPUcores --value 1 --step 1\`
if [ \$? != 0 ]; then
exit
fi
ThreadsPerCore=\`lscpu | grep -i \"thread(s)\" | awk '{print \$4}'\`
MAXmemory=\`cat /proc/meminfo | grep \"MemTotal\" | awk '{print \$2}'\`
MAXmemory=\"\$(( MAXmemory / 1024 / 2 ))\" # Maximalno dozvoli pola RAM-a
RAMsize=\`zenity --scale --title \"\$ScriptName - Odaberi količinu RAM-a\" --text \"Količina RAM-a za virtualnu mašinu (u MiB):\\\t\\\t\\\t\\\t\\\t\\\t\" --min-value 128 --max-value \$MAXmemory --value \$(( MAXmemory / 2 )) --step 1\`
if [ \$? != 0 ]; then
exit
exit 1
fi
if [ \"\$SelectHDD\" != \"/dev/null\" ]; then # Ako je \$SelectHDD /dev/null pokreće se ISO datoteka pa ne treba spremanje
zenity --question --width 300 --title \"\$ScriptName - Spremanje postavki\" --text \"Želite li spremiti odabrane postavke za ovaj virtualni disk?\" --cancel-label \"Ne spremaj\" --ok-label \"Spremi\"
if [ \$? = 0 ]; then
echo -e \"#########################\\\n# DO NOT EDIT THIS FILE #\\\n#########################\\\nBootDevice=\\\"c\\\"\\\nChipset=\\\"\\\"\\\nCPUcores=\\\"\$CPUcores\\\"\\\nQEMUvirtualMachine=\\\"\$QEMUvirtualMachine\\\"\\\nRAMsize=\\\"\$RAMsize\\\"\\\nSoundDevice=\\\"\$SoundDevice\\\"\\\nThreadsPerCore=\\\"\\\"\" > \"\${SelectHDD%.*}\".cfg
echo -e \"#########################\\\n# DO NOT EDIT THIS FILE #\\\n#########################\\\nBootDevice=\\\"c\\\"\\\nChipset=\\\"\$Chipset\\\"\\\nCPUcores=\\\"\$CPUcores\\\"\\\nQEMUvirtualMachine=\\\"\$QEMUvirtualMachine\\\"\\\nRAMsize=\\\"\$RAMsize\\\"\\\nSoundDevice=\\\"\$SoundDevice\\\"\\\nThreadsPerCore=\\\"\$ThreadsPerCore\\\"\" > \"\${SelectHDD%.*}\".cfg
fi
fi
fi
}
function RUN_VM {
\$QEMUvirtualMachine\$UseKVM -usbdevice tablet -hda \"\$SelectHDD\" -cdrom \"\$SelectISO\" -smp cores=\$CPUcores -soundhw \$SoundDevice -boot \$BootDevice -net nic -net user -m \$RAMsize -rtc base=localtime
\$QEMUvirtualMachine\$UseKVM -M \$Chipset -usbdevice tablet -hda \"\$SelectHDD\" -cdrom \"\$SelectISO\" -smp cores=\$CPUcores,threads=\$ThreadsPerCore -soundhw \$SoundDevice -boot \$BootDevice -net nic -net user -m \$RAMsize -rtc base=localtime
if [ \$? != 0 ]; then
zenity --error --width 300 --title \"\$ScriptName\" --text \"Greška pri pokretanju virtualke!\\\n\\\nIzlazna naredba:
\$QEMUvirtualMachine\$UseKVM -usbdevice tablet -hda \\\"\$SelectHDD\\\" -cdrom \\\"\$SelectISO\\\" -smp cores=\$CPUcores -soundhw \$SoundDevice -boot \$BootDevice -net nic -net user -m \$RAMsize -rtc base=localtime\"
zenity --error --width 300 --title \"\$ScriptName\" --text \"Greška pri pokretanju virtualke!\\\n\\\nIzlazna naredba:\\\n
\$QEMUvirtualMachine\$UseKVM -M \$Chipset -usbdevice tablet -hda \\\"\$SelectHDD\\\" -cdrom \\\"\$SelectISO\\\" -smp cores=\$CPUcores,threads=\$ThreadsPerCore -soundhw \$SoundDevice -boot \$BootDevice -net nic -net user -m \$RAMsize -rtc base=localtime\"
fi
exit
exit 1
}
function START {
QEMUjob=\`zenity --width 300 --height 300 --list --radiolist --title \"\$ScriptName\" --text \"Što želite napraviti s QEMU?\" \\
QEMUjob=\`zenity --width 420 --height 300 --list --radiolist --title \"\$ScriptName\" --text \"Što želite napraviti s QEMU?\" \\
--column \" ? \" --column \"Radnja za QEMU\" \$MkVirtHDD \"Stvori virtualni HDD\" \$RunVirtHDD \"Pokreni virtualni HDD\" \\
\$RunISO \"Pokreni ISO datoteku\" \$ImageInstall \"Instalacija pomoću ISO datoteke\"\`
......@@ -156,13 +182,13 @@ function START {
;;
Pok*ISO*)
SELECT_ISO
RAM_SIZE_AND_CPU_CORES
CHIPSET_SOUND_CPU_RAM
BootDevice=\"d\"
RUN_VM
;;
Pok*HDD)
SELECT_HDD
RAM_SIZE_AND_CPU_CORES
CHIPSET_SOUND_CPU_RAM
BootDevice=\"c\"
RUN_VM
;;
......@@ -176,7 +202,7 @@ function START {
SELECT_HDD
fi
fi
RAM_SIZE_AND_CPU_CORES
CHIPSET_SOUND_CPU_RAM
BootDevice=\"once=d\"
RUN_VM
;;
......@@ -203,13 +229,13 @@ if [ \"\$1\" != \"\" ]; then
case \"\$1\" in
*cow|*img|*vdi|*vhd|*qcow|*qcow2|*qed|*qvd)
SelectHDD=\"\$1\"
RAM_SIZE_AND_CPU_CORES
CHIPSET_SOUND_CPU_RAM
BootDevice=\"c\"
RUN_VM
;;
*iso)
SelectISO=\"\$1\"
RAM_SIZE_AND_CPU_CORES
CHIPSET_SOUND_CPU_RAM
BootDevice=\"d\"
RUN_VM
;;
......@@ -218,7 +244,7 @@ if [ \"\$1\" != \"\" ]; then
exit 1
;;
esac
exit
exit 0
fi
# Postavi varijable za START
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment