liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

script.expect (1572B)


      1 set timeout 40
      2 fconfigure stdout -buffering  none
      3 
      4 set when [lindex $argv 0];
      5 
      6 send_user "\n\n\n\n#################################\n running $when"
      7 
      8 
      9 spawn socat -,echo=0,icanon=1 unix-connect:vm/monitor
     10 set monitor_id $spawn_id
     11 fconfigure $monitor_id -buffering none
     12 
     13 spawn socat unix-connect:vm/console -
     14 set console_id $spawn_id
     15 fconfigure $console_id -buffering  none
     16 
     17 proc chat {instr outstr} {
     18     expect {
     19         $instr  { send $outstr }
     20         timeout { exit 1 }
     21     }
     22 }
     23 
     24 proc adddevice { } {
     25     global monitor_id console_id spawn_id
     26     set spawn_id $monitor_id
     27 
     28     send_user "\n#### inserting usb device"
     29     send "\r\n"
     30     chat "QEMU" "device_add usb-storage,bus=xhci.0,drive=usbstick\n"
     31 
     32     set spawn_id $console_id
     33 
     34     expect {
     35       "sda: sda1" { }
     36       timeout {
     37           puts stderr "timeout waiting for disk"
     38           exit 1
     39       }
     40     }
     41     send_user "done inserting usb device"       
     42 }
     43 
     44 if { $when eq "early" } {
     45   adddevice
     46 }
     47 
     48 expect "BusyBox"
     49 chat "#" "PS1=RE\\ADY_\\ ; stty -echo \r"
     50 # script needs klogd output to tell when sda1 appears. Then
     51 # run s6-rc -b  -a list to wait for booting to finish
     52 chat "READY_"  "tail -f /run/log/current & \rs6-rc -b  -a list\r"
     53 
     54 if { $when eq "late" } {
     55   adddevice
     56 }
     57 
     58 send_user "\n\n\nwaiting for mount to happen"
     59 
     60 set FINISHED 0
     61 set EXIT "1" 
     62 while { $FINISHED < 10 } {
     63   chat "READY_" "grep /srv /proc/mounts\r\n"
     64   expect {
     65     "backup-disk" { set FINISHED 20; set EXIT 0; }
     66     "READY_" { send_user "waiting ...\n" ; send "\r\n"; sleep 6 }
     67   }
     68   set FINISHED [ expr $FINISHED + 1 ]
     69 }
     70 
     71 exit $EXIT