Difference between revisions of "Ide-detect.pl"

From Organic Design wiki
(No difference)

Revision as of 02:30, 4 January 2006

  1. !/usr/bin/perl -w
  1. Script to detect and auto-install the OS image
  2. on an ide disk connected to the system.

use strict; my $bb = "/bin/busybox"; my %disks; my @list = split /^/, `ls /proc/ide`;

  1. get list of connected devices

foreach my $file (@list) { if ($file =~ m/^(hd[a-d])/) { chomp $file; # filter for type=disk (ignore cdrom) if ( `cat /proc/ide/$file/media` =~ m/^disk/ ) { # construct a hash with the devices as keys $disks{$file}{'device'} = "/dev/$file\n"; $disks{$file}{'model'} = `cat /proc/ide/$file/model`; } } }

print $disks{hda}{device}; print "You are about to install the Peer OS onto the hard disk of your computer.\n"; print "This installer will ERASE ALL DATA on the target hard drive.\nIf this is not your intention or you do not understand what this means reply NO.\nIf you want to go ahead and initalise the hard drive, reply yes.\n\n"; print "Do you realy want to install? ";

  1. my $answer = <>;
  1. if (!grep /^y/i, $answer) { print "Aborting. Your disks were not modified.\n"; exit; }
  1. if ( keys( %disks ) > 1 ) {
  2. print "\nMultiple hard drives detected:";
  3. my @disks = keys %disks;
  4. foreach (@disks) {
  5. print "$_\n: model ${$_}{'model'}\n";
  6. }
  7. }

print "Initialising filesystem on hda\n";

system "mkfs";

  1. system "mount /dev/hda /install -t devfs";