From 7a28bfcc2d98e2513456516ae14e14aa065cf87a Mon Sep 17 00:00:00 2001 From: bckelley Date: Fri, 24 May 2024 10:08:30 -0500 Subject: [PATCH 1/6] correction --- setup.sh | 79 ++++++++++++++++++++++++-------------------------------- 1 file changed, 34 insertions(+), 45 deletions(-) diff --git a/setup.sh b/setup.sh index de361ab..96ed54c 100755 --- a/setup.sh +++ b/setup.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash RC='\e[0m' RED='\e[31m' @@ -11,16 +11,24 @@ command_exists() { ## Function to grant sudo permissions to the current user grant_sudo_permissions() { - # Prompt for the root password + echo "Attempting to grant sudo permissions to user ${USER}. Please enter the root password if prompted." su -c "usermod -aG sudo ${USER}" - echo "Sudo permissions granted to user ${USER}" + if [ $? -eq 0 ]; then + echo -e "${GREEN}Sudo permissions granted to user ${USER}.${RC}" + echo "Please log out and log back in, then re-run this script with sudo:" + echo " sudo $0" + exit 0 + else + echo -e "${RED}Failed to grant sudo permissions. Please run this script as root or ask an administrator to add you to the sudo group.${RC}" + exit 1 + fi } # Check if the user is in the sudo group -if id -nG "${USER}" | grep -qw "sudo"; then - echo "User ${USER} is already in the sudo group" -else +if ! id -nG "${USER}" | grep -qw "sudo"; then grant_sudo_permissions +else + echo "User ${USER} is already in the sudo group." fi checkEnv() { @@ -76,45 +84,26 @@ installDepend() { ## Check for dependencies. DEPENDENCIES='bash bash-completion tar neovim bat tree multitail' echo -e "${YELLOW}Installing dependencies...${RC}" - if [ "$PACKAGER" = "nala" ] || [ "$PACKAGER" = "apt" ]; then - for pkg in $DEPENDENCIES; do - read -p "Would you like to install $pkg package? [Y/n]: " choice - case "$choice" in - y|Y|'') sudo "$PACKAGER" install -y "$pkg" ;; - n|N) ;; - *) echo "Invalid choice. Defaulting to yes." && sudo "$PACKAGER" install -y "$pkg" ;; - esac - done - elif [ "$PACKAGER" = "yum" ] || [ "$PACKAGER" = "dnf" ]; then - for pkg in $DEPENDENCIES; do - read -p "Would you like to install $pkg package? [Y/n]: " choice - case "$choice" in - y|Y|'') sudo "$PACKAGER" install -y "$pkg" ;; - n|N) ;; - *) echo "Invalid choice. Defaulting to yes." && sudo "$PACKAGER" install -y "$pkg" ;; - esac - done - elif [ "$PACKAGER" = "pacman" ]; then - for pkg in $DEPENDENCIES; do - read -p "Would you like to install $pkg package? [Y/n]: " choice - case "$choice" in - y|Y|'') sudo "$PACKAGER" -S --noconfirm "$pkg" ;; - n|N) ;; - *) echo "Invalid choice. Defaulting to yes." && sudo "$PACKAGER" -S --noconfirm "$pkg" ;; - esac - done - elif [ "$PACKAGER" = "zypper" ]; then - for pkg in $DEPENDENCIES; do - read -p "Would you like to install $pkg package? [Y/n]: " choice - case "$choice" in - y|Y|'') sudo "$PACKAGER" install -y "$pkg" ;; - n|N) ;; - *) echo "Invalid choice. Defaulting to yes." && sudo "$PACKAGER" install -y "$pkg" ;; - esac - done - else - echo "Unsupported package manager: $PACKAGER" - fi + for pkg in $DEPENDENCIES; do + read -p "Would you like to install $pkg package? [Y/n]: " choice + case "$choice" in + y|Y|'') + if [ "$PACKAGER" = "pacman" ]; then + sudo "$PACKAGER" -S --noconfirm "$pkg" + else + sudo "$PACKAGER" install -y "$pkg" + fi + ;; + n|N) ;; + *) echo "Invalid choice. Defaulting to yes." + if [ "$PACKAGER" = "pacman" ]; then + sudo "$PACKAGER" -S --noconfirm "$pkg" + else + sudo "$PACKAGER" install -y "$pkg" + fi + ;; + esac + done } installOhMyPosh() { From a78bf857adc854d9016830e8ba05fafc5309a5ea Mon Sep 17 00:00:00 2001 From: bckelley Date: Fri, 24 May 2024 10:27:12 -0500 Subject: [PATCH 2/6] refactor grant_sudo_permissions --- setup.sh | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/setup.sh b/setup.sh index 96ed54c..5c8b050 100755 --- a/setup.sh +++ b/setup.sh @@ -11,22 +11,25 @@ command_exists() { ## Function to grant sudo permissions to the current user grant_sudo_permissions() { - echo "Attempting to grant sudo permissions to user ${USER}. Please enter the root password if prompted." - su -c "usermod -aG sudo ${USER}" + echo "Granting sudo permissions to user ${USER}" + sudo usermod -aG sudo "${USER}" if [ $? -eq 0 ]; then echo -e "${GREEN}Sudo permissions granted to user ${USER}.${RC}" - echo "Please log out and log back in, then re-run this script with sudo:" - echo " sudo $0" - exit 0 else - echo -e "${RED}Failed to grant sudo permissions. Please run this script as root or ask an administrator to add you to the sudo group.${RC}" + echo -e "${RED}Failed to grant sudo permissions.${RC}" exit 1 fi } # Check if the user is in the sudo group if ! id -nG "${USER}" | grep -qw "sudo"; then - grant_sudo_permissions + if [ "$EUID" -ne 0 ]; then + echo "This script needs sudo privileges to add the user to the sudo group." + echo "Please enter the sudo password to proceed." + grant_sudo_permissions + else + echo "User ${USER} is already in the sudo group." + fi else echo "User ${USER} is already in the sudo group." fi From 74119b533f436b11ddefca92e02840f564c32fea Mon Sep 17 00:00:00 2001 From: bckelley Date: Fri, 24 May 2024 10:30:56 -0500 Subject: [PATCH 3/6] delete grant_sudo_permissions -> for check_root --- setup.sh | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/setup.sh b/setup.sh index 5c8b050..00c47c8 100755 --- a/setup.sh +++ b/setup.sh @@ -9,31 +9,13 @@ command_exists() { command -v "$1" >/dev/null 2>&1 } -## Function to grant sudo permissions to the current user -grant_sudo_permissions() { - echo "Granting sudo permissions to user ${USER}" - sudo usermod -aG sudo "${USER}" - if [ $? -eq 0 ]; then - echo -e "${GREEN}Sudo permissions granted to user ${USER}.${RC}" - else - echo -e "${RED}Failed to grant sudo permissions.${RC}" +check_root() { + if [ "$(id -u)" != "0" ]; then + echo -e "${RED}This script must be run as root.${RC}" 1>&2 exit 1 fi } -# Check if the user is in the sudo group -if ! id -nG "${USER}" | grep -qw "sudo"; then - if [ "$EUID" -ne 0 ]; then - echo "This script needs sudo privileges to add the user to the sudo group." - echo "Please enter the sudo password to proceed." - grant_sudo_permissions - else - echo "User ${USER} is already in the sudo group." - fi -else - echo "User ${USER} is already in the sudo group." -fi - checkEnv() { ## Check for requirements. REQUIREMENTS='curl groups sudo' From 5b553ba8fd7fa76a1b8ebf9323d023f2705624d7 Mon Sep 17 00:00:00 2001 From: bckelley Date: Fri, 24 May 2024 10:37:16 -0500 Subject: [PATCH 4/6] delete check_root -> added to checkEnv --- setup.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/setup.sh b/setup.sh index 00c47c8..6f8b42b 100755 --- a/setup.sh +++ b/setup.sh @@ -9,14 +9,13 @@ command_exists() { command -v "$1" >/dev/null 2>&1 } -check_root() { +checkEnv() { + if [ "$(id -u)" != "0" ]; then echo -e "${RED}This script must be run as root.${RC}" 1>&2 exit 1 fi -} -checkEnv() { ## Check for requirements. REQUIREMENTS='curl groups sudo' for req in ${REQUIREMENTS}; do From be01cef9e941cfdc6ae13a990bea85e5804b08af Mon Sep 17 00:00:00 2001 From: bckelley Date: Fri, 24 May 2024 10:40:33 -0500 Subject: [PATCH 5/6] changed all exit 1 -> exit 1 hopfully fixes the issue of the script logging out prematurely --- setup.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/setup.sh b/setup.sh index 6f8b42b..b2acacb 100755 --- a/setup.sh +++ b/setup.sh @@ -13,7 +13,7 @@ checkEnv() { if [ "$(id -u)" != "0" ]; then echo -e "${RED}This script must be run as root.${RC}" 1>&2 - exit 1 + exit 0 fi ## Check for requirements. @@ -21,7 +21,7 @@ checkEnv() { for req in ${REQUIREMENTS}; do if ! command_exists "$req"; then echo -e "${RED}To run me, you need: ${req}${RC}" - exit 1 + exit 0 fi done @@ -37,14 +37,14 @@ checkEnv() { if [ -z "${PACKAGER}" ]; then echo -e "${RED}Can't find a supported package manager${RC}" - exit 1 + exit 0 fi ## Check if the current directory is writable. GITPATH="$(dirname "$(realpath "$0")")" if [ ! -w "${GITPATH}" ]; then echo -e "${RED}Can't write to ${GITPATH}${RC}" - exit 1 + exit 0 fi ## Check SuperUser Group @@ -60,7 +60,7 @@ checkEnv() { ## Check if member of the sudo group. if ! groups | grep -q "$SUGROUP"; then echo -e "${RED}You need to be a member of the sudo group to run me!${RC}" - exit 1 + exit 0 fi } @@ -98,7 +98,7 @@ installOhMyPosh() { if ! curl -sS https://ohmyposh.dev/install.sh | bash -s; then echo -e "${RED}Something went wrong during oh-my-posh install!${RC}" - exit 1 + exit 0 fi oh-my-posh font install @@ -119,7 +119,7 @@ installZoxide() { if ! curl -sS https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh; then echo -e "${RED}Something went wrong during zoxide install!${RC}" - exit 1 + exit 0 fi } @@ -133,7 +133,7 @@ installFastfetch() { if [ "$PACKAGER" = "nala" ] || [ "$PACKAGER" = "apt" ]; then if ! curl -sSL https://github.com/fastfetch-cli/fastfetch/releases/download/2.13.2/fastfetch-linux-amd64.deb -o fastfetch-linux-amd64.deb || ! sudo dpkg -i fastfetch-linux-amd64.deb; then echo -e "${RED}Something went wrong during fastfetch install${RC}" - exit 1 + exit 0 fi else sudo "$PACKAGER" install -y fastfetch @@ -158,7 +158,7 @@ linkConfig() { echo -e "${YELLOW}Moving old bash config file to ${USER_HOME}/.bashrc.bak${RC}" if ! mv "${OLD_BASHRC}" "${USER_HOME}/.bashrc.bak"; then echo -e "${RED}Can't move the old bash config file!${RC}" - exit 1 + exit 0 fi fi From 472f2458bd25d94017c8d9a5ee3aa2bbe96d2f64 Mon Sep 17 00:00:00 2001 From: bckelley Date: Fri, 24 May 2024 10:53:11 -0500 Subject: [PATCH 6/6] Revert "removed old README" This reverts commit 7e69257fd59bf4e329af3b0b2bd2327234082ee4. --- README | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 README diff --git a/README b/README new file mode 100644 index 0000000..2451c2d --- /dev/null +++ b/README @@ -0,0 +1,45 @@ +## Overview of my `.bashrc` Configuration + +The `.bashrc` file is a script that runs every time a new terminal session is started in Unix-like operating systems. It is used to configure the shell session, set up aliases, define functions, and more, making the terminal easier to use and more powerful. Below is a summary of the key sections and functionalities defined in the provided `.bashrc` file. + +### Initial Setup and System Checks + +- **Environment Checks**: The script checks if it is running in an interactive mode and sets up the environment accordingly. +- **System Utilities**: It checks for the presence of utilities like `fastfetch`, `bash-completion`, and system-specific configurations (`/etc/bashrc`). + +### Aliases and Functions + +- **Aliases**: Shortcuts for common commands are set up to enhance productivity. For example, `alias cp='cp -i'` makes the `cp` command interactive, asking for confirmation before overwriting files. +- **Functions**: Custom functions for complex operations like `extract()` for extracting various archive types, and `cpp()` for copying files with a progress bar. + +### Prompt Customization and History Management + +- **Prompt Command**: The `PROMPT_COMMAND` variable is set to automatically save the command history after each command. +- **History Control**: Settings to manage the size of the history file and how duplicates are handled. + +### System-Specific Aliases and Settings + +- **Editor Settings**: Sets `nvim` (NeoVim) as the default editor. +- **Conditional Aliases**: Depending on the system type (like Fedora), it sets specific aliases, e.g., replacing `cat` with `bat`. + +### Enhancements and Utilities + +- **Color and Formatting**: Enhancements for command output readability using colors and formatting for tools like `ls`, `grep`, and `man`. +- **Navigation Shortcuts**: Aliases to simplify directory navigation, e.g., `alias ..='cd ..'` to go up one directory. +- **Safety Features**: Aliases for safer file operations, like using `trash` instead of `rm` for deleting files, to prevent accidental data loss. +- **Extensive Zoxide support**: Easily navigate with `z`, `zi`, or pressing Ctrl+f to launch zi to see frequently used navigation directories. + +### Advanced Functions + +- **System Information**: Functions to display system information like `distribution()` to identify the Linux distribution. +- **Networking Utilities**: Tools to check internal and external IP addresses. +- **Resource Monitoring**: Commands to monitor system resources like disk usage and open ports. + +### Installation and Configuration Helpers + +- **Auto-Install**: A function `install_bashrc_support()` to automatically install necessary utilities based on the system type. +- **Configuration Editors**: Functions to edit important configuration files directly, e.g., `apacheconfig()` for Apache server configurations. + +### Conclusion + +This `.bashrc` file is a comprehensive setup that not only enhances the shell experience with useful aliases and functions but also provides system-specific configurations and safety features to cater to different user needs and system types. It is designed to make the terminal more user-friendly, efficient, and powerful for an average user.