Archive for May 28th, 2006
Random GRUB Splash Image Selection - a Python Script
Before the script there are two warnings, we all know booting is no kidding:
1. Make sure your GRUB splashimage configuration is compatible to the one introduced in my previous blog entry. My script may crash your boot procedure… or much less severely, garble your screen.
2. Check *EVERY* images you plan to use before the random selection ever takes place, this could be done by entering “ctrl C” at the boot screen, and use some GRUB commands to browse the splashimage directories and try them out.
Ok, let’s go on, here is the random splash python script:
———-START OF SCRIPT ————-
#!/usr/bin/python
import os
import commands
import string
from random import choice
GRUB_PATH = '/boot/grub/'
IMG_LNK = 'splash.xpm.gz'
IMG_PATH = '../images/' #Relative path!
curr_dir = os.getcwd()
os.chdir(GRUB_PATH)
img_str = commands.getoutput(''.join(('ls ',IMG_PATH)))
img_lst = []
while len(img_str):
try:
idx = img_str.index('\n')
img_lst.append(img_str[:idx].strip())
img_str = img_str[idx+1:]
except ValueError:
img_lst.append(img_str.strip())
img_str = ''
img_cand = choice(img_lst)
print "The splash image chosen for next boot is %s" % img_cand
if commands.getoutput(''.join(('ln -s -f ', IMG_PATH, img_cand, ' ', IMG_LNK))):
"Something Wrong while setting the new splashimage!"
else: print "New splashimage set, enjoy!"
os.chdir(curr_dir)
———-END OF SCRIPT ————-
You may want to add it to your startup script so each reboot will bring a little surprise
This piece of code has been tested on Kubuntu Dapper, you should try at your own risk. Good Luck.
Add comment May 28, 2006