Patch title: Release 89 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/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 nobody (cast 65534 Int)
constant reconfigure_printers true


function embedded_command cmd user uid gid detached -> err
  arg Str cmd user ; arg Int uid gid ; arg CBool detached ; arg Int err
  var Str env := "PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/X11R6/bin[0]"
  env += "DISPLAY=:0[0]"
  env += "USER="+user+"[0]"
  env += "HOME="+(shunt user<>"root" "/home" "")+"/"+user+"[0]"
  # if this_computer:env:"pliant":"identity":"language"<>""
  #   env += "LANG="+this_computer:env:"pliant":"identity":"language"+"[0]"
  if detached
    err := execute cmd root "embedded:/" path "embedded:/" user uid group gid environment env detached
  else
    err := execute cmd root "embedded:/" path "embedded:/" user uid group gid environment env
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_command cmd user detached -> err
  arg Str cmd user ; arg CBool detached ; arg Int err
  err := embedded_command cmd user (shunt user="root" undefined user="daemon" 1 user="lp" 7 user="me" 4096 nobody) (shunt user="root" undefined user="daemon" 1 user="lp" 7 user="me" 100 nobody) detached


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" "root" false
  embedded_command "ldconfig" "" # SECURITY

  # update modules
  file_extract "file:/boot/modules.tgz" "embedded:/"
  embedded_command "depmod -a" "root" false
  embedded_command "depmod -a" "" # SECURITY
     
  # overwrite cdrecord
  if (file_query "file:/bin/cdrecord" standard)=defined
    # we need a patched cdrecord in FullPliant system
    file_copy "embedded:/usr/bin/cdrecord" "file:/bin/cdrecord" extended+lazy
    file_copy "embedded:/usr/bin/mkisofs" "file:/bin/mkisofs" extended+lazy

  # start PCMCIA
  if c:env:"kernel":"make":"CONFIG_PCMCIA"="y"
    embedded_command "/etc/init.d/pcmcia start" "root" false
  if false # c:env:"kernel":"make":"CONFIG_PCMCIA"="y"
    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/"+c:env:"hardware":"keyboard":"layout" "root" false
  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"
    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
        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/")
    embedded_command "modprobe parport_pc" "root" false
    embedded_command "modprobe lp" "root" false
    embedded_command "lpd" "root" false
    execute "insmod parport"
    execute "insmod parport_pc"
    execute "insmod 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 (replace c:env:"hardware":"mouse":"linux_device" "device:/" "embedded:/dev/")
  kernel_make_device "embedded:/dev/fb0"
  if xdriver="i810"
    kernel_make_device "embedded:/dev/agpgart"
    execute "insmod agpgart"
  if xserver<>"" and (file_query "embedded:/usr/X11R6/bin/"+xfree3_exe standard)=success
    # Free 3
  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 "root" true
    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
    embedded_command "XFree86" "root" true
    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
  part x_setup
    for (var Int i) 1 15
      if (embedded_command "xhost +local:" "root" false)=0
        leave x_setup
      sleep 1
  if x11<>"none"
    wait_for_tcp_port "127.0.0.1" 6000 15
    embedded_command "xhost +local:" "" # SECURITY
  # start windows manager
  embedded_command c:env:"debian":"x11":"windows_manager" "me" true
  if true
    embedded_command "xmodmap -e 'keycode 24 = a A acircumflex adiaeresis'" "root" false
    embedded_command "xmodmap -e 'keycode 26 = e E ecircumflex ediaeresis'" "root" false
    embedded_command "xmodmap -e 'keycode 31 = i I icircumflex idiaeresis'" "root" false
    embedded_command "xmodmap -e 'keycode 32 = o O ocircumflex odiaeresis'" "root" false
    embedded_command "xmodmap -e 'keycode 30 = u U ucircumflex udiaeresis'" "root" false
    embedded_command "xmodmap -e 'keycode 34 = Mode_switch'" "root" false
  embedded_command "xsetroot -solid #407060" "root" false
  sleep 5
  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"
    embedded_command "xsetroot -solid #407060" "" # SECURITY

  # xterm devices
  if (file_query "embedded:/dev/ptya0" standard)=undefined
    execute "/dev/MAKEDEV pty" root "embedded:/" path "embedded:/dev/"

  # xbiff mail received warner
  if c:env:"pliant":"mail":"pop3_provider"<>""
    embedded_command "xbiff2" "me" true
  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"
  # embedded_command "netscape" "me" true
  if false # rather use Mozilla
    embedded_command "netscape" "user [dq]me[dq] detached"

  # mozilla
  embedded_command "mozilla" "me" true
  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_command embedded_boot1 embedded_boot2
export embedded_boot1 embedded_boot2 wait_for_tcp_port