Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added options for easy customisation #1

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
56 changes: 46 additions & 10 deletions install.sh → GReza
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#! /bin/bash
#!/usr/bin/env bash

set -e

# This script installs the GRUB2 theme in /boot/grub/themes/, /boot/grub2/themes/ or /grub/themes/
Expand Down Expand Up @@ -76,14 +77,35 @@ mkConfig_File=$(which ${Grub_Dir##*/}-mkconfig) || \

# Ask for desired resolution if set to "any"
if [[ $Theme_Resolution = "any" ]]; then
echo ""
echo "Enter desired resolution in the form of 1024x768, 800x600, 1600x1200, etc."
echo "Also, only choose a resolution that is supported by your VESA BIOS Extensions"
echo "which can be found by installing the hwinfo package, and running hwinfo --framebuffer,"
echo "or by running vbeinfo at grub's command line. The outputs may vary."
echo ""
echo -n "Enter desired resolution: "
read Theme_Resolution
Theme_Resolution=$(xdpyinfo | awk '/dimensions/{print $2}')
width=$(echo $Theme_Resolution | awk -Fx '{print $1}')
height=$(echo $Theme_Resolution | awk -Fx '{print $2}')

# syntax to resize -- send width and height as arguments
# to edit the code, make changes in ImgResize.java

java -version
if [ $? -ne 0 ]
then
echo "Java is not installed or not in the system path. Exiting now..."
exit 1
fi

javac ImgResize.java
echo "Enter background image path (Ctrl+Shift+V to paste): "
read path
java ImgResize $width $height "$path"
echo
echo "Enter message text (Use @ for new line): "
read text
echo "Enter text color in RGB (#000000 is black, #FFFFFF is white): "
read color
javac TextToGraphics.java
java TextToGraphics "$text" "$color"
if [ $? -ne 0 ]
then
exit
fi
fi

# Create theme directory. If directory already exists, ask the user if they would like
Expand Down Expand Up @@ -158,6 +180,20 @@ if [[ $Response = yes || $Response = y ]]; then
sed "s,^#\?GRUB_THEME=.*,GRUB_THEME=$Theme_Dir/$Theme_Definition_File," <$Grub_File >$Grub_File.~
mv $Grub_File.~ $Grub_File
fi
$($mkConfig_File -o $Grub_Dir/grub.cfg) # Generate new grub.cfg
$($mkConfig_File -o $Grub_Dir/grub.cfg) # Generate new grub.cfg

# to add icons to Advanced menu and System setup
chmod -R 644 /boot/grub/grub.cfg
sed -i -e "s/submenu \(.*\)\$menu/submenu \1 --class submenu \$menu/g" /boot/grub/grub.cfg
sed -i "s/menuentry 'System setup'/menuentry 'System setup' --class settings/g" /boot/grub/grub.cfg
echo
echo "New Grub Theme added. Changes will apply on reboot."
echo "Do you want to reboot now? Enter Yes to reboot."
read reboot_response
if [ "$reboot_response" = "Yes" ]
then
reboot
fi

fi
exit 0
45 changes: 45 additions & 0 deletions ImgResize.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.awt.Image;
import java.net.*;

public class ImgResize {

public static void main(String args[]) {

int width = Integer.parseInt(args[0]);
int height = Integer.parseInt(args[1]);
String path = args[2];

BufferedImage newImage;
Image image;

try {
if (path.substring(0, 4).equals("http")) {
URL url = new URL(path);
image = ImageIO.read(url);
} else {
File file = new File(path);
image = ImageIO.read(file);
}
newImage = getScaledImage(image, width, height);
File outputfile = new File("background.png");
ImageIO.write(newImage, "png", outputfile);
System.exit(0);
} catch (IOException e) {
System.out.println("Image could not be found / resized");
System.exit(1);
}
}

private static BufferedImage getScaledImage(Image srcImg, int w, int h) {
BufferedImage resizedImg = new BufferedImage(w, h, Transparency.TRANSLUCENT);
Graphics2D g2 = resizedImg.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2.drawImage(srcImg, 0, 0, w, h, null);
g2.dispose();
return resizedImg;
}
}
39 changes: 33 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
# GReza
A GRUB theme.
A GRUB theme customization App for Linux

Find out the resolution grub supports:
- `hwinfo --framebuffer`
- At grub commandline (pressing `C` at grub menu): `vbeinfo`
**Requirements:**
Java

To name an icon for display in the grub menu, you need to know the distro class name.
`menuentry "Gentoo" --class **gentoo** --class os...`
**To use this app, enter the following commands in your terminal:**
```
git clone https://github.com/AseedUsmani/GReza.git
cd GReza
sudo ./GReza
```

**Tips on customization:**
1) The script will ask for an image path, it can be an internet URL or a local path.
2) The color of the custom message you enter is in RGB, where `#FFFFFF` is white and `#000000` is black. Enter a blank message (space) to remove the image.
3) The bootloader images (background and selected) are determined by `select_bkg_*.png` and `select_bg_*.png`; where c stands for center, n, ne, s etc stands for North, North-East, South etc. Same rule applies to terminal background.
4) You can edit theme.txt for further customization.
5) To change the order or the names of the menu items in bootloader, edit `/boot/grub/grub.cfg`.
6) In case an icon is missing, add `--class <icon_name>` to the line containing the menu item. For example:
`submenu 'Advanced menu for Ubuntu' --class submenu`... will put the image file `submenu` as the icon of this item. To put your icons, copy the image file in `./GReza/icons` directory.

**Files you can consider editing**
1) ImgResize.java
2) TextToGraphics.java
3) GReza
4) theme.txt
5) `/boot/grub/grub.cfg`
Please be cautious while editing `grub.cfg`.

PS: You do not need to recompile `.java` files in order to see changes.

# Preview
![Preview](https://i.imgur.com/8LPgmMD.jpg)

**Credits:** https://github.com/safiyat/GReza
63 changes: 63 additions & 0 deletions TextToGraphics.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

public class TextToGraphics {

public static void main(String[] args) {
String color = args[1];
String[] text = args[0].split("@", 0);
int lines = text.length;
int red = Integer.parseInt(color.substring(1, 3), 16);
int green = Integer.parseInt(color.substring(3, 5), 16);
int blue = Integer.parseInt(color.substring(5, 7), 16);

/*
Because font metrics is based on a graphics context, we need to create
a small, temporary image so we can ascertain the width and height
of the final image
*/
BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = img.createGraphics();
Font font = new Font("Arial", Font.PLAIN, 48);
g2d.setFont(font);
FontMetrics fm = g2d.getFontMetrics();
int width=fm.stringWidth("");
for (int i = 0; i < lines; i++) {
if(width<fm.stringWidth(text[i])) width=fm.stringWidth(text[i]);
}
int height = fm.getHeight() * lines;
g2d.dispose();

img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
g2d = img.createGraphics();
g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
g2d.setFont(font);
fm = g2d.getFontMetrics();
g2d.setColor(new Color(red, green, blue));
for (int i = 1; i<=lines; i++) {
g2d.drawString(text[i-1], 0, fm.getAscent()*i);
}
g2d.dispose();
try {
ImageIO.write(img, "png", new File("info.png"));
} catch (IOException ex) {
ex.printStackTrace();
}

}

}
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
theme: jekyll-theme-minimal
Binary file removed background.png
Binary file not shown.
Binary file added icons/settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified icons/submenu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed info.png
Binary file not shown.
Binary file removed info1.png
Binary file not shown.
Binary file removed info2.png
Binary file not shown.
Binary file removed info3.png
Binary file not shown.
Binary file removed info4.png
Binary file not shown.
Binary file modified menu_bkg_c.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified menu_bkg_e.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified menu_bkg_n.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified menu_bkg_ne.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified menu_bkg_nw.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified menu_bkg_s.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified menu_bkg_se.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified menu_bkg_sw.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified menu_bkg_w.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions theme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ terminal-font: "Fixed Regular 13"

# Show the boot menu
+ boot_menu {
left = 0
left = 10
width = 50%
top = 0
height = 100%
Expand All @@ -27,11 +27,11 @@ terminal-font: "Fixed Regular 13"
item_color = "#f5f5f5"
selected_item_color = "#333333"
item_height = 56
item_padding = 0
item_spacing = 20
icon_width = 48
icon_height = 48
item_icon_space = 20
item_padding = 100
item_spacing = 10
icon_width = 36
icon_height = 36
item_icon_space = 15
selected_item_pixmap_style= "select_bkg_*.png"
menu_pixmap_style = "menu_bkg_*.png"
scrollbar = false
Expand Down