Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/bash
- # define bash directory
- BASH_DIR="${HOME}"/scripts/bash/
- #decide on packages
- # get os
- if [[ $(uname -s) == "Darwin" ]]
- then
- OS="macos"
- elif [[ $(uname -s) == "Linux" ]]
- then
- if [[ -f /etc/arch-release ]]
- then
- OS="arch"
- elif [[ -f /etc/debian_version ]]
- then
- OS="debian"
- fi
- else
- exit 1
- fi
- case $OS in
- macos)
- GHI="ghi"
- FD="fd"
- ;;
- arch)
- GHI="ghi"
- FD="fd"
- ;;
- debian)
- GHI="ghi"
- FD="fd-find" #command is fdfind
- ;;
- esac
- # Check if brew exists; if not, which package manager
- if command -v brew > /dev/null 2>&1
- then
- PACMAN='brew install'
- PACSEARCH='brew list'
- else
- declare -A osInfo;
- osInfo[/etc/redhat-release]='sudo yum install'
- osInfo[/etc/arch-release]='sudo pacman -S'
- osInfo[/etc/gentoo-release]='sudo emerge'
- osInfo[/etc/SuSE-release]='sudo zypper in'
- osInfo[/etc/debian_version]='sudo apt install -y'
- declare -A osSearch;
- osInfo[/etc/redhat-release]='yum list installed'
- osInfo[/etc/arch-release]='sudo pacman -Q'
- osSearch[/etc/gentoo-release]="cd /var/db/pkg/ && ls -d */*| sed 's/\/$//'"
- osSearch[/etc/SuSE-release]='rpm -qa'
- osSearch[/etc/debian_version]='apt list --installed'
- for f in "${!osInfo[@]}"
- do
- if [[ -f $f ]];then
- PACMAN="${osInfo[$f]}"
- fi
- done
- for s in "${!osSearch[@]}"
- do
- if [[ -f $s ]];then
- PACSEARCH="${osSearch[$s]}"
- fi
- done
- fi
- # Ensure jq is installed
- if ! command -v jq > /dev/null 2>&1
- then
- echo -e "\u001b[1;38mInstalling \`jq\`...\u001b[0;38m" && \
- $PACMAN jq && \
- echo -e "\u001b[1;38;5;2m\`jq\` installed successfully\u001b[0;38m"
- fi
- # Parse json colours to bash
- jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' ${BASH_DIR}/colours/textcolours.json | \
- sed -e 's/=\([^" >][^ >]*\)/="\1"/g' >> \
- ${BASH_DIR}/textcolours.txt && source ${BASH_DIR}/textcolours.txt
- # Clean up
- clean-exit() {
- [[ -f ${BASH_DIR}/textcolours.txt ]] && \
- rm ${BASH_DIR}/textcolours.txt
- exit $?
- }
- brew_install() {
- PACINSTALL=false
- for i in "${@}"; #previously @:2
- do
- if ! command -v "${i}" > /dev/null 2>&1
- then
- PACINSTALL=true
- $PACMAN "${i}"
- fi
- done
- if [ "${PACINSTALL}" = true ]
- then
- return 0
- else
- return 1
- fi
- }
- is-command-then-install() {
- #install deps if command is not found
- for i in "${@}"
- do
- brew_install "${i}"
- done
- }
- # get script dependencies
- is-command-then-install "${GHI}"
- # Clean up
- clean-exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement