revision to setup

This commit is contained in:
2024-05-23 12:49:18 -05:00
parent 40d349bc1e
commit c56a0a7f18
+68 -33
View File
@@ -6,34 +6,51 @@ YELLOW='\e[33m'
GREEN='\e[32m' GREEN='\e[32m'
command_exists() { command_exists() {
command -v $1 >/dev/null 2>&1 command -v "$1" >/dev/null 2>&1
} }
## Function to grant sudo permissions to the current user
grant_sudo_permissions() {
# Prompt for the root password
su -c "usermod -aG sudo ${USER}"
echo "Sudo permissions granted to user ${USER}"
}
# 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
grant_sudo_permissions
fi
checkEnv() { checkEnv() {
## Check for requirements. ## Check for requirements.
REQUIREMENTS='curl groups sudo' REQUIREMENTS='curl groups sudo'
if ! command_exists ${REQUIREMENTS}; then for req in ${REQUIREMENTS}; do
echo -e "${RED}To run me, you need: ${REQUIREMENTS}${RC}" if ! command_exists "$req"; then
exit 1 echo -e "${RED}To run me, you need: ${req}${RC}"
fi exit 1
fi
done
## Check Package Handeler ## Check Package Manager
PACKAGEMANAGER='nala apt yum dnf pacman zypper' PACKAGEMANAGER='nala apt yum dnf pacman zypper'
for pgm in ${PACKAGEMANAGER}; do for pgm in ${PACKAGEMANAGER}; do
if command_exists ${pgm}; then if command_exists "$pgm"; then
PACKAGER=${pgm} PACKAGER="$pgm"
echo -e "Using ${pgm}" echo -e "Using ${pgm}"
break
fi fi
done done
if [ -z "${PACKAGER}" ]; then if [ -z "${PACKAGER}" ]; then
echo -e "${RED}Can't find a supported package manager" echo -e "${RED}Can't find a supported package manager${RC}"
exit 1 exit 1
fi fi
## Check if the current directory is writable. ## Check if the current directory is writable.
GITPATH="$(dirname "$(realpath "$0")")" GITPATH="$(dirname "$(realpath "$0")")"
if [[ ! -w ${GITPATH} ]]; then if [ ! -w "${GITPATH}" ]; then
echo -e "${RED}Can't write to ${GITPATH}${RC}" echo -e "${RED}Can't write to ${GITPATH}${RC}"
exit 1 exit 1
fi fi
@@ -41,29 +58,29 @@ checkEnv() {
## Check SuperUser Group ## Check SuperUser Group
SUPERUSERGROUP='wheel sudo root' SUPERUSERGROUP='wheel sudo root'
for sug in ${SUPERUSERGROUP}; do for sug in ${SUPERUSERGROUP}; do
if groups | grep ${sug}; then if groups | grep -q "$sug"; then
SUGROUP=${sug} SUGROUP="$sug"
echo -e "Super user group ${SUGROUP}" echo -e "Super user group ${SUGROUP}"
break
fi fi
done done
## Check if member of the sudo group. ## Check if member of the sudo group.
if ! groups | grep ${SUGROUP} >/dev/null; then if ! groups | grep -q "$SUGROUP"; then
echo -e "${RED}You need to be a member of the sudo group to run me!" echo -e "${RED}You need to be a member of the sudo group to run me!${RC}"
exit 1 exit 1
fi fi
} }
installDepend() { installDepend() {
## Check for dependencies. ## Check for dependencies.
DEPENDENCIES='bash bash-completion tar neovim bat tree multitail fastfetch' DEPENDENCIES='bash bash-completion tar neovim bat tree multitail fastfetch'
echo -e "${YELLOW}Installing dependencies...${RC}" echo -e "${YELLOW}Installing dependencies...${RC}"
if [[ $PACKAGER == "pacman" ]]; then if [ "$PACKAGER" = "pacman" ]; then
if ! command_exists yay && ! command_exists paru; then if ! command_exists yay && ! command_exists paru; then
echo "Installing yay as AUR helper..." echo "Installing yay as AUR helper..."
sudo ${PACKAGER} --noconfirm -S base-devel sudo pacman --noconfirm -S base-devel
cd /opt && sudo git clone https://aur.archlinux.org/yay-git.git && sudo chown -R ${USER}:${USER} ./yay-git cd /opt && sudo git clone https://aur.archlinux.org/yay-git.git && sudo chown -R "${USER}:${USER}" ./yay-git
cd yay-git && makepkg --noconfirm -si cd yay-git && makepkg --noconfirm -si
else else
echo "Aur helper already installed" echo "Aur helper already installed"
@@ -76,12 +93,11 @@ installDepend() {
echo "No AUR helper found. Please install yay or paru." echo "No AUR helper found. Please install yay or paru."
exit 1 exit 1
fi fi
${AUR_HELPER} --noconfirm -S ${DEPENDENCIES} "${AUR_HELPER}" --noconfirm -S ${DEPENDENCIES}
elif [[ $PACKAGER == "nala apt" ]]; then elif [ "$PACKAGER" = "nala" ] || [ "$PACKAGER" = "apt" ]; then
sudo "$PACKAGER" install -y ${DEPENDENCIES}
sudo ${PACKAGER} install -y ${DEPENDENCIES}
else else
sudo ${PACKAGER} install -yq ${DEPENDENCIES} sudo "$PACKAGER" install -yq ${DEPENDENCIES}
fi fi
} }
@@ -93,10 +109,11 @@ installOhMyPosh() {
if ! curl -sS https://ohmyposh.dev/install.sh | bash -s; then if ! curl -sS https://ohmyposh.dev/install.sh | bash -s; then
echo -e "${RED}Something went wrong during oh-my-posh install!${RC}" echo -e "${RED}Something went wrong during oh-my-posh install!${RC}"
oh-my-posh font install
exit 1 exit 1
fi fi
oh-my-posh font install
if command_exists fzf; then if command_exists fzf; then
echo "Fzf already installed" echo "Fzf already installed"
else else
@@ -117,19 +134,35 @@ installZoxide() {
fi fi
} }
installFastfetch() {
if command_exists fastfetch; then
echo "fastfetch already installed"
return
fi
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
fi
}
installCleanup() {
echo -e "${GREEN}Cleanup not implemented yet.${RC}"
}
install_additional_dependencies() { install_additional_dependencies() {
sudo apt update sudo apt update
sudo apt install -y trash-cli bat meld jpico sudo apt install -y trash-cli bat meld jpico
} }
linkConfig() { linkConfig() {
## Get the correct user home directory. ## 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. ## Check if a bashrc file is already there.
OLD_BASHRC="${USER_HOME}/.bashrc" OLD_BASHRC="${USER_HOME}/.bashrc"
if [[ -e ${OLD_BASHRC} ]]; then if [ -e "${OLD_BASHRC}" ]; then
echo -e "${YELLOW}Moving old bash config file to ${USER_HOME}/.bashrc.bak${RC}" echo -e "${YELLOW}Moving old bash config file to ${USER_HOME}/.bashrc.bak${RC}"
if ! mv ${OLD_BASHRC} ${USER_HOME}/.bashrc.bak; then if ! mv "${OLD_BASHRC}" "${USER_HOME}/.bashrc.bak"; then
echo -e "${RED}Can't move the old bash config file!${RC}" echo -e "${RED}Can't move the old bash config file!${RC}"
exit 1 exit 1
fi fi
@@ -137,17 +170,19 @@ linkConfig() {
echo -e "${YELLOW}Linking new bash config file...${RC}" echo -e "${YELLOW}Linking new bash config file...${RC}"
## Make symbolic link. ## Make symbolic link.
ln -svf ${GITPATH}/.bashrc ${USER_HOME}/.bashrc ln -svf "${GITPATH}/.bashrc" "${USER_HOME}/.bashrc"
} }
checkEnv checkEnv
installDepend installDepend
installOh-My-Posh installOhMyPosh
installZoxide installZoxide
installFastfetch
install_additional_dependencies install_additional_dependencies
installCleanup
if link nfig; then if linkConfig; then
echo -e "${GREEN}Done!\nrestart your shell to see the changes.${RC}" echo -e "${GREEN}Done!\nRestart your shell to see the changes.${RC}"
else else
echo -e "${RED}Something went wrong!${RC}" echo -e "${RED}Something went wrong!${RC}"
fi fi