diff --git a/actions/prepare-environment.sh b/actions/prepare-environment.sh index 15fc802..7a58e76 100755 --- a/actions/prepare-environment.sh +++ b/actions/prepare-environment.sh @@ -29,12 +29,36 @@ source ./functions/vm.sh source ./functions/network.sh source ./functions/shell.sh +# Check for the 'dumpkeys.cache' file +echo -n "Checking for 'dumpkeys.cache'... " +if ! [ -f dumpkeys.cache ]; then + echo + echo + echo "The file 'dumpkeys.cache' shouldn't be removed from the main directory!" + case "$(uname)" in + CYGWIN*) + echo "Please restore it from the sources, it can't be recreated on this operating system." + ;; + *) + echo "Please restore it from the sources, or it can recreated using this command:" + echo " sudo dumpkeys --keys-only > dumpkeys.cache" + echo "The 'dumpkeys' and 'sudo' should be installed first using your package manager." + ;; + esac + echo "Aborting." + exit 1 +else + echo "OK" +fi + # Check for procps package if [ "$(execute uname -s | cut -c1-6)" = "CYGWIN" ]; then echo -n "Checking for 'free'... " execute type free >/dev/null 2>&1 if [ $? -eq 1 ]; then - echo "\"free\" is not available in the path, but it's required. Please install the \"procps\" package. Aborting." + echo + echo + echo "'free' is not available in the path, but it's required. Please install the 'procps' package. Aborting." exit 1 else echo "OK" @@ -45,7 +69,9 @@ fi echo -n "Checking for 'expect'... " execute type expect >/dev/null 2>&1 if [ $? -eq 1 ]; then - echo "\"expect\" is not available in the path, but it's required. Please install Tcl \"expect\" package. Aborting." + echo + echo + echo "'expect' is not available in the path, but it's required. Please install Tcl 'expect' package. Aborting." exit 1 else echo "OK" @@ -55,17 +81,21 @@ fi echo -n "Checking for 'xxd'... " execute type xxd >/dev/null 2>&1 if [ $? -eq 1 ]; then - echo "\"xxd\" is not available in the path, but it's required. Please install the \"xxd\" package. Aborting." + echo + echo + echo "'xxd' is not available in the path, but it's required. Please install the 'xxd' package. Aborting." exit 1 else echo "OK" fi # Check for VirtualBox -echo -n "Checking for \"VBoxManage\"... " +echo -n "Checking for 'VBoxManage'... " execute type VBoxManage >/dev/null 2>&1 if [ $? -eq 1 ]; then - echo "\"VBoxManage\" is not available in the path, but it's required. Likely, VirtualBox is not installed. Aborting." + echo + echo + echo "'VBoxManage' is not available in the path, but it's required. Likely, VirtualBox is not installed. Aborting." exit 1 else echo "OK" @@ -75,9 +105,13 @@ fi echo -n "Checking for VirtualBox Extension Pack... " extpacks=`execute VBoxManage list extpacks | grep 'Usable' | grep 'true' | wc -l` if [ "$extpacks" -le 0 ]; then - echo >&2 "VirtualBox Extension Pack is not installed. Please, download and install it from the official VirtualBox web site at https://www.virtualbox.org/wiki/Downloads"; exit 1; + echo + echo + echo "VirtualBox Extension Pack is not installed. Please, download and install it from the official VirtualBox web site at https://www.virtualbox.org/wiki/Downloads" + exit 1; +else + echo "OK" fi -echo "OK" # execute some checks only in the 'launch' mode if [ $1 == "launch" ]; then @@ -103,11 +137,14 @@ fi # Check for ISO image to be available echo -n "Checking for Mirantis OpenStack ISO image... " if [ -z $iso_path ]; then - echo "Mirantis OpenStack image is not found. Please download it from software.mirantis.com and put under the 'iso' directory." - exit 1 + echo + echo + echo "Mirantis OpenStack image is not found. Please download it from software.mirantis.com and put under the 'iso' directory." + exit 1 +else + echo "OK" + echo "Going to use Mirantis OpenStack ISO file: $iso_path" fi -echo "OK" -echo "Going to use Mirantis OpenStack ISO file $iso_path" # Copy ISO to host copy_if_required $iso_path @@ -118,6 +155,8 @@ fi # end 'launch' mode check echo -n "Checking if SSH client installed... " execute type ssh >/dev/null 2>&1 if [ $? -eq 1 ]; then + echo + echo echo "SSH client is not installed. Please install the \"openssh\" package if you run this script under Cygwin. Aborting." exit 1 else @@ -128,6 +167,8 @@ echo -n "Checking if ipconfig or ifconfig installed... " case "$(execute uname)" in Linux | Darwin) if ! execute test -x /sbin/ifconfig ; then + echo + echo echo "No ifconfig available at /sbin/ifconfig path! This path is hard-coded into VBoxNetAdpCtl utility." echo "Please install ifconfig or create symlink to proper interface configuration utility. Aborting." exit 1 @@ -138,11 +179,15 @@ case "$(execute uname)" in # It uses built-in Windows ipconfig utility instead. execute type ipconfig >/dev/null 2>&1 if [ $? -eq 1 ]; then + echo + echo echo "No ipconfig available in Cygwin environment. Please check you can run ipconfig from Cygwin command prompt. Aborting." exit 1 fi ;; *) + echo + echo echo "$(execute uname) is not supported operating system." exit 1 ;; diff --git a/functions/memory.sh b/functions/memory.sh index 68cd7a5..ce309ed 100755 --- a/functions/memory.sh +++ b/functions/memory.sh @@ -16,6 +16,8 @@ # This file contains the functions to get available memory on host PC +[ "$(basename ${0})" = "memory.sh" ] && exit 1 + source ./functions/shell.sh get_available_memory() { diff --git a/functions/network.sh b/functions/network.sh index 181ac91..3777479 100755 --- a/functions/network.sh +++ b/functions/network.sh @@ -16,6 +16,8 @@ # This file contains the functions to manage host-only interfaces in the system +[ "$(basename ${0})" = "network.sh" ] && exit 1 + source ./functions/shell.sh get_hostonly_interfaces() { diff --git a/functions/product.sh b/functions/product.sh index 52cb69f..4f6500f 100755 --- a/functions/product.sh +++ b/functions/product.sh @@ -18,6 +18,8 @@ # and Fuel became operational, and also enabling outbound network/internet access for this VM through the # host system +[ "$(basename ${0})" = "product.sh" ] && exit 1 + source ./functions/shell.sh ssh_options='-oConnectTimeout=5 -oStrictHostKeyChecking=no -oCheckHostIP=no -oUserKnownHostsFile=/dev/null -oRSAAuthentication=no -oPubkeyAuthentication=no' diff --git a/functions/shell.sh b/functions/shell.sh index 66f83b5..fb4b90f 100755 --- a/functions/shell.sh +++ b/functions/shell.sh @@ -18,6 +18,8 @@ # Each command might be executed on the local machine or on the remote machine # depending on environment settings +[ "$(basename ${0})" = "shell.sh" ] && exit 1 + function execute() { # use shell substitution pattern ${parameter/pattern/string}, to escape spaces in arguments. if [ -n "$REMOTE_HOST" ]; then diff --git a/functions/translate.sh b/functions/translate.sh index 3a55858..a402538 100755 --- a/functions/translate.sh +++ b/functions/translate.sh @@ -16,11 +16,7 @@ # This file contains the functions for AT translated set 2 encoder -type xxd > /dev/null || exit 1 - -if ! test -f dumpkeys.cache; then - sudo dumpkeys --keys-only > dumpkeys.cache -fi +[ "$(basename ${0})" = "translate.sh" ] && exit 1 # XXX: hardcoded values are generated by: #make_break_shift="$(eval echo \$at_table_$(echo -n Shift | xxd -ps))" @@ -31,69 +27,66 @@ make_shift=36 break_shift=b6 map_set() { - # $1 - keycode - # $2 - normal value - # $3 - shifted value - [ "${2}${3}" = "nulnul" ] && return 1 - make=$(printf %02x "$1") - break=$(printf %02x "$(($1 | 128))") - eval "at_table_$(echo -n "${3#+}" | xxd -ps)='$make_shift $make $break $break_shift'" - eval "at_table_$(echo -n "${2#+}" | xxd -ps)='$make $break'" + # $1 - keycode + # $2 - normal value + # $3 - shifted value + [ "${2}${3}" = "nulnul" ] && return 1 + make=$(printf %02x "$1") + break=$(printf %02x "$(($1 | 128))") + eval "at_table_$(echo -n "${3#+}" | xxd -ps)='$make_shift $make $break $break_shift'" + eval "at_table_$(echo -n "${2#+}" | xxd -ps)='$make $break'" } map_alias() { - # $1,$3,$5,... - names - # $2,$4,$6,... - aliases - while [ -n "$1" -a -n "$2" ]; do - eval "at_table_$(echo -n "${2#+}" | xxd -ps)=\${at_table_$(echo -n "${1#+}" | xxd -ps)}" - shift - shift - done + # $1,$3,$5,... - names + # $2,$4,$6,... - aliases + while [ -n "$1" -a -n "$2" ]; do + eval "at_table_$(echo -n "${2#+}" | xxd -ps)=\${at_table_$(echo -n "${1#+}" | xxd -ps)}" + shift + shift + done } # at_table_$normal = n # at_table_$shifted = n while read keycode n _ normal shifted rest; do - [ "$keycode" = "keycode" ] || continue - map_set "${n}" "${normal}" "${shifted}" + [ "$keycode" = "keycode" ] || continue + map_set "${n}" "${normal}" "${shifted}" done < dumpkeys.cache # Extra mapping map_alias \ - one 1 exclam '!' \ - two 2 at '@' \ - three 3 numbersign '#' \ - four 4 dollar '$' \ - five 5 percent '%' \ - six 6 asciicircum '^' \ - seven 7 ampersand '&' \ - eight 8 asterisk '*' \ - nine 9 parenleft '(' \ - zero 0 parenright ')' \ - minus '-' underscore '_' \ - equal '=' plus '+' + one 1 exclam '!' \ + two 2 at '@' \ + three 3 numbersign '#' \ + four 4 dollar '$' \ + five 5 percent '%' \ + six 6 asciicircum '^' \ + seven 7 ampersand '&' \ + eight 8 asterisk '*' \ + nine 9 parenleft '(' \ + zero 0 parenright ')' \ + minus '-' underscore '_' \ + equal '=' plus '+' map_alias \ - bracketleft '[' braceleft '{' \ - bracketright ']' braceright '}' \ - semicolon ';' colon ':' \ - apostrophe "'" quotedbl '"' \ - grave '`' asciitilde '~' \ - backslash "\\" bar '|' \ - comma ',' less '<' \ - period '.' greater '>' \ - slash '/' question '?' \ - space ' ' Return $'\n' + bracketleft '[' braceleft '{' \ + bracketright ']' braceright '}' \ + semicolon ';' colon ':' \ + apostrophe "'" quotedbl '"' \ + grave '`' asciitilde '~' \ + backslash "\\" bar '|' \ + comma ',' less '<' \ + period '.' greater '>' \ + slash '/' question '?' \ + space ' ' Return $'\n' translate() { - for t in $(echo -n "$*" | xxd -ps | sed -e 's/../& /g'); do - n="at_table_$t" - v="${!n}" - [ -z "$v" ] && echo "$0: unknown char: '$t'." >&2 - echo -n " ${v}" - done - echo + for t in $(echo -n "$*" | xxd -ps | sed -e 's/../& /g'); do + n="at_table_$t" + v="${!n}" + [ -z "$v" ] && echo "$0: unknown char: '$t'." >&2 + echo -n " ${v}" + done + echo } - -[ "$(basename "$0")" = "translate.sh" ] && translate " vmlinuz initrd=initrd.img biosdevname=0 ks=cdrom:/ks.cfg ip=10.20.0.2 gw=10.20.0.1 dns1=10.20.0.1 netmask=255.255.255.0 hostname=fuel.domain.tld showmenu=no -" diff --git a/functions/vm.sh b/functions/vm.sh index aa96feb..60a9e8d 100755 --- a/functions/vm.sh +++ b/functions/vm.sh @@ -16,6 +16,8 @@ # This file contains the functions to manage VMs in through VirtualBox CLI +[ "$(basename ${0})" = "vm.sh" ] && exit 1 + source ./functions/shell.sh get_vm_base_path() {