Patch title: Release 91 bulk changes
Abstract:
File: /fullpliant/embedded/boot.pli
Key:
    Removed line
    Added line
module "/pliant/language/stream.pli"
module "/pliant/language/unsafe.pli"
module "/pliant/language/context.pli"
module "/pliant/fullpliant/this_computer.pli"
module "/pliant/admin/file.pli"
module "/pliant/admin/execute.pli"
module "/pliant/linux/kernel/module.pli"
module "/pliant/linux/storage/filesystem.pli"
module "/pliant/linux/schedule/process.pli"
module "/pliant/language/stream/filesystembase.pli"
module "/pliant/language/stream/multi.pli"
module "/pliant/linux/kernel/device.pli"
module "command.pli"

constant reconfigure_printers true


function wait_for_tcp_port server port timeout -> status
  arg Str server ; arg Int port ; arg Float timeout ; arg Status status
  for (var Int i) 0 (cast timeout Int)
    (var Stream s) open "tcp://"+server+"/client/"+string:port in+out+safe
    if s=success
      return success
    sleep 1
  status := failure 


function embedded_boot1 c
  arg_rw Data:Computer c
  if file_os_name:"embedded:/":len<2
    return
  var Str embedded := c:env:"pliant":"system":"embedded"

  # new embedded computer
  plugin install
    if (file_query "file:/boot/"+embedded+".tgz" standard)=defined
      console "Installing a new embedded system" eol
      if (file_query "file:/boot/remove_existing_embedded_system.flag" standard)=defined
        file_delete "file:/boot/remove_existing_embedded_system.flag"
        console "  removing existing embedded system" eol
        file_tree_delete "embedded:/"
      file_extract "file:/boot/"+embedded+".tgz" "embedded:/"
      file_delete "file:/boot/"+embedded+".tgz"

  # cleanup /tmp
  var Str flags := (file_query "embedded:/tmp/" extended) options
  file_tree_delete "embedded:/tmp/"
  file_tree_create "embedded:/tmp/"
  file_configure "embedded:/tmp/" flags

  # mount /proc in the embedded system
  filesystem_mount "file:proc" "embedded:/proc" "filesystem [dq]proc[dq]"

  # update DLLs
  embedded_command "ldconfig" "" # SECURITY

  # update modules
  file_extract "file:/boot/modules.tgz" "embedded:/"
  embedded_command "depmod -a" "" # SECURITY
     
  # start PCMCIA
  if c:env:"kernel":"make":"CONFIG_PCMCIA"="y" and c:env:"kernel":"constant":"pcmcia_version"<>"" and (file_query "file:/bin/cardmgr" standard)=undefined
    embedded_command "/etc/init.d/pcmcia start" "" # SECURITY
    sleep 5


function embedded_boot2 c
  arg_rw Data:Computer c
  if file_os_name:"embedded:/":len<2
    return

  # network
  module "/pliant/fullpliant/export.pli"
  export_init
  if c:env:"debian":"nfs":"service"="true"
    export_nfs_start
  if c:env:"debian":"samba":"service"="true"
    export_samba_start
  if c:env:"debian":"netatalk":"service"="true"
    export_netatalk_start

  # load keyboard layout
  embedded_command "loadkeys /usr/share/keymaps/"+(shunt c:env:"hardware":"keyboard":"glibc_layout"<>"" c:env:"hardware":"keyboard":"glibc_layout" c:env:"hardware":"keyboard":"layout") "" # SECURITY
  # tpconfig --rate=1 --tapmode=0

  # mouse modules
  kernel_make_device c:env:"hardware":"mouse":"linux_device"
  if c:env:"hardware":"mouse":"linux_device"="device:/input/mice"
    execute "insmod usbcore"
    execute "insmod usb-uhci"
    execute "insmod input"
    execute "insmod hid"
    execute "insmod mousedev"
    execute "insmod keybdev"
    kernel_load_module "usbcore"
    kernel_load_module "usb-uhci" # 2.4
    kernel_load_module "uhci_hcd" # 2.6
    kernel_load_module "input" # 2.4
    kernel_load_module "hid"
    kernel_load_module "mousedev" # 2.4
    kernel_load_module "keybdev" # 2.4
    kernel_load_module "usbkbd" # 2.6
    kernel_load_module "usbmouse" # 2.6
    sleep 3

  # standard Unix print queues: now replaced by Pliant lpr service
  if false # c:env:"printer":size>0
    each printer c:env:"printer"
      if (printer:"device" parse "device:/usb/lp" (var Int num))
        execute "insmod usbcore" quiet
        execute "insmod usb-uhci" quiet
        execute "insmod printer" quiet
        kernel_load_module "usbcore"
        kernel_load_module "usb-uhci" # 2.4
        kernel_load_module "ehci-hcd" # 2.4
        kernel_load_module "uhci_hcd" # 2.6
        kernel_load_module "ehci_hcd" # 2.6
        kernel_load_module "printer" # 2.4
        kernel_load_module "usblp" # 2.6
        filesystem_mount "file:usb" "embedded:/proc/bus/usb/" "filesystem [dq]usbdevfs[dq]"
        file_tree_create "embedded:/dev/usb/"
        kernel_make_device (replace printer:"device" "device:/" "embedded:/dev/") kernel_character_device 180 num
      eif printer:"device"<>""
        kernel_make_device (replace printer:"device" "device:/" "embedded:/dev/")
    execute "insmod parport"
    execute "insmod parport_pc"
    execute "insmod lp"
    kernel_load_module "parport"
    kernel_load_module "parport_pc"
    kernel_load_module "lp"
    embedded_command "lpd" "" # SECURITY

  # start X11 server
  var Str x11 := c:env:"hardware":"video":"x11"
  var Str xserver := c:env:"hardware":"video":"xfree86_server_name"
  var Str xfree3_exe := "XF86_"+upper:(xserver 0 1)+(xserver 1 xserver:len)
  var Str xdriver := c:env:"hardware":"video":"xfree86_driver"
  kernel_make_device "embedded:/dev/fb0"
  if xdriver="i810"
    kernel_make_device "embedded:/dev/agpgart"
    execute "insmod agpgart"
    kernel_load_module "agpgart"
  if x11="none"
    void
  eif x11="vnc"
    if false
      file_tree_create "embedded:/home/me/.vnc/"
      module "/pliant/protocol/vnc/password.pli"
      vnc_set_password "ji56au" "embedded:/home/me/.vnc/passwd"
      file_tree_rights "embedded:/home/me/.vnc/" 4096 100 0 0 0 0
      file_rights "embedded:/home/me/.vnc/passwd" undefined undefined 0 7*8+7
    if not (c:env:"hardware":"screen":"horizontal_resolution" parse (var Int rx))
      rx := 1024
    if not (c:env:"hardware":"screen":"vertical_resolution" parse (var Int ry))
      ry := 768
    embedded_command "Xrealvnc :0 -localhost -rfbport 5900 -geometry "+string:rx+"x"+string:ry+" -depth 24 -pixelformat rgb888 -fp /usr/X11R6/lib/X11/fonts/misc:unscaled,/usr/X11R6/lib/X11/fonts/75dpi:unscaled,/usr/X11R6/lib/X11/fonts/100dpi:unscaled,/usr/X11R6/lib/X11/fonts/Type1,/usr/X11R6/lib/X11/fonts/Speedo,/usr/X11R6/lib/X11/fonts/misc,/usr/X11R6/lib/X11/fonts/75dpi,/usr/X11R6/lib/X11/fonts/100dpi -co /usr/X11R6/lib/X11/rgb" "user [dq]me[dq] detached quiet"
  eif xserver<>"" and (file_query "embedded:/usr/X11R6/bin/"+xfree3_exe standard)=success
    # XFree 3
    kernel_make_device (replace c:env:"hardware":"mouse":"linux_device" "device:/" "embedded:/dev/")
    for (var Int i) 0 15
      kernel_make_device "embedded:/dev/tty"+string:i
    embedded_command xfree3_exe "detached" # SECURITY
  eif xdriver<>"" and (file_query "embedded:/usr/X11R6/bin/XFree86" standard)=success
    # XFree 4
    kernel_make_device (replace c:env:"hardware":"mouse":"linux_device" "device:/" "embedded:/dev/")
    for (var Int i) 0 15
      kernel_make_device "embedded:/dev/vcs"+string:i
      kernel_make_device "embedded:/dev/tty"+string:i
    kernel_make_device "embedded:/dev/mem"
    if (file_query "embedded:/usr/X11R6/bin/855patch" standard)=success # Dell Inspiron 500m workaround
      embedded_command "855patch 8192" ""
    embedded_command "XFree86" "detached" # SECURITY
  else
    return
  if x11<>"none"
    wait_for_tcp_port "127.0.0.1" 6000 15
    embedded_command "xhost +local:" "" # SECURITY
  # start windows manager
  if x11<>"none"
    embedded_command c:env:"debian":"x11":"windows_manager" "user [dq]me[dq] detached"
  if x11<>"vnc" and x11<>"none" and (xserver<>"" or xdriver<>"") # SECURITY
    embedded_command "xmodmap -e 'keycode 24 = a A acircumflex adiaeresis'" ""
    embedded_command "xmodmap -e 'keycode 26 = e E ecircumflex ediaeresis'" ""
    embedded_command "xmodmap -e 'keycode 31 = i I icircumflex idiaeresis'" ""
    embedded_command "xmodmap -e 'keycode 32 = o O ocircumflex odiaeresis'" ""
    embedded_command "xmodmap -e 'keycode 30 = u U ucircumflex udiaeresis'" ""
    embedded_command "xmodmap -e 'keycode 34 = Mode_switch'" ""
  if x11<>"none" and (file_query "embedded:/usr/lib/openoffice/program/swriter" standard)=defined
    embedded_command "gnome-settings-daemon" "user [dq]me[dq] detached" # required to get decent OpenOffice fonts :-(
    sleep 5
  if x11<>"none" and (c:env:"hardware":"mouse":"resolution" parse (var Int rd) "/" (var Int rq))
    embedded_command "xset m "+c:env:"hardware":"mouse":"resolution"+" 1" "" # SECURITY
  if x11<>"none"
    embedded_command "xsetroot -solid #407060" "" # SECURITY

  # xbiff mail received warner
  if x11<>"none" and c:env:"pliant":"mail":"pop3_provider"<>""
    embedded_command "xbiff2" "user [dq]me[dq] detached"

  # netscape
  file_delete "embedded:/home/me/.netscape/lock"
  if false # rather use Mozilla
    embedded_command "netscape" "user [dq]me[dq] detached"

  # mozilla
  if false # launched by run.pli when the HTTP server is up
    embedded_command "mozilla" "user [dq]me[dq] detached"
    
  safe
    plugin boot
  failure err
    (var Stream log) open "file:/tmp/embedded_boot.log" out+safe
    log writeline err

export embedded_boot1 embedded_boot2 wait_for_tcp_port