You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

93 lines
2.1 KiB

  1. #!/usr/bin/perl
  2. #
  3. # makedesc directory file
  4. #
  5. # Scan the directory for files, and use the files to generate a task
  6. # description file. The format of the task description file is described in
  7. # tata.c. The format of the input files is:
  8. #
  9. # Task: desktop
  10. # Section: user
  11. # Description: Provide a basic GUI system
  12. # This task provides functionality for a basic desktop; whether Gnome
  13. # based, KDE based or customised. With this task, your system will boot
  14. # into a graphical login screen, at which point you can choose which of
  15. # these desktops you wish to use on a per-user basis. You can further
  16. # customise your desktop once installed.
  17. # Packages:
  18. # kdebase
  19. # gdm
  20. # ...
  21. #
  22. # Hash-comments are allowed in the files, but must be on their own lines.
  23. my $dir=shift or die "no directory specified\n";
  24. my $file=shift or die "no file specified\n";
  25. my %package;
  26. my %notmain;
  27. my $dolint=1;
  28. {
  29. local $/="\n\n";
  30. if (! open (AVAIL, "/var/lib/dpkg/available")) {
  31. warn "cannot real available file, so disabling lint check\n";
  32. $dolint=0;
  33. }
  34. while (<AVAIL>) {
  35. my ($package)=/Package:\s*(.*?)\n/;
  36. $package{$package}=1;
  37. if (/Section:\s*(contrib|non-free)/) {
  38. $notmain{$package}=$1;
  39. }
  40. }
  41. close AVAIL;
  42. }
  43. open (OUT, ">$file") or die ">$file: $!";
  44. use File::Find;
  45. find(\&processfile, $dir);
  46. sub processfile {
  47. my $file=$_; # File::Find craziness.
  48. return unless $file =~ /^[-+_.a-z0-9]+$/ and -f $file;
  49. open (IN, $file) or die "$file: $!";
  50. my %fields;
  51. my $field="";
  52. while (<IN>) {
  53. chomp;
  54. next if /^\s*#/;
  55. s/#.*//;
  56. if (/^\s/) {
  57. $fields{$field}.="\n$_";
  58. }
  59. else {
  60. ($field, my $value)=split(/:\s*/, $_, 2);
  61. $field=lc($field);
  62. $fields{$field}=$value;
  63. }
  64. }
  65. close IN;
  66. # Basic lint of the listed packages.
  67. # TODO: a better lint would incloude checks for conflicting
  68. # packages. Hard tho.
  69. if ($dolint) {
  70. foreach (split ' ', $fields{packages}) {
  71. if (! $package{$_}) {
  72. print STDERR "$file: $_ is not a valid package.\n";
  73. }
  74. if ($notmain{$_}) {
  75. print STDERR "$file: $_ is in $notmain{$_}.\n";
  76. }
  77. }
  78. }
  79. print OUT map { ucfirst($_).": ".$fields{$_}."\n" }
  80. qw{task section description};
  81. print OUT "\n";
  82. }
  83. close OUT;