From: ebelcrom Date: Sun, 2 Jun 2019 21:53:08 +0000 (+0200) Subject: adapt build.sh options X-Git-Tag: v2.0~1 X-Git-Url: http://www.binomiant.duckdns.org/9wAuyR5S/?a=commitdiff_plain;h=9a509a401852e83ceae8d9815359fc3156fd7e18;p=rescuesys.git adapt build.sh options --- diff --git a/build.sh b/build.sh index d1a5519..20d2627 100755 --- a/build.sh +++ b/build.sh @@ -25,7 +25,7 @@ Options: -h show help (resp. this message) -i create raw image -a all, run steps -g, -c, -r, -i -l clean up vm - -n don't use ramfs + -s speed up execution using ramfs Some options are mutualy exclusive. EOF } @@ -74,29 +74,31 @@ create_VM() echo "Creating VM with VDI in ramfs..." - # create ramfs -# sudo mount -t ramfs ramfs -o mode=1777 ramfs -# cp setup.iso ramfs/ + if [ $option_ramfs -eq 1 ]; then + local vdi_file=ramfs/rescuesys.vdi + local iso_file=ramfs/setup.iso + # create ramfs + sudo mount -t ramfs ramfs -o mode=1777 ramfs + cp setup.iso ramfs/ + else + local vdi_file=rescuesys.vdi + local iso_file=setup.iso + fi # create and configure VM VBoxManage createvm --name rescuesys --register > /dev/null VBoxManage modifyvm rescuesys --memory 1024 --acpi on --boot1 disk --boot2\ - dvd --vram 12 --cpus $(nproc) + dvd --vram 12 --cpus $(getconf _NPROCESSORS_ONLN) VBoxManage modifyvm rescuesys --nic1 nat --nictype1 82540EM\ --cableconnected1 on VBoxManage modifyvm rescuesys --ostype Ubuntu_64 VBoxManage modifyvm rescuesys --ioapic on -# VBoxManage createhd --filename ramfs/rescuesys.vdi --size 3814 > /dev/null - VBoxManage createhd --filename rescuesys.vdi --size 3814 > /dev/null + VBoxManage createhd --filename $vdi_file --size 3814 > /dev/null VBoxManage storagectl rescuesys --name SATA --add sata --hostiocache on -# VBoxManage storageattach rescuesys --storagectl SATA --port 0 --device 0\ -# --type hdd --medium ramfs/rescuesys.vdi -# VBoxManage storageattach rescuesys --storagectl SATA --port 1 --device 0\ -# --type dvddrive --medium ramfs/setup.iso VBoxManage storageattach rescuesys --storagectl SATA --port 0 --device 0\ - --type hdd --medium rescuesys.vdi + --type hdd --medium $vdi_file VBoxManage storageattach rescuesys --storagectl SATA --port 1 --device 0\ - --type dvddrive --medium setup.iso + --type dvddrive --medium $iso_file } run_VM() @@ -124,10 +126,12 @@ create_image() echo "Creating image..." rm -f rescuesys.img -# VBoxManage clonehd ramfs/rescuesys.vdi rescuesys.img --format RAW >\ -# /dev/null - VBoxManage clonehd rescuesys.vdi rescuesys.img --format RAW >\ - /dev/null + if [ $option_ramfs -eq 1 ]; then + local vdi_file=ramfs/rescuesys.vdi + else + local vdi_file=rescuesys.vdi + fi + VBoxManage clonehd $vdi_file rescuesys.img --format RAW > /dev/null adapt_image } @@ -167,16 +171,16 @@ cleanup() set -e } -action_other= -action_generate_iso= -action_create_VM= -action_run_VM= -action_create_image= -action_all= -action_cleanup= -option_noramfs= +action_other=0 +action_generate_iso=0 +action_create_VM=0 +action_run_VM=0 +action_create_image=0 +action_all=0 +action_cleanup=0 +option_ramfs=0 -while getopts "hgcrialn" opt; do +while getopts "hgcrials" opt; do case $opt in h) usage @@ -204,6 +208,9 @@ while getopts "hgcrialn" opt; do l) action_cleanup=1 ;; + s) + option_ramfs=1 + ;; *) usage exit 1 @@ -213,8 +220,19 @@ done [ -z "$1" ] && { usage; exit 0; } -if [ $action_all && $action_other ] || [ $action_cleanup && $action_other ] ||\ - [ $action_all && $action_cleanup ]; then +if (($action_all&&$action_other)) || (($action_cleanup&&$action_other)) ||\ + (($action_all&&$action_cleanup)); then usage exit 1 fi + +[ $action_cleanup -eq 1 ] && { cleanup; exit 0; } +[ $action_all -eq 1 ] && { generate_iso; create_VM; run_VM; create_image;\ + exit 0; } + +[ $action_generate_iso -eq 1 ] && generate_iso +[ $action_create_VM -eq 1 ] && create_VM +[ $action_run_VM -eq 1 ] && run_VM +[ $action_create_image -eq 1 ] && create_image + +exit 0