-
Notifications
You must be signed in to change notification settings - Fork 16
/
grub.py
108 lines (89 loc) · 3.12 KB
/
grub.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# Liza feat. Lord Osiris
# GrubScript ver 0.2
import sys
import os
import commands
#trunk = commands.getoutput("cat .svn/entries | head -n 4 | tail -n 1")
trunk = "-svn"
patchlevel = commands.getoutput("cat include/version.h | grep PATCHLEVEL | cut -b 21-23")
if os.getuid() != 0:
print "[-] You need to run this install script as root!"
sys.exit(1)
def grub_hd(pn):
letter = pn[2]
nump = int(pn[3]) - 1
alphanum = { 'a':0, 'b':1, 'c':2, 'd':3, 'e':4, 'f':5 }
res = "(hd" + str(alphanum[letter]) + "," + str(nump) + ")"
return res
def sub_mount(mp, cwd):
count = 0
for x in mp:
if mp[count] == cwd[count]:
count+=1
return cwd[count:]
# Manca il controllo errori
fd = open("/boot/grub/menu.lst", "a")
print "Insert the source partition (ex. hda2):",
pn = raw_input()
partition = grub_hd(pn)
print "Insert the mountpoint:",
mp = raw_input()
cwd = os.getcwd() + "/dreamos.img"
initFS = os.getcwd() + "/initfs"
if mp == "/":
path = cwd
else:
cwd = sub_mount(mp, cwd)
print "Do you want the DreamOS splash in your grub? (y/n):",
answer2 = raw_input()
if answer2 == 'y':
os.system("su -c 'cp boot/grub2.xpm.gz /boot/grub/grub2.xpm.gz'")
print "+--------------------------- INFO ------------------------------+"
print "| splashimage=" + partition + "/boot/grub/grub2.xpm.gz |"
print "| Title: DreamOS v0." + patchlevel + "-" + trunk +" |"
print "| Root: " + partition + " |"
print "| Kernel: " + cwd +" |"
print "| Module: " + initFS +" |"
print "+---------------------------------------------------------------+"
print "Proceed to the writing? (y/n):",
answer = raw_input()
if answer == 'y':
fd.write("\nsplashimage=" + partition + "/boot/grub/grub2.xpm.gz\n\n")
fd.write("\ntitle\tDreamOS v0." + patchlevel + "-" + trunk +"")
fd.write("\nroot\t" + partition)
fd.write("\nkernel\t" + cwd + "\nmodule\t" + initFS)
fd.write("\nboot\n")
fd.close()
print ""
print "Changes added to /boot/grub/menu.lst: "
print "\n+title\tDreamOS trunk"
print "+root\t" + partition
print "+kernel\t" + cwd
print "+boot\n"
print "[+] Done."
elif answer == 'n':
print "Ok, aborting."
elif answer2 == 'n':
print "+--------------------------- INFO ------------------------------+"
print "| Title: DreamOS v0." + patchlevel + "-" + trunk +" |"
print "| Root: " + partition + " |"
print "| Kernel: " + cwd +" |"
print "| Module: " + initFS +" |"
print "+---------------------------------------------------------------+"
print "Proceed to the writing? (y/n):",
answer3 = raw_input()
if answer3 == 'y':
fd.write("\ntitle\tDreamOS v0." + patchlevel + "-" + trunk +"")
fd.write("\nroot\t" + partition)
fd.write("\nkernel\t" + cwd + "\nmodule\t" + initFS)
fd.write("\nboot\n")
fd.close()
print ""
print "Changes added to /boot/grub/menu.lst: "
print "\n+title\tDreamOS trunk"
print "+root\t" + partition
print "+kernel\t" + cwd
print "+boot\n"
print "[+] Done."
elif answer3 == 'n':
print "Ok, aborting."