Skip to content

Commit

Permalink
Merge experimental fedora-support into master
Browse files Browse the repository at this point in the history
  • Loading branch information
mateosss committed Sep 28, 2020
2 parents 1668e8d + 7e70cc0 commit 23f35f4
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 52 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ help.

## Quick Start

*Note for Fedora users: Matter does not yet support [The Boot Loader
Specification](https://systemd.io/BOOT_LOADER_SPECIFICATION/) so before executing
`matter.py` you should set `GRUB_ENABLE_BLSCFG="false"` in `/etc/default/grub` and then
update your grub file with `sudo grub2-mkconfig -o /boot/grub2/grub.cfg`*

Following is a Matter installation with default values. Don't worry, it is very
easy to rollback or overwrite this installation later if you wan't to.

Expand Down
4 changes: 4 additions & 0 deletions grub.template
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
GRUB_THEME={installation_dir}/theme.txt
GRUB_GFXMODE=1920x1080,auto

# Fedora specific fixes
GRUB_ENABLE_BLSCFG=false
GRUB_TERMINAL_OUTPUT=""
111 changes: 59 additions & 52 deletions matter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,55 @@
"Matter is a minimalist grub theme originally inspired by material design 2.\n"
"Run this script without arguments for next steps on installing Matter."
)

# Logging utils

def color_string(string, fg=None):
COLORS = { # List some colors that may be needed
"red": "\033[31m",
"green": "\033[32m",
"orange": "\033[33m",
"blue": "\033[34m",
"cyan": "\033[36m",
"lightred": "\033[91m",
"lightgreen": "\033[92m",
"yellow": "\033[93m",
"lightblue": "\033[94m",
"lightcyan": "\033[96m",
}
endcolor = "\033[0m"
return f"{COLORS.get(fg, '')}{string}{endcolor}"


def info(*lines):
for line in lines:
print(f"{color_string('[I] ', fg='cyan')}{line}")


def error(*lines, should_exit=True):
for line in lines:
print(f"{color_string('[E] ', fg='lightred')}{line}")
if should_exit:
exit(1)


def warning(*lines):
for line in lines:
print(f"{color_string('[W] ', fg='yellow')}{line}")


if exists("/boot/grub"):
BOOT_GRUB_PATH = "/boot/grub"
elif exists("/boot/grub2"):
BOOT_GRUB_PATH = "/boot/grub2"
else:
error("Could not find your grub's boot path (tried /boot/grub and /boot/grub2)")

INSTALLER_ABSPATH = os.path.abspath(__file__)
INSTALLER_NAME = basename(INSTALLER_ABSPATH)
INSTALLER_DIR = dirname(INSTALLER_ABSPATH)
INSTALLATION_SOURCE_DIR = f"{INSTALLER_DIR}/{THEME_NAME}"
INSTALLATION_TARGET_DIR = f"/boot/grub/themes/{THEME_NAME}"
INSTALLATION_TARGET_DIR = f"{BOOT_GRUB_PATH}/themes/{THEME_NAME}"

THEME_DEFAULT_HIGHLIGHT = "pink"
THEME_DEFAULT_FOREGROUND = "white"
Expand All @@ -34,8 +78,11 @@
THEME_DEFAULT_FONT_SIZE = 32

GRUB_DEFAULTS_PATH = f"/etc/default/grub"
GRUB_CFG_PATH = f"/boot/grub/grub.cfg"
GRUB_MKCONFIG_PATH = which("grub-mkconfig")
GRUB_CFG_PATH = f"{BOOT_GRUB_PATH}/grub.cfg"
GRUB_MKCONFIG_PATH = which("grub-mkconfig") or which("grub2-mkconfig")
if GRUB_MKCONFIG_PATH is None:
error("Could not find grub-mkconfig command file (grub2-mkconfig neither)")


THEME_TEMPLATE_PATH = f"{INSTALLER_DIR}/theme.txt.template"
GRUB_DEFAULTS_TEMPLATE_PATH = f"{INSTALLER_DIR}/grub.template"
Expand Down Expand Up @@ -83,40 +130,6 @@
# Utils


def color_string(string, fg=None):
COLORS = { # List some colors that may be needed
"red": "\033[31m",
"green": "\033[32m",
"orange": "\033[33m",
"blue": "\033[34m",
"cyan": "\033[36m",
"lightred": "\033[91m",
"lightgreen": "\033[92m",
"yellow": "\033[93m",
"lightblue": "\033[94m",
"lightcyan": "\033[96m",
}
endcolor = "\033[0m"
return f"{COLORS.get(fg, '')}{string}{endcolor}"


def info(*lines):
for line in lines:
print(f"{color_string('[I] ', fg='cyan')}{line}")


def error(*lines, should_exit=True):
for line in lines:
print(f"{color_string('[E] ', fg='lightred')}{line}")
if should_exit:
exit(1)


def warning(*lines):
for line in lines:
print(f"{color_string('[W] ', fg='yellow')}{line}")


def sh(command):
"Executes command in shell and returns its exit status"
return run(command, shell=True).returncode
Expand Down Expand Up @@ -173,9 +186,6 @@ def read_cleaned_grub_defaults():


def read_cleaned_grub_mkconfig():
if GRUB_MKCONFIG_PATH is None:
error("grub-mkconfig command is not present in your system")

# Read previous defaults
with open(GRUB_MKCONFIG_PATH, "r", newline="") as f:
grub_mkconfig = f.read()
Expand Down Expand Up @@ -221,7 +231,7 @@ def convert_icon_svg2png(icon_name):
if not has_command("convert"):
error(
"Stop. The `convert` command from imagemagick was not found",
"Consider installing `inkscape`",
"Also consider installing `inkscape` for the best results",
)
if not has_command("inkscape"):
warning("Resulting icons could look a bit off, consider installing inkscape")
Expand Down Expand Up @@ -321,9 +331,9 @@ def prepare_source_dir():

# Font checks
# grub-mkfont present
grub_mkfont = "grub-mkfont"
if not has_command(grub_mkfont):
error(f"{grub_mkfont} command not found in your system")
grub_mkfont = which("grub-mkfont") or which("grub2-mkfont")
if grub_mkfont is None:
error(f"grub-mkfont command not found in your system (grub2-mkfont neither)")
# Valid font arguments
if fontfile is None: # User did not specify custom font file
fontfile = f"{INSTALLER_DIR}/fonts/{fontkey}.ttf"
Expand Down Expand Up @@ -398,14 +408,11 @@ def copy_source_to_target():


def update_grub_cfg():
COMMAND = "update-grub"
ALT_COMMAND = "grub-mkconfig"
info(f"Update grub.cfg")
command = COMMAND
if not has_command(command):
if not has_command(ALT_COMMAND):
error(f"{COMMAND} and {ALT_COMMAND} command not found in your system")
command = f"{ALT_COMMAND} -o {GRUB_CFG_PATH}"
info("Update grub.cfg")
update_command = which("update-grub") or which("grub-mkconfig") or which("grub2-mkconfig")
if update_command is None:
error(f"Command for generating grub.cfg not found (tried update-grub, grub-mkconfig and grub2-mkconfig)")
command = f"{update_command} -o {GRUB_CFG_PATH}"
info(f"Remake grub.cfg with {command}")
sh(command)

Expand Down

0 comments on commit 23f35f4

Please sign in to comment.