From 91d141dc316d28274ec9aa68cd12a32988182b00 Mon Sep 17 00:00:00 2001 From: 1337kid <45532566+1337kid@users.noreply.github.com> Date: Thu, 11 Jan 2024 20:29:05 +0530 Subject: [PATCH 1/2] Bug fixes & remove theme feat. --- NoiceGRUB.py | 10 ++++++++-- noicegrub/__init__.py | 11 ++++++++++- scripts/functions.sh | 24 ++++++++++++++++++++++++ scripts/install.sh | 25 ++++--------------------- scripts/remove.sh | 23 +++++++++++++++++++++++ 5 files changed, 69 insertions(+), 24 deletions(-) create mode 100755 scripts/functions.sh create mode 100755 scripts/remove.sh diff --git a/NoiceGRUB.py b/NoiceGRUB.py index 9b38921..8daea67 100644 --- a/NoiceGRUB.py +++ b/NoiceGRUB.py @@ -11,17 +11,24 @@ from rich.panel import Panel import os +init() console = Console() richprint(Panel("[cyan bold]" + banner + "[/cyan bold]",width=65,border_style="cyan")) table,preset_dict = preset_table() console.print(table) richprint("[cyan bold][ 0 ][/cyan bold] [green bold]Instructions for creating a preset[/green bold]") +richprint("[cyan bold][ 99 ][/cyan bold] [green bold]Remove installed NoiceGRUB theme[/green bold]") -choice = IntPrompt.ask("[yellow]Choice[/yellow]",choices=[str(i) for i in range(len(preset_dict)+1)]) +choice = IntPrompt.ask("[yellow]Choice[/yellow]",choices=gen_choices(preset_dict)) if choice == 0: console.print(Markdown(open('noicegrub/createpreset.md').read())) exit() +elif choice == 99: + richprint('\n[green bold]Executing scripts/remove.sh ... [/green bold]') + os.system('sudo ./scripts/remove.sh') + richprint('[green bold]Done[/green bold]') + exit() print() preset = get_preset(preset_dict[choice]) @@ -50,6 +57,5 @@ choice = Confirm.ask("[yellow bold]Would you like to install the theme ?[/yellow bold]") if choice: richprint('\n[green bold]Executing scripts/install.sh ... [/green bold]') - os.system('chmod +x ./scripts/install.sh') os.system('sudo ./scripts/install.sh') richprint('[green bold]Done[/green bold]') \ No newline at end of file diff --git a/noicegrub/__init__.py b/noicegrub/__init__.py index ce4b66b..d9240a7 100644 --- a/noicegrub/__init__.py +++ b/noicegrub/__init__.py @@ -5,6 +5,15 @@ def get_preset(name): data=toml.load(open(f'./presets/{name}.toml')) return [data[i] for i in data] +def gen_choices(presetDict): + ch_list = [str(i) for i in range(len(presetDict)+1)] + ch_list.append('99') + return ch_list + +def init(): + os.system('chmod +x ./scripts/functions.sh') + os.system('chmod +x ./scripts/install.sh') + os.system('chmod +x ./scripts/remove.sh') #================= rich tables def preset_table(): @@ -56,4 +65,4 @@ def gen_font_name(font_name,size): 8 `b8 8 8 8 8 . 8. 8 8 8 8 8 8 8 8 8 `8 `YooP' 8 `YooP' `Yooo' `YooP8 8 8 `YooP' 8oooP' ..:::..:.....::..:.....::.....::....8 :..:::..:.....::......: -:::::::: @1337kid ::::::::::::::::::8 :::::::: v2.0 :::::::::\n''' \ No newline at end of file +:::::::: @1337kid ::::::::::::::::::8 :::::::: v2.0.1 :::::::\n''' \ No newline at end of file diff --git a/scripts/functions.sh b/scripts/functions.sh new file mode 100755 index 0000000..63d12f7 --- /dev/null +++ b/scripts/functions.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +update_grub_func() { + if [[ $(which dnf) != "" ]];then + fedora_version=$(cat /etc/fedora-release | awk '{print $3}') + if [[ fedora_version -gt 34 ]];then + grub2-mkconfig -o /boot/grub2/grub.cfg + else + grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg + fi + else + update-grub + fi +} + +get_path() { + if [[ -d "/boot/grub2" ]]; then + GRUB_PATH='/boot/grub2/' + elif [[ -d "/boot/grub" ]]; then + GRUB_PATH='/boot/grub/' + elif [[ -d "/boot/efi/EFI/fedora" ]]; then + GRUB_PATH='/boot/efi/EFI/fedora/' + fi +} diff --git a/scripts/install.sh b/scripts/install.sh index 98dd034..c14e2d0 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -1,17 +1,9 @@ #!/bin/bash GRUB_PATH='' -THEMES_PATH='' +THEME_PATH='' -get_path() { - if [[ -d "/boot/grub2" ]]; then - GRUB_PATH='/boot/grub2/' - elif [[ -d "/boot/grub" ]]; then - GRUB_PATH='/boot/grub/' - elif [[ -d "/boot/efi/EFI/fedora" ]]; then - GRUB_PATH='/boot/efi/EFI/fedora/' - fi -} +source ./scripts/functions.sh makefont() { font=$(ls ./export | grep -E '.ttf|.otf') @@ -42,16 +34,7 @@ install() { #========= GRUB update # printf "\033[92m[+] \033[94mUpdating GRUB config\n\033[92m" - if [[ $(which dnf) != "" ]];then - fedora_version=$(cat /etc/fedora-release | awk '{print $3}') - if [[ fedora_version -gt 34 ]];then - grub2-mkconfig -o /boot/grub2/grub.cfg - else - grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg - fi - else - update-grub - fi + update_grub_func } #========================= @@ -75,5 +58,5 @@ fi get_path THEME_PATH=$GRUB_PATH"themes/noicegrub" printf "\033[1m\033[93m" -echo "Generated theme will be placed in $THEMES_PATH" +echo "Generated theme will be placed in $THEME_PATH" install \ No newline at end of file diff --git a/scripts/remove.sh b/scripts/remove.sh new file mode 100755 index 0000000..6a19cf6 --- /dev/null +++ b/scripts/remove.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +GRUB_PATH='' + +if [[ $(id -u) != "0" ]] +then + printf "\033[91mCurrent user does not have root perms\n" + exit +fi + +source ./scripts/functions.sh + +printf "\033[1m" +get_path +THEME_PATH=$GRUB_PATH"themes/noicegrub" +printf "\033[92m[+] \033[94mRemoving NoiceGRUB theme\n\033[92m" +rm -rf $THEME_PATH 2>/dev/null +#===== grub config +sed -i 's/.*GRUB_THEME=.*//' /etc/default/grub +sed -i 's/.*GRUB_FONT=.*//' /etc/default/grub +#===== +printf "\033[92m[+] \033[94mUpdating GRUB config\n\033[92m" +update_grub_func \ No newline at end of file From e06e8356b7fc5e9655536465f2b1910b61fc2e5c Mon Sep 17 00:00:00 2001 From: 1337kid <45532566+1337kid@users.noreply.github.com> Date: Thu, 11 Jan 2024 20:44:02 +0530 Subject: [PATCH 2/2] check_uid function --- scripts/functions.sh | 8 ++++++++ scripts/install.sh | 7 +------ scripts/remove.sh | 7 +------ 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/scripts/functions.sh b/scripts/functions.sh index 63d12f7..5b0b302 100755 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -1,5 +1,13 @@ #!/bin/bash +check_uid() { + if [[ $(id -u) != "0" ]] + then + printf "\033[91mCurrent user does not have root perms\n" + exit + fi +} + update_grub_func() { if [[ $(which dnf) != "" ]];then fedora_version=$(cat /etc/fedora-release | awk '{print $3}') diff --git a/scripts/install.sh b/scripts/install.sh index c14e2d0..5c4cdcb 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -49,12 +49,7 @@ cat <