Browse Source

Add checks for the file 'dumpkeys.cache'

This commit adds check for the file 'dumpkeys.cache' because it
should be exist in the main directory and in some cases it can't
be recreated. Also, this commit contains some enchancements for
all other checks and for the functions/*.sh modules.

Change-Id: Iaa55921709e0575e924af042f4322b759847d097
Closes-Bug: #1547019
Maksim Malchuk 3 years ago
parent
commit
74374b316c
7 changed files with 113 additions and 65 deletions
  1. 56
    11
      actions/prepare-environment.sh
  2. 2
    0
      functions/memory.sh
  3. 2
    0
      functions/network.sh
  4. 2
    0
      functions/product.sh
  5. 2
    0
      functions/shell.sh
  6. 47
    54
      functions/translate.sh
  7. 2
    0
      functions/vm.sh

+ 56
- 11
actions/prepare-environment.sh View File

@@ -29,12 +29,36 @@ source ./functions/vm.sh
29 29
 source ./functions/network.sh
30 30
 source ./functions/shell.sh
31 31
 
32
+# Check for the 'dumpkeys.cache' file
33
+echo -n "Checking for 'dumpkeys.cache'... "
34
+if ! [ -f dumpkeys.cache ]; then
35
+  echo
36
+  echo
37
+  echo "The file 'dumpkeys.cache' shouldn't be removed from the main directory!"
38
+  case "$(uname)" in
39
+    CYGWIN*)
40
+      echo "Please restore it from the sources, it can't be recreated on this operating system."
41
+    ;;
42
+    *)
43
+      echo "Please restore it from the sources, or it can recreated using this command:"
44
+      echo "  sudo dumpkeys --keys-only > dumpkeys.cache"
45
+      echo "The 'dumpkeys' and 'sudo' should be installed first using your package manager."
46
+    ;;
47
+  esac
48
+  echo "Aborting."
49
+  exit 1
50
+else
51
+  echo "OK"
52
+fi
53
+
32 54
 # Check for procps package
33 55
 if [ "$(execute uname -s | cut -c1-6)" = "CYGWIN" ]; then
34 56
   echo -n "Checking for 'free'... "
35 57
   execute type free >/dev/null 2>&1
36 58
   if [ $? -eq 1 ]; then
37
-    echo "\"free\" is not available in the path, but it's required. Please install the \"procps\" package. Aborting."
59
+    echo
60
+    echo
61
+    echo "'free' is not available in the path, but it's required. Please install the 'procps' package. Aborting."
38 62
     exit 1
39 63
   else
40 64
     echo "OK"
@@ -45,7 +69,9 @@ fi
45 69
 echo -n "Checking for 'expect'... "
46 70
 execute type expect >/dev/null 2>&1
47 71
 if [ $? -eq 1 ]; then
48
-  echo "\"expect\" is not available in the path, but it's required. Please install Tcl \"expect\" package. Aborting."
72
+  echo
73
+  echo
74
+  echo "'expect' is not available in the path, but it's required. Please install Tcl 'expect' package. Aborting."
49 75
   exit 1
50 76
 else
51 77
   echo "OK"
@@ -55,17 +81,21 @@ fi
55 81
 echo -n "Checking for 'xxd'... "
56 82
 execute type xxd >/dev/null 2>&1
57 83
 if [ $? -eq 1 ]; then
58
-  echo "\"xxd\" is not available in the path, but it's required. Please install the \"xxd\" package. Aborting."
84
+  echo
85
+  echo
86
+  echo "'xxd' is not available in the path, but it's required. Please install the 'xxd' package. Aborting."
59 87
   exit 1
60 88
 else
61 89
   echo "OK"
62 90
 fi
63 91
 
64 92
 # Check for VirtualBox
65
-echo -n "Checking for \"VBoxManage\"... "
93
+echo -n "Checking for 'VBoxManage'... "
66 94
 execute type VBoxManage >/dev/null 2>&1
67 95
 if [ $? -eq 1 ]; then
68
-  echo "\"VBoxManage\" is not available in the path, but it's required. Likely, VirtualBox is not installed. Aborting."
96
+  echo
97
+  echo
98
+  echo "'VBoxManage' is not available in the path, but it's required. Likely, VirtualBox is not installed. Aborting."
69 99
   exit 1
70 100
 else
71 101
   echo "OK"
@@ -75,9 +105,13 @@ fi
75 105
 echo -n "Checking for VirtualBox Extension Pack... "
76 106
 extpacks=`execute VBoxManage list extpacks | grep 'Usable' | grep 'true' | wc -l`
77 107
 if [ "$extpacks" -le 0 ]; then
78
-    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;
108
+  echo
109
+  echo
110
+  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"
111
+  exit 1;
112
+else
113
+  echo "OK"
79 114
 fi
80
-echo "OK"
81 115
 
82 116
 # execute some checks only in the 'launch' mode
83 117
 if [ $1 == "launch" ]; then
@@ -103,11 +137,14 @@ fi
103 137
 # Check for ISO image to be available
104 138
 echo -n "Checking for Mirantis OpenStack ISO image... "
105 139
 if [ -z $iso_path ]; then
106
-    echo "Mirantis OpenStack image is not found. Please download it from software.mirantis.com and put under the 'iso' directory."
107
-    exit 1
140
+  echo
141
+  echo
142
+  echo "Mirantis OpenStack image is not found. Please download it from software.mirantis.com and put under the 'iso' directory."
143
+  exit 1
144
+else
145
+  echo "OK"
146
+  echo "Going to use Mirantis OpenStack ISO file: $iso_path"
108 147
 fi
109
-echo "OK"
110
-echo "Going to use Mirantis OpenStack ISO file $iso_path"
111 148
 
112 149
 # Copy ISO to host
113 150
 copy_if_required $iso_path
@@ -118,6 +155,8 @@ fi # end 'launch' mode check
118 155
 echo -n "Checking if SSH client installed... "
119 156
 execute type ssh >/dev/null 2>&1
120 157
 if [ $? -eq 1 ]; then
158
+  echo
159
+  echo
121 160
   echo "SSH client is not installed. Please install the \"openssh\" package if you run this script under Cygwin. Aborting."
122 161
   exit 1
123 162
 else
@@ -128,6 +167,8 @@ echo -n "Checking if ipconfig or ifconfig installed... "
128 167
 case "$(execute uname)" in
129 168
   Linux | Darwin)
130 169
     if ! execute test -x /sbin/ifconfig ; then
170
+      echo
171
+      echo
131 172
       echo "No ifconfig available at /sbin/ifconfig path! This path is hard-coded into VBoxNetAdpCtl utility."
132 173
       echo "Please install ifconfig or create symlink to proper interface configuration utility. Aborting."
133 174
       exit 1
@@ -138,11 +179,15 @@ case "$(execute uname)" in
138 179
     # It uses built-in Windows ipconfig utility instead.
139 180
     execute type ipconfig >/dev/null 2>&1
140 181
     if [ $? -eq 1 ]; then
182
+      echo
183
+      echo
141 184
       echo "No ipconfig available in Cygwin environment. Please check you can run ipconfig from Cygwin command prompt. Aborting."
142 185
       exit 1
143 186
     fi
144 187
   ;;
145 188
   *)
189
+    echo
190
+    echo
146 191
     echo "$(execute uname) is not supported operating system."
147 192
     exit 1
148 193
   ;;

+ 2
- 0
functions/memory.sh View File

@@ -16,6 +16,8 @@
16 16
 
17 17
 # This file contains the functions to get available memory on host PC
18 18
 
19
+[ "$(basename ${0})" = "memory.sh" ] && exit 1
20
+
19 21
 source ./functions/shell.sh
20 22
 
21 23
 get_available_memory() {

+ 2
- 0
functions/network.sh View File

@@ -16,6 +16,8 @@
16 16
 
17 17
 # This file contains the functions to manage host-only interfaces in the system
18 18
 
19
+[ "$(basename ${0})" = "network.sh" ] && exit 1
20
+
19 21
 source ./functions/shell.sh
20 22
 
21 23
 get_hostonly_interfaces() {

+ 2
- 0
functions/product.sh View File

@@ -18,6 +18,8 @@
18 18
 # and Fuel became operational, and also enabling outbound network/internet access for this VM through the
19 19
 # host system
20 20
 
21
+[ "$(basename ${0})" = "product.sh" ] && exit 1
22
+
21 23
 source ./functions/shell.sh
22 24
 
23 25
 ssh_options='-oConnectTimeout=5 -oStrictHostKeyChecking=no -oCheckHostIP=no -oUserKnownHostsFile=/dev/null -oRSAAuthentication=no -oPubkeyAuthentication=no'

+ 2
- 0
functions/shell.sh View File

@@ -18,6 +18,8 @@
18 18
 # Each command might be executed on the local machine or on the remote machine
19 19
 # depending on environment settings
20 20
 
21
+[ "$(basename ${0})" = "shell.sh" ] && exit 1
22
+
21 23
 function execute() {
22 24
   #  use shell substitution pattern ${parameter/pattern/string}, to escape spaces in arguments.
23 25
   if [ -n "$REMOTE_HOST" ]; then

+ 47
- 54
functions/translate.sh View File

@@ -16,11 +16,7 @@
16 16
 
17 17
 # This file contains the functions for AT translated set 2 encoder
18 18
 
19
-type xxd > /dev/null || exit 1
20
-
21
-if ! test -f dumpkeys.cache; then
22
-        sudo dumpkeys --keys-only > dumpkeys.cache
23
-fi
19
+[ "$(basename ${0})" = "translate.sh" ] && exit 1
24 20
 
25 21
 # XXX: hardcoded values are generated by:
26 22
 #make_break_shift="$(eval echo \$at_table_$(echo -n Shift | xxd -ps))"
@@ -31,69 +27,66 @@ make_shift=36
31 27
 break_shift=b6
32 28
 
33 29
 map_set() {
34
-        # $1 - keycode
35
-        # $2 - normal value
36
-        # $3 - shifted value
37
-        [ "${2}${3}" = "nulnul" ] && return 1
38
-        make=$(printf %02x "$1")
39
-        break=$(printf %02x "$(($1 | 128))")
40
-        eval "at_table_$(echo -n "${3#+}" | xxd -ps)='$make_shift $make $break $break_shift'"
41
-        eval "at_table_$(echo -n "${2#+}" | xxd -ps)='$make $break'"
30
+  # $1 - keycode
31
+  # $2 - normal value
32
+  # $3 - shifted value
33
+  [ "${2}${3}" = "nulnul" ] && return 1
34
+  make=$(printf %02x "$1")
35
+  break=$(printf %02x "$(($1 | 128))")
36
+  eval "at_table_$(echo -n "${3#+}" | xxd -ps)='$make_shift $make $break $break_shift'"
37
+  eval "at_table_$(echo -n "${2#+}" | xxd -ps)='$make $break'"
42 38
 }
43 39
 
44 40
 map_alias() {
45
-        # $1,$3,$5,... - names
46
-        # $2,$4,$6,... - aliases
47
-        while [ -n "$1" -a -n "$2" ]; do
48
-               eval "at_table_$(echo -n "${2#+}" | xxd -ps)=\${at_table_$(echo -n "${1#+}" | xxd -ps)}"
49
-               shift
50
-               shift
51
-        done
41
+  # $1,$3,$5,... - names
42
+  # $2,$4,$6,... - aliases
43
+  while [ -n "$1" -a -n "$2" ]; do
44
+    eval "at_table_$(echo -n "${2#+}" | xxd -ps)=\${at_table_$(echo -n "${1#+}" | xxd -ps)}"
45
+    shift
46
+    shift
47
+  done
52 48
 }
53 49
 
54 50
 # at_table_$normal = n
55 51
 # at_table_$shifted = n
56 52
 while read keycode n _ normal shifted rest; do
57
-        [ "$keycode" = "keycode" ] || continue
58
-        map_set "${n}" "${normal}" "${shifted}"
53
+  [ "$keycode" = "keycode" ] || continue
54
+  map_set "${n}" "${normal}" "${shifted}"
59 55
 done < dumpkeys.cache
60 56
 
61 57
 # Extra mapping
62 58
 map_alias \
63
-        one 1 exclam '!' \
64
-	two 2 at '@' \
65
-	three 3 numbersign '#' \
66
-	four 4 dollar '$' \
67
-	five 5 percent '%' \
68
-	six 6 asciicircum '^' \
69
-	seven 7 ampersand '&' \
70
-	eight 8 asterisk '*' \
71
-	nine 9 parenleft '(' \
72
-	zero 0 parenright ')' \
73
-	minus '-' underscore '_' \
74
-	equal '=' plus '+'
59
+  one 1 exclam '!' \
60
+  two 2 at '@' \
61
+  three 3 numbersign '#' \
62
+  four 4 dollar '$' \
63
+  five 5 percent '%' \
64
+  six 6 asciicircum '^' \
65
+  seven 7 ampersand '&' \
66
+  eight 8 asterisk '*' \
67
+  nine 9 parenleft '(' \
68
+  zero 0 parenright ')' \
69
+  minus '-' underscore '_' \
70
+  equal '=' plus '+'
75 71
 
76 72
 map_alias \
77
-        bracketleft '[' braceleft '{' \
78
-        bracketright ']' braceright '}' \
79
-        semicolon ';' colon ':' \
80
-        apostrophe "'" quotedbl '"' \
81
-        grave '`' asciitilde '~' \
82
-        backslash "\\" bar '|' \
83
-        comma ',' less '<' \
84
-        period '.' greater '>' \
85
-        slash '/' question '?' \
86
-        space ' ' Return $'\n'
73
+  bracketleft '[' braceleft '{' \
74
+  bracketright ']' braceright '}' \
75
+  semicolon ';' colon ':' \
76
+  apostrophe "'" quotedbl '"' \
77
+  grave '`' asciitilde '~' \
78
+  backslash "\\" bar '|' \
79
+  comma ',' less '<' \
80
+  period '.' greater '>' \
81
+  slash '/' question '?' \
82
+  space ' ' Return $'\n'
87 83
 
88 84
 translate() {
89
-        for t in $(echo -n "$*" | xxd -ps | sed -e 's/../& /g'); do
90
-                n="at_table_$t"
91
-                v="${!n}"
92
-                [ -z "$v" ] && echo "$0: unknown char: '$t'." >&2
93
-                echo -n " ${v}"
94
-        done
95
-        echo
85
+  for t in $(echo -n "$*" | xxd -ps | sed -e 's/../& /g'); do
86
+    n="at_table_$t"
87
+    v="${!n}"
88
+    [ -z "$v" ] && echo "$0: unknown char: '$t'." >&2
89
+    echo -n " ${v}"
90
+  done
91
+  echo
96 92
 }
97
-
98
-[ "$(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
99
-"

+ 2
- 0
functions/vm.sh View File

@@ -16,6 +16,8 @@
16 16
 
17 17
 # This file contains the functions to manage VMs in through VirtualBox CLI
18 18
 
19
+[ "$(basename ${0})" = "vm.sh" ] && exit 1
20
+
19 21
 source ./functions/shell.sh
20 22
 
21 23
 get_vm_base_path() {

Loading…
Cancel
Save