- Timestamp:
- Oct 25, 2010 2:37:39 PM (14 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/x11/Installer/x11config.sh
r33342 r33428 1 #!/ usr/bin/perl -w1 #!/bin/sh 2 2 # 3 3 # Guest Additions X11 config update script … … 14 14 # 15 15 16 my $auto_mouse = 0; 17 my $new_mouse = 0; 18 my $no_bak = 0; 19 my $old_mouse_dev = "/dev/psaux"; 16 auto_mouse="" 17 new_mouse="" 18 no_bak="" 19 old_mouse_dev="/dev/psaux" 20 20 21 foreach $arg (@ARGV) 21 tab=`printf '\t'` 22 23 ALL_SECTIONS=\ 24 '^[ '$tab']*[Ss][Ee][Cc][Tt][Ii][Oo][Nn][ '$tab']*'\ 25 '"\([Ii][Nn][Pp][Uu][Tt][Dd][Ee][Vv][Ii][Cc][Ee]\|'\ 26 '[Dd][Ee][Vv][Ii][Cc][Ee]\|'\ 27 '[Ss][Ee][Rr][Vv][Ee][Rr][Ll][Aa][Yy][Oo][Uu][Tt]\|'\ 28 '[Ss][Cc][Rr][Ee][Ee][Nn]\|'\ 29 '[Mm][Oo][Nn][Ii][Tt][Oo][Rr]\|'\ 30 '[Kk][Ee][Yy][Bb][Oo][Aa][Rr][Dd]\|'\ 31 '[Pp][Oo][Ii][Nn][Tt][Ee][Rr]\)"' 32 # ^\s*Section\s*"(InputDevice|Device|ServerLayout|Screen|Monitor|Keyboard|Pointer)" 33 34 KBD_SECTION='[Kk][Ee][Yy][Bb][Oo][Aa][Rr][Dd]' # Keyboard 35 36 END_SECTION='[Ee][Nn][Dd][Ss][Ee][Cc][Tt][Ii][Oo][Nn]' # EndSection 37 38 OPT_XKB='^[ '$tab']*option[ '$tab'][ '$tab']*"xkb' 39 40 DRIVER_KBD='^[ '$tab']*[Dd][Rr][Ii][Vv][Ee][Rr][ '$tab'][ '$tab']*'\ 41 '"\(kbd\|keyboard\)"' 42 # ^\s*driver\s+\"(kbd|keyboard)\" 43 44 reconfigure() 22 45 { 23 if (lc($arg) eq "--automouse") 24 { 25 $auto_mouse = 1; 26 } 27 elsif (lc($arg) eq "--newmouse") 28 { 29 $new_mouse = 1; 30 } 31 elsif (lc($arg) eq "--nobak") 32 { 33 $no_bak = 1; 34 } 35 elsif (lc($arg) eq "--nopsaux") 36 { 37 $old_mouse_dev = "/dev/input/mice"; 38 } 39 else 40 { 41 my $cfg = $arg; 42 my $CFG; 43 my $xkbopts = ""; 44 my $kb_driver = ""; 45 my $layout_kb = ""; 46 if (open(CFG, $cfg)) 47 { 48 my $TMP; 49 my $temp = $cfg.".vbox.tmp"; 50 open(TMP, ">$temp") or die "Can't create $TMP: $!\n"; 51 52 my $in_section = 0; 53 print TMP "# VirtualBox generated configuration file\n"; 54 print TMP "# based on $cfg.\n"; 55 56 while (defined ($line = <CFG>)) 57 { 58 if ($line =~ /^\s*Section\s*"([a-zA-Z]+)"/i) 59 { 60 my $section = lc($1); 61 if ( ($section eq "inputdevice") 62 || ($section eq "device") 63 || ($section eq "serverlayout") 64 || ($section eq "screen") 65 || ($section eq "monitor") 66 || ($section eq "keyboard") 67 || ($section eq "pointer")) 68 { 69 $in_section = 1; 70 } 71 } else { 72 if ($line =~ /^\s*EndSection/i) 73 { 74 $line = "# " . $line unless $in_section eq 0; 75 $in_section = 0; 76 } 77 } 78 79 if ($in_section) 80 { 81 # Remember XKB options 82 if ($line =~ /^\s*option\s+\"xkb/i) 83 { 84 $xkbopts = $xkbopts . $line; 85 } 86 # If we find a keyboard driver, remember it 87 if ($line =~ /^\s*driver\s+\"(kbd|keyboard)\"/i) 88 { 89 $kb_driver = $1; 90 } 91 $line = "# " . $line; 92 } 93 print TMP $line; 94 } 95 96 if ($kb_driver ne "") 97 { 98 print TMP <<EOF; 46 cfg="$1" 47 tmp="$cfg.vbox.tmp" 48 test -w "$cfg" || { echo "$cfg does not exist"; return; } 49 rm -f "$tmp" 50 test ! -e "$tmp" || { echo "Failed to delete $tmp"; return; } 51 touch "$tmp" 52 test -w "$tmp" || { echo "Failed to create $tmp"; return; } 53 xkb_opts="`cat "$cfg" | sed -n -e "/$KBD_SECTION/,/$END_SECTION/p" | 54 grep -i "$OPT_XKB"`" 55 kbd_drv="`cat "$cfg" | sed -n -e "/$KBD_SECTION/,/$END_SECTION/p" | 56 sed -n -e "0,/$DRIVER_KBD/s/$DRIVER_KBD/\\1/p"`" 57 cat > "$tmp" << EOF 58 # VirtualBox generated configuration file 59 # based on $cfg. 60 EOF 61 cat "$cfg" | sed -e "/$ALL_SECTIONS/,/$END_SECTION/s/\\(.*\\)/# \\1/" >> "$tmp" 62 test -n "$kbd_drv" && cat >> "$tmp" << EOF 99 63 Section "InputDevice" 100 64 Identifier "Keyboard[0]" 101 Driver "$kb_driver" 102 $xkbopts Option "Protocol" "Standard" 65 Driver "$kbd_drv" 66 $xkb_opts 67 Option "Protocol" "Standard" 103 68 Option "CoreKeyboard" 104 69 EndSection 105 70 EOF 106 $layout_kb = " InputDevice \"Keyboard[0]\" \"CoreKeyboard\"\n" 107 } 108 109 if (!$auto_mouse && !$new_mouse) { 110 print TMP <<EOF; 71 kbd_layout="" 72 test -n "$kbd_drv" && kbd_layout=' InputDevice "Keyboard[0]" "CoreKeyboard"' 73 test -z "$auto_mouse" -a -z "$new_mouse" && cat >> $tmp << EOF 111 74 112 75 Section "InputDevice" … … 124 87 Section "ServerLayout" 125 88 Identifier "Layout[all]" 126 $layout_kb InputDevice "Mouse[1]" "CorePointer" 89 $kbd_layout 90 InputDevice "Mouse[1]" "CorePointer" 127 91 Option "Clone" "off" 128 92 Option "Xinerama" "off" … … 130 94 EndSection 131 95 EOF 132 }133 96 134 if (!$auto_mouse && $new_mouse) {135 print TMP <<EOF;97 test -z "$auto_mouse" -a -n "$new_mouse" && 98 cat >> "$tmp" << EOF 136 99 137 100 Section "InputDevice" … … 166 129 EndSection 167 130 EOF 168 }169 131 170 print TMP <<EOF;132 cat >> "$tmp" << EOF 171 133 172 134 Section "Monitor" … … 192 154 EndSection 193 155 EOF 194 close(TMP);195 156 196 system("cp", $cfg, $cfg.".vbox") unless 197 ($no_bak eq 1 || -e $cfg.".vbox"); 198 rename $cfg, $cfg.".bak" unless $no_bak eq 1; 199 rename $temp, $cfg; 200 } 201 } 157 test -n "$no_bak" -o -f "$cfg.vbox" || cp "$cfg" "$cfg.vbox" 158 test -n "$no_bak" || mv "$cfg" "$cfg.bak" 159 mv "$tmp" "$cfg" 202 160 } 203 exit 0 161 162 while test -n "$1" 163 do 164 case "$1" in 165 --autoMouse) 166 auto_mouse=1 ;; 167 --newMouse) 168 new_mouse=1 ;; 169 --noBak) 170 no_bak=1 ;; 171 --nopsaux) 172 old_mouse_dev="/dev/input/mice" ;; 173 *) 174 reconfigure "$1" ;; 175 esac 176 shift 177 done
Note:
See TracChangeset
for help on using the changeset viewer.