#!/usr/bin/perl
#You must have the USB filesystem enabled to use UPDD.\nDo you want UPDD to try to enable it?


open XC, "</etc/rc.local";
$flag = 0;
while($test = <XC>) {
  $test=~s/^\s+//;
  $test=~s/\s+$//;
  if($test eq "# UPDD USBFS") {
    $flag = 1;
  }
}
close(XC);

if ($flag == 0) {
open XIN, "</etc/rc.local";
open XOUT, ">/etc/rc.local.new";

while($buf = <XIN>) {
  $buf2 = $buf;
  $buf=~s/^\s+//;
  $buf=~s/\s+$//;

  if($buf eq "# By default this script does nothing.") {
print XOUT $buf2;    
print XOUT "# UPDD USBFS\n";
print XOUT "mkdir -p /dev/bus/usb/.usbfs\n";
print XOUT "mount -n -t usbfs usbfs /dev/bus/usb/.usbfs -obusmode=0700,devmode=0600,listmode=0644\n";
print XOUT "ln -sf .usbfs/devices /dev/bus/usb/devices\n";
print XOUT "mount --rbind /dev/bus/usb /proc/bus/usb\n";
  }
  else {
    print XOUT $buf2;
  }
}

`mv /etc/rc.local.new /etc/rc.local`;
`chmod 755 /etc/rc.local`;
}
