diff --git a/.bashrc b/.bashrc index 4a23f35..3489375 100644 --- a/.bashrc +++ b/.bashrc @@ -601,4 +601,11 @@ eval "$(starship init bash)" #Autojump -. /usr/share/autojump/autojump.sh +if [ -f "/usr/share/autojump/autojump.sh" ]; then + . /usr/share/autojump/autojump.sh +elif [ -f "/usr/share/autojump/autojump.bash" ]; then + . /usr/share/autojump/autojump.bash +else + echo "can't found the autojump script" +fi + diff --git a/setup-arch.sh b/setup-arch.sh new file mode 100755 index 0000000..9f0ee16 --- /dev/null +++ b/setup-arch.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +RC='\e[0m' +RED='\e[31m' +YELLOW='\e[33m' +GREEN='\e[32m' + +checkEnv(){ + ## 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 + fi + + ## Check for requirements. + REQUIREMENTS='curl yay sudo' + if ! which ${REQUIREMENTS}>/dev/null;then + echo -e "${RED}To run me,https://github.com/fearlessgeekmedia/mybash you need: ${REQUIREMENTS}${RC}" + exit 1 + fi + + ## Check if member of the wheel group. + if ! groups|grep wheel>/dev/null;then + echo -e "${RED}You need to be a member of the wheel to run me!" + exit 1 + fi +} + +installDepend(){ + ## Check for dependencies. + # For some reason, if I put autojump in the original DEPENDENCIES variable, + # it skips the installation and just does bash and bash completion. So I + # put autojump in a separate variable and separate yay command. + DEPENDENCIES1='bash bash-completion' + DEPENDENCIES2='autojump' + echo -e "${YELLOW}Installing dependencies...${RC}" + yay -S ${DEPENDENCIES1} + yay -S ${DEPENDENCIES2} + sudo mkdir /usr/local/bin/autojump + sudo ln -s /etc/profile.d/autojump.sh /usr/share/autojump/autojump.sh +} + +installStarship(){ + if ! curl -sS https://starship.rs/install.sh|sh;then + echo -e "${RED}Something went wrong during starship install!${RC}" + exit 1 + fi +} + +linkConfig(){ + ## Check if a bashrc file is already there. + OLD_BASHRC="${HOME}/.bashrc" + if [[ -e ${OLD_BASHRC} ]];then + echo -e "${YELLOW}Moving old bash config file to ${HOME}/.bashrc.bak${RC}" + if ! mv ${OLD_BASHRC} ${HOME}/.bashrc.bak;then + echo -e "${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 ${HOME}/.bashrc + ln -svf ${GITPATH}/starship.toml ${HOME}/.config/starship.toml +} + +checkEnv +installDepend +installStarship +if linkConfig;then + echo -e "${GREEN}Done!\nrestart your shell to see the changes.${RC}" +else + echo -e "${RED}Something went wrong!${RC}" +fi diff --git a/setup.sh b/setup.sh old mode 100755 new mode 100644 index 5088e34..3aa5111 --- a/setup.sh +++ b/setup.sh @@ -43,17 +43,29 @@ checkEnv() { echo -e "${RED}You need to be a member of the sudo group to run me!" exit 1 fi + + if [[ ! -x "/usr/bin/apt-get" ]] && [[ ! -x "/usr/bin/yum" ]] && [[ ! -x "/usr/bin/dnf" ]]; then + echo -e "Can't find a supported package manager" + exit 1 + fi + } installDepend() { ## Check for dependencies. - DEPENDENCIES='autojump bash bash-completion' + DEPENDENCIES='autojump bash bash-completion tar neovim' echo -e "${YELLOW}Installing dependencies...${RC}" sudo ${PACKAGER} install -yq ${DEPENDENCIES} } -installStarship() { - if ! curl -sS https://starship.rs/install.sh | sudo sh; then +installStarship(){ + STARSHIP_CMD==$(which starship) + if [[ ! -z $STARSHIP_CMD ]]; then + echo "Starship already installed" + return + fi + + if ! curl -sS https://starship.rs/install.sh|sh;then echo -e "${RED}Something went wrong during starship install!${RC}" exit 1 fi