]> git.pld-linux.org Git - packages/grub2.git/blob - grub-rebootin.awk
- proper handling of APPEND
[packages/grub2.git] / grub-rebootin.awk
1 #!/bin/awk -f
2
3 BEGIN {
4         menu = "/boot/grub/menu.lst"
5         once = "/boot/grub/menu.once"
6
7         if ((getline < menu) > 0)
8                 close(menu)
9         else {
10                 print "grub is not installed (" menu " is missing)"
11                 exit 1
12         }
13         nrentries = 0
14         altconfig = 0
15         while (getline < menu) {
16                 if ( /^title[ \t]+/ ) {
17                         gsub(/^title[ \t]+/,"")
18                         entries[nrentries] = $0
19                         nrentries++
20                 }
21                 if ( /^altconfigfile[ \t]+.*grub\/menu\.once/ )
22                         altconfig = 1
23         }
24         if ( !altconfig ) {
25                 print "rebootin is of no use without altconfigfile"
26                 exit 2
27         }
28         if ( !nrentries ) {
29                 print "bad menu.lst (no entry found)"
30                 exit 3
31         }
32         if ( ARGC != 2 ) {
33                 print "usage: rebootin <label>\n  where <label> is one of "
34                 for (n = 0 ; n < nrentries ; n++)
35                         print " " entries[n]
36                 exit 4
37         }
38
39         for (n = 0 ; n < nrentries ; n++)
40                 if ( ARGV[1] == entries[n] ) {
41                         dflt = "default " n
42                         print dflt "\ntimeout 0\n" > once
43                         close(once)
44                         getline be_safe < once
45                         if ( be_safe != dflt ) {
46                                 print "can't write rebootin file (" once "), verify the rights"
47                                 exit 666
48                         }
49                         system("/sbin/shutdown -r now")
50                         print "dupa"
51                 }
52
53         print "\"" ARGV[1] "\" not found"
54 }
This page took 0.05357 seconds and 3 git commands to generate.