From d567f45628e2baf90d86a4df811d8c6da47b5257 Mon Sep 17 00:00:00 2001 From: hesam-init Date: Wed, 10 Jul 2024 19:50:33 +0330 Subject: [PATCH] refactor: setup script --- .scripts/app-installer/nekoray.sh | 2 +- .scripts/setup/fonts-installer.sh | 17 ------ .scripts/utils/{helpers.sh => _links.sh} | 4 +- .scripts/utils/{main.sh => init.sh} | 0 host/ui/fonts/{ => TTF}/GrapeNuts-Regular.ttf | Bin host/ui/fonts/{ => TTF}/Icomoon-Feather.ttf | Bin .../{ => TTF}/Iosevka-Nerd-Font-Complete.ttf | Bin .../JetBrains-Mono-Nerd-Font-Complete.ttf | Bin .scripts/setup/pkgs-installer.sh => setup.sh | 51 ++++++++++++++---- stow.sh | 32 +++++------ 10 files changed, 59 insertions(+), 47 deletions(-) delete mode 100755 .scripts/setup/fonts-installer.sh rename .scripts/utils/{helpers.sh => _links.sh} (96%) rename .scripts/utils/{main.sh => init.sh} (100%) rename host/ui/fonts/{ => TTF}/GrapeNuts-Regular.ttf (100%) rename host/ui/fonts/{ => TTF}/Icomoon-Feather.ttf (100%) rename host/ui/fonts/{ => TTF}/Iosevka-Nerd-Font-Complete.ttf (100%) rename host/ui/fonts/{ => TTF}/JetBrains-Mono-Nerd-Font-Complete.ttf (100%) rename .scripts/setup/pkgs-installer.sh => setup.sh (82%) diff --git a/.scripts/app-installer/nekoray.sh b/.scripts/app-installer/nekoray.sh index bee11ca..d112b75 100755 --- a/.scripts/app-installer/nekoray.sh +++ b/.scripts/app-installer/nekoray.sh @@ -1,6 +1,6 @@ #!/bin/bash -source ../utils/main.sh +source ../utils/init.sh DOWNLOAD_URL="https://github.com/MatsuriDayo/nekoray/releases/download/3.26/nekoray-3.26-2023-12-09-linux64.zip" FILE_NAME="nekoray.zip" diff --git a/.scripts/setup/fonts-installer.sh b/.scripts/setup/fonts-installer.sh deleted file mode 100755 index f0f97f4..0000000 --- a/.scripts/setup/fonts-installer.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -source ../utils/main.sh - -FONTS_DIR="../configs/host/ui/fonts" - -install_ttf_fonts() { - sudo cp *.ttf /usr/share/fonts/TTF - sudo fc-cache -f -v - - log "Fonts installed successfully!" -} - -check_sudo - -cd $FONTS_DIR -install_ttf_fonts diff --git a/.scripts/utils/helpers.sh b/.scripts/utils/_links.sh similarity index 96% rename from .scripts/utils/helpers.sh rename to .scripts/utils/_links.sh index 20e2ef8..d700c7e 100755 --- a/.scripts/utils/helpers.sh +++ b/.scripts/utils/_links.sh @@ -1,6 +1,6 @@ #!/bin/bash -create_symlinks() { +create_links() { local source_dir=$1 local target_dir=$2 @@ -17,7 +17,7 @@ create_symlinks() { done } -delete_symlinks() { +delete_links() { local source_dir=$1 local target_dir=$2 diff --git a/.scripts/utils/main.sh b/.scripts/utils/init.sh similarity index 100% rename from .scripts/utils/main.sh rename to .scripts/utils/init.sh diff --git a/host/ui/fonts/GrapeNuts-Regular.ttf b/host/ui/fonts/TTF/GrapeNuts-Regular.ttf similarity index 100% rename from host/ui/fonts/GrapeNuts-Regular.ttf rename to host/ui/fonts/TTF/GrapeNuts-Regular.ttf diff --git a/host/ui/fonts/Icomoon-Feather.ttf b/host/ui/fonts/TTF/Icomoon-Feather.ttf similarity index 100% rename from host/ui/fonts/Icomoon-Feather.ttf rename to host/ui/fonts/TTF/Icomoon-Feather.ttf diff --git a/host/ui/fonts/Iosevka-Nerd-Font-Complete.ttf b/host/ui/fonts/TTF/Iosevka-Nerd-Font-Complete.ttf similarity index 100% rename from host/ui/fonts/Iosevka-Nerd-Font-Complete.ttf rename to host/ui/fonts/TTF/Iosevka-Nerd-Font-Complete.ttf diff --git a/host/ui/fonts/JetBrains-Mono-Nerd-Font-Complete.ttf b/host/ui/fonts/TTF/JetBrains-Mono-Nerd-Font-Complete.ttf similarity index 100% rename from host/ui/fonts/JetBrains-Mono-Nerd-Font-Complete.ttf rename to host/ui/fonts/TTF/JetBrains-Mono-Nerd-Font-Complete.ttf diff --git a/.scripts/setup/pkgs-installer.sh b/setup.sh similarity index 82% rename from .scripts/setup/pkgs-installer.sh rename to setup.sh index 076bc24..3645796 100755 --- a/.scripts/setup/pkgs-installer.sh +++ b/setup.sh @@ -1,10 +1,17 @@ #!/bin/bash -source ../utils/main.sh +source ./.scripts/utils/init.sh UPDATE_PKGS=false CLEAR_CACHE=false DISABLE_GRUB_MENU=false +TTF_FONTS_DIR="./host/ui/fonts/TTF" + +display_help() { + echo "Usage: [-i | -f] [-h]" + echo " -i Full install" + echo " -f Install host fonts" +} declare -A PACKAGES=( ["VOID_REPOS"]="void-repo-multilib void-repo-nonfree" @@ -110,13 +117,39 @@ disable_grub_menu() { fi } -check_sudo +install_ttf_fonts() { + sudo cp $TTF_FONTS_DIR/* /usr/share/fonts/TTF + sudo fc-cache -f -v -update_system -clear_pkgs_cache -install_pkgs -add_user_to_groups -enable_services -disable_grub_menu + log "Fonts installed successfully!" +} -log "Setup is done, please log out and log in" +while getopts "sfh" opt; do + case $opt in + s) + check_sudo + + update_system + clear_pkgs_cache + install_pkgs + add_user_to_groups + enable_services + disable_grub_menu + + log "Setup is done, please log out and log in" + ;; + f) + check_sudo + + install_ttf_fonts + ;; + h) + display_help + exit 0 + ;; + esac +done + +if [[ $# -eq 0 ]]; then + display_help +fi diff --git a/stow.sh b/stow.sh index 54692f0..fb8c1e2 100755 --- a/stow.sh +++ b/stow.sh @@ -1,7 +1,7 @@ #!/bin/bash -source ./.scripts/utils/main.sh -source ./.scripts/utils/helpers.sh +source ./.scripts/utils/init.sh +source ./.scripts/utils/_links.sh DOTS_CONFIG_DIR="$(pwd)/linux-configs" DOTFILES_DIR="$DOTS_CONFIG_DIR/dotfiles" @@ -31,36 +31,36 @@ create_target_dir() { stow() { create_target_dir - create_symlinks $SHELL_DIR ~ + create_links $SHELL_DIR ~ log "Shell stowed successfully!" - create_symlinks $EDITOR_DIR ~ + create_links $EDITOR_DIR ~ log "Editor stowed successfully!" - create_symlinks $DOTFILES_DIR ~/.config + create_links $DOTFILES_DIR ~/.config log "Dotfiles stowed successfully!" - create_symlinks $HYPRLAND_DIR ~/.config + create_links $HYPRLAND_DIR ~/.config log "Hyprland stowed successfully!" - create_symlinks $SHORTCUTS_DIR ~/.local/share/applications + create_links $SHORTCUTS_DIR ~/.local/share/applications log "Shortcuts stowed successfully!" - create_symlinks $UTILS_DIR ~ + create_links $UTILS_DIR ~ log "Utilities stowed successfully!" } unstow() { - delete_symlinks $SHELL_DIR ~ - delete_symlinks $DOTFILES_DIR ~/.config - delete_symlinks $HYPRLAND_DIR ~/.config - delete_symlinks $SHORTCUTS_DIR ~/.local/share/applications - delete_symlinks $UTILS_DIR ~ + delete_links $SHELL_DIR ~ + delete_links $DOTFILES_DIR ~/.config + delete_links $HYPRLAND_DIR ~/.config + delete_links $SHORTCUTS_DIR ~/.local/share/applications + delete_links $UTILS_DIR ~ log "All configs ustowed successfully !" } -while getopts "ps" opt; do +while getopts "ush" opt; do case $opt in s) stow @@ -72,10 +72,6 @@ while getopts "ps" opt; do display_help exit 0 ;; - \?) - display_help - exit 1 - ;; esac done