diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..6e3712a --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,8 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + reviewers: + - "ChrisTitusTech" diff --git a/config.jsonc b/config.jsonc index 28a2c1c..3a85404 100644 --- a/config.jsonc +++ b/config.jsonc @@ -60,7 +60,7 @@ }, { "type": "custom", - "format": "|──────────────\u001b[1mUptime / Age\u001b[0m────────────────|" + "format": "|──────────────\u001b[1mUptime / Age\u001b[0m──────────────────|" }, { "type": "command", diff --git a/setup.sh b/setup.sh index cec5608..b479050 100755 --- a/setup.sh +++ b/setup.sh @@ -1,29 +1,28 @@ -#!/usr/bin/env bash -# use bin/env bash as cannot be sure that bash actually exists at bin/bash +#!/bin/sh -e -RC='\e[0m' -RED='\e[31m' -YELLOW='\e[33m' -GREEN='\e[32m' +RC='\033[0m' +RED='\033[31m' +YELLOW='\033[33m' +GREEN='\033[32m' # Check if the home directory and linuxtoolbox folder exist, create them if they don't LINUXTOOLBOXDIR="$HOME/linuxtoolbox" -if [[ ! -d "$LINUXTOOLBOXDIR" ]]; then - echo -e "${YELLOW}Creating linuxtoolbox directory: $LINUXTOOLBOXDIR${RC}" +if [ ! -d "$LINUXTOOLBOXDIR" ]; then + echo "${YELLOW}Creating linuxtoolbox directory: $LINUXTOOLBOXDIR${RC}" mkdir -p "$LINUXTOOLBOXDIR" - echo -e "${GREEN}linuxtoolbox directory created: $LINUXTOOLBOXDIR${RC}" + echo "${GREEN}linuxtoolbox directory created: $LINUXTOOLBOXDIR${RC}" fi -if [[ ! -d "$LINUXTOOLBOXDIR/mybash" ]]; then - echo -e "${YELLOW}Cloning mybash repository into: $LINUXTOOLBOXDIR/mybash${RC}" - git clone https://github.com/ChrisTitusTech/mybash "$LINUXTOOLBOXDIR/mybash" - if [[ $? -eq 0 ]]; then - echo -e "${GREEN}Successfully cloned mybash repository${RC}" - else - echo -e "${RED}Failed to clone mybash repository${RC}" - exit 1 - fi +if [ -d "$LINUXTOOLBOXDIR/mybash" ]; then rm -rf "$LINUXTOOLBOXDIR/mybash"; fi + +echo "${YELLOW}Cloning mybash repository into: $LINUXTOOLBOXDIR/mybash${RC}" +git clone https://github.com/ChrisTitusTech/mybash "$LINUXTOOLBOXDIR/mybash" +if [ $? -eq 0 ]; then + echo "${GREEN}Successfully cloned mybash repository${RC}" +else + echo "${RED}Failed to clone mybash repository${RC}" + exit 1 fi # add variables to top level so can easily be accessed by all functions @@ -40,29 +39,26 @@ command_exists() { checkEnv() { ## Check for requirements. - # use local as it is more correct bash - # use arrays instead of splitting - local REQUIREMENTS=(curl groups sudo) - for req in "${REQUIREMENTS[@]}"; do - if ! command_exists ${req}; then - echo -e "${RED}To run me, you need: ${REQUIREMENTS}${RC}" + REQUIREMENTS='curl groups sudo' + for req in $REQUIREMENTS; do + if ! command_exists "$req"; then + echo "${RED}To run me, you need: $REQUIREMENTS${RC}" exit 1 fi done - ## Check Package Handeler - local PACKAGEMANAGER=(nala apt dnf yum pacman zypper emerge xbps-install nix-env) - - for pgm in "${PACKAGEMANAGER[@]}"; do - if command_exists ${pgm}; then - PACKAGER=${pgm} - echo -e "Using ${pgm}" + ## Check Package Handler + PACKAGEMANAGER='nala apt dnf yum pacman zypper emerge xbps-install nix-env' + for pgm in $PACKAGEMANAGER; do + if command_exists "$pgm"; then + PACKAGER="$pgm" + echo "Using $pgm" break fi done - if [ -z "${PACKAGER}" ]; then - echo -e "${RED}Can't find a supported package manager${RC}" + if [ -z "$PACKAGER" ]; then + echo "${RED}Can't find a supported package manager${RC}" exit 1 fi @@ -77,26 +73,26 @@ checkEnv() { echo "Using $SUDO_CMD as privilege escalation software" ## Check if the current directory is writable. - # we cd'd into this directory before this function so we can use the PWD var - if [[ ! -w "$PWD" ]]; then - echo -e "${RED}Can't write to ${PWD}${RC}" + GITPATH=$(dirname "$(realpath "$0")") + if [ ! -w "$GITPATH" ]; then + echo "${RED}Can't write to $GITPATH${RC}" exit 1 fi ## Check SuperUser Group - local SUPERUSERGROUP=(wheel sudo root) - for sug in "${SUPERUSERGROUP[@]}"; do - if groups | (command_exists rg && rg -q ${sug} || grep -q ${sug}); then - SUGROUP=${sug} - # don't need -e as there are no escape codes to escape - echo "Super user group ${SUGROUP}" + + SUPERUSERGROUP='wheel sudo root' + for sug in $SUPERUSERGROUP; do + if groups | grep -q "$sug"; then + SUGROUP="$sug" + echo "Super user group $SUGROUP" break fi done ## Check if member of the sudo group. - if ! groups | (command_exists rg && rg -q ${SUGROUP} || grep -q ${SUGROUP}); then - echo -e "${RED}You need to be a member of the sudo group to run me!${RC}" + if ! groups | grep -q "$SUGROUP"; then + echo "${RED}You need to be a member of the sudo group to run me!${RC}" exit 1 fi } @@ -107,13 +103,32 @@ installDepend() { if ! command_exists nvim; then DEPENDENCIES="${DEPENDENCIES} neovim" fi + # Check to see if a the FiraCode Nerd Font is installed (Change this to whatever font you would like) + FONT_NAME="FiraCode Nerd Font" + if fc-list :family | grep -iq "$FONT_NAME"; then + echo "Font '$FONT_NAME' is installed." + else + echo "Installing font '$FONT_NAME'" + # Change this URL to correspond with the correct font + FONT_URL="https://github.com/ryanoasis/nerd-fonts/releases/download/v2.3.3/FiraCode.zip" + FONT_DIR="$HOME/.local/share/fonts" + wget $FONT_URL -O ${FONT_NAME}.zip + unzip ${FONT_NAME}.zip -d $FONT_NAME + mkdir -p $FONT_DIR + mv ${FONT_NAME}/*.ttf $FONT_DIR/ + # Update the font cache + fc-cache -fv + # delete the files created from this + rm -rf ${FONT_NAME} ${FONT_NAME}.zip + echo "'$FONT_NAME' installed successfully." + fi - echo -e "${YELLOW}Installing dependencies...${RC}" - if [[ "$PACKAGER" == "pacman" ]]; then + echo "${YELLOW}Installing dependencies...${RC}" + if [ "$PACKAGER" = "pacman" ]; then if ! command_exists yay && ! command_exists paru; then echo "Installing yay as AUR helper..." ${SUDO_CMD} ${PACKAGER} --noconfirm -S base-devel - cd /opt && ${SUDO_CMD} git clone https://aur.archlinux.org/yay-git.git && ${SUDO_CMD} chown -R ${USER}:${USER} ./yay-git + cd /opt && ${SUDO_CMD} git clone https://aur.archlinux.org/yay-git.git && ${SUDO_CMD} chown -R "${USER}:${USER}" ./yay-git cd yay-git && makepkg --noconfirm -si else echo "AUR helper already installed" @@ -127,13 +142,13 @@ installDepend() { exit 1 fi ${AUR_HELPER} --noconfirm -S ${DEPENDENCIES} - elif [[ "$PACKAGER" == "nala" ]]; then + elif [ "$PACKAGER" = "nala" ]; then ${SUDO_CMD} ${PACKAGER} install -y ${DEPENDENCIES} - elif [[ "$PACKAGER" == "emerge" ]]; then + elif [ "$PACKAGER" = "emerge" ]; then ${SUDO_CMD} ${PACKAGER} -v app-shells/bash app-shells/bash-completion app-arch/tar app-editors/neovim sys-apps/bat app-text/tree app-text/multitail app-misc/fastfetch - elif [[ "$PACKAGER" == "xbps-install" ]]; then + elif [ "$PACKAGER" = "xbps-install" ]; then ${SUDO_CMD} ${PACKAGER} -v ${DEPENDENCIES} - elif [[ "$PACKAGER" == "nix-env" ]]; then + elif [ "$PACKAGER" = "nix-env" ]; then ${SUDO_CMD} ${PACKAGER} -iA nixos.bash nixos.bash-completion nixos.gnutar nixos.neovim nixos.bat nixos.tree nixos.multitail nixos.fastfetch elif [[ "$PACKAGER" == "dnf" ]]; then ${SUDO_CMD} ${PACKAGER} install -y ${DEPENDENCIES} @@ -149,7 +164,7 @@ installStarshipAndFzf() { fi if ! curl -sS https://starship.rs/install.sh | sh; then - echo -e "${RED}Something went wrong during starship install!${RC}" + echo "${RED}Something went wrong during starship install!${RC}" exit 1 fi if command_exists fzf; then @@ -167,7 +182,7 @@ installZoxide() { fi if ! curl -sS https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh; then - echo -e "${RED}Something went wrong during zoxide install!${RC}" + echo "${RED}Something went wrong during zoxide install!${RC}" exit 1 fi } @@ -179,15 +194,17 @@ install_additional_dependencies() { return case "$PACKAGER" in *apt) - curl -LO https://github.com/neovim/neovim/releases/latest/download/nvim.appimage - chmod u+x nvim.appimage - ./nvim.appimage --appimage-extract - ${SUDO_CMD} mv squashfs-root /opt/neovim - ${SUDO_CMD} ln -s /opt/neovim/AppRun /usr/bin/nvim + if [ ! -d "/opt/neovim" ]; then + curl -LO https://github.com/neovim/neovim/releases/latest/download/nvim.appimage + chmod u+x nvim.appimage + ./nvim.appimage --appimage-extract + ${SUDO_CMD} mv squashfs-root /opt/neovim + ${SUDO_CMD} ln -s /opt/neovim/AppRun /usr/bin/nvim + fi ;; *zypper) ${SUDO_CMD} zypper refresh - ${SUDO_CMD} zypper install -y neovim + ${SUDO_CMD} zypper -n install neovim # -y doesn't work on opensuse -n is short for -non-interactive which is equivalent to -y ;; *dnf) ${SUDO_CMD} dnf check-update @@ -205,28 +222,35 @@ install_additional_dependencies() { } create_fastfetch_config() { - fastfetch --gen-config + ## Get the correct user home directory. + USER_HOME=$(getent passwd "${SUDO_USER:-$USER}" | cut -d: -f6) + + if [ ! -d "$USER_HOME/.config/fastfetch" ]; then + mkdir -p "$USER_HOME/.config/fastfetch" + fi + # Check if the fastfetch config file exists + if [ -e "$USER_HOME/.config/fastfetch/config.jsonc" ]; then + rm -f "$USER_HOME/.config/fastfetch/config.jsonc" + fi + ln -svf "$GITPATH/config.jsonc" "$USER_HOME/.config/fastfetch/config.jsonc" } linkConfig() { ## Get the correct user home directory. - USER_HOME=$(getent passwd ${SUDO_USER:-$USER} | cut -d: -f6) + USER_HOME=$(getent passwd "${SUDO_USER:-$USER}" | cut -d: -f6) ## Check if a bashrc file is already there. - OLD_BASHRC="${USER_HOME}/.bashrc" - if [[ -e "${OLD_BASHRC}" ]]; then - 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}" + OLD_BASHRC="$USER_HOME/.bashrc" + if [ -e "$OLD_BASHRC" ]; then + echo "${YELLOW}Moving old bash config file to $USER_HOME/.bashrc.bak${RC}" + if ! mv "$OLD_BASHRC" "$USER_HOME/.bashrc.bak"; then + echo "${RED}Can't move the old bash config file!${RC}" exit 1 fi fi - echo -e "${YELLOW}Linking new bash config file...${RC}" - ## Make symbolic link. - ln -svf "${GITPATH}/.bashrc" "${USER_HOME}/.bashrc" - ln -svf "${GITPATH}/starship.toml" "${USER_HOME}/.config/starship.toml" - echo -e "${YELLOW}Linking custom fastfetch config file...${RC}" - ln -svf "${GITPATH}/config.jsonc" "${USER_HOME}/.config/fastfetch/config.jsonc" + echo "${YELLOW}Linking new bash config file...${RC}" + ln -svf "$GITPATH/.bashrc" "$USER_HOME/.bashrc" + ln -svf "$GITPATH/starship.toml" "$USER_HOME/.config/starship.toml" } checkEnv @@ -237,7 +261,7 @@ install_additional_dependencies create_fastfetch_config if linkConfig; then - echo -e "${GREEN}Done!\nRestart your shell to see the changes.${RC}" + echo "${GREEN}Done!\nrestart your shell to see the changes.${RC}" else - echo -e "${RED}Something went wrong!${RC}" -fi + echo "${RED}Something went wrong!${RC}" +fi \ No newline at end of file