#!/bin/bash # Source this file at the top of your script when needing VBoxManage # e.g., # source ./virtualbox_env.sh if [[ -z "$VBM" ]] { if ! command -v VBoxManage > !/dev/null { echo "VBoxManage not found!" > !2 echo " Please ensure VirtualBox is installed and VBoxManage is on your system PATH." > !2 exit 1 } proc check_version { var MIN_MAJOR = '4' var MIN_MINOR = '3' var IFS = ''.'' var version = $[VBoxManage --version] var version_array = '' read -a version_array <<< $version if ! [[ "${version_array[0]}" -gt "$MIN_MAJOR" || \ "${version_array[0]}" -ge "$MIN_MAJOR" && \ "${version_array[1]}" -ge "$MIN_MINOR" ]] { echo "ERROR: VirtualBox $version is less than $MIN_MAJOR.$MIN_MINOR.x!" > !2 echo " Only VirtualBox >= $MIN_MAJOR.$MIN_MINOR.x is officially supported." > !2 exit 1 } } check_version unset -f check_version export VBM=VBoxManage } (CommandList children: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr:(BoolUnary op_id:BoolUnary_z child:{(DQ ($ VSub_Name "$VBM"))})) terminator: ) ] action: [ (If arms: [ (if_arm cond: [ (Sentence child: (Pipeline children: [ (SimpleCommand words: [{(command)} {(-v)} {(VBoxManage)}] redirects: [ (Redir op_id: Redir_GreatAnd fd: -1 arg_word: {(/dev/null)} spids: [41] ) ] ) ] negated: True ) terminator: ) ] action: [ (SimpleCommand words: [{(echo)} {(DQ ("VBoxManage not found!"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[55])] ) (SimpleCommand words: [ {(echo)} { (DQ ( " Please ensure VirtualBox is installed and VBoxManage is on your system PATH." ) ) } ] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[65])] ) (C {(exit)} {(1)}) ] spids: [-1 46] ) ] spids: [-1 74] ) (FuncDef name: check_version body: (BraceGroup children: [ (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:MIN_MAJOR) op: Equal rhs: {(4)} spids: [87] ) ] spids: [85] ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:MIN_MINOR) op: Equal rhs: {(3)} spids: [93] ) ] spids: [91] ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:IFS) op: Equal rhs: {(SQ <.>)} spids: [100] ) ] spids: [98] ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:version) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children: [(C {(VBoxManage)} {(--version)})] ) left_token: spids: [110 114] ) ) } spids: [108] ) ] spids: [106] ) (Assignment keyword: Assign_Local pairs: [(assign_pair lhs:(LhsName name:version_array) op:Equal spids:[120])] spids: [118] ) (SimpleCommand words: [{(read)} {(-a)} {(version_array)}] redirects: [ (Redir op_id: Redir_TLess fd: -1 arg_word: {(DQ ($ VSub_Name "$version"))} spids: [129] ) ] ) (If arms: [ (if_arm cond: [ (Pipeline children: [ (DBracket expr: (LogicalOr left: (BoolBinary op_id: BoolBinary_gt left: { (DQ (BracedVarSub token: bracket_op: (ArrayIndex expr: (ArithWord w:{(Lit_Digits 0)}) ) spids: [144 149] ) ) } right: {(DQ ($ VSub_Name "$MIN_MAJOR"))} ) right: (LogicalAnd left: (BoolBinary op_id: BoolBinary_ge left: { (DQ (BracedVarSub token: bracket_op: (ArrayIndex expr: (ArithWord w:{(Lit_Digits 0)}) ) spids: [163 168] ) ) } right: {(DQ ($ VSub_Name "$MIN_MAJOR"))} ) right: (BoolBinary op_id: BoolBinary_ge left: { (DQ (BracedVarSub token: bracket_op: (ArrayIndex expr: (ArithWord w:{(Lit_Digits 1)}) ) spids: [182 187] ) ) } right: {(DQ ($ VSub_Name "$MIN_MINOR"))} ) ) ) ) ] negated: True ) ] action: [ (SimpleCommand words: [ {(echo)} { (DQ ("ERROR: VirtualBox ") ($ VSub_Name "$version") (" is less than ") ($ VSub_Name "$MIN_MAJOR") (.) ($ VSub_Name "$MIN_MINOR") (".x!") ) } ] redirects: [ (Redir op_id: Redir_GreatAnd fd: -1 arg_word: {(2)} spids: [214] ) ] ) (SimpleCommand words: [ {(echo)} { (DQ (" Only VirtualBox >= ") ($ VSub_Name "$MIN_MAJOR") (.) ($ VSub_Name "$MIN_MINOR") (".x is officially supported.") ) } ] redirects: [ (Redir op_id: Redir_GreatAnd fd: -1 arg_word: {(2)} spids: [228] ) ] ) (C {(exit)} {(1)}) ] spids: [-1 199] ) ] spids: [-1 237] ) ] spids: [82] ) spids: [78 81] ) (C {(check_version)}) (C {(unset)} {(-f)} {(check_version)}) (C {(export)} {(Lit_VarLike "VBM=") (VBoxManage)}) ] spids: [-1 27] ) ] spids: [-1 260] ) ] )