diff --git a/install.sh b/GReza old mode 100755 new mode 100644 similarity index 79% rename from install.sh rename to GReza index b4369a3..bf46124 --- a/install.sh +++ b/GReza @@ -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/ @@ -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 @@ -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 diff --git a/ImgResize.java b/ImgResize.java new file mode 100644 index 0000000..ce848a1 --- /dev/null +++ b/ImgResize.java @@ -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; + } +} diff --git a/README.md b/README.md index d7fcf99..827a63c 100644 --- a/README.md +++ b/README.md @@ -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 ` 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 diff --git a/TextToGraphics.java b/TextToGraphics.java new file mode 100644 index 0000000..8404fb0 --- /dev/null +++ b/TextToGraphics.java @@ -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