123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551 |
- #!/usr/bin/env bash
- # Install various binaries directly from GitHub
- # Set script_dir
- script_dir="$(dirname "$(realpath "$0")")"
- bin_dir=${bin_dir:-"/usr/local/bin"}
- delay=${delay:-0.5}
- # Source util lib
- source "${script_dir}/_util"
- # Overide script args if present
- [[ -n "${2}" ]] && bin_dir="${2}"
- [[ -n "${3}" ]] && delay="${3}"
- ran_col_str "Binary install utility" c
- binaries="docker-compose k9s eza bat starship mcfly fzf jq htmlq yq fd upx"
- cmd_arg_help \
- "Program name. Available: ${GREEN}${binaries}${CLEAR}" \
- "Bin path. Set: ${GREEN}${bin_dir}${CLEAR}" \
- "Curl requests delay in seconds: Set: ${GREEN}${delay}${CLEAR}s"
- # Check requirements
- command -v jq >/dev/null || error_msg "Please install jq JSON parsing utility" 1
- # FETCH FUNCTIONS
- function fetch_version_docker_compose {
- # Get latest Docker compose version and print result
- sleep "$delay"
- curl -s "https://api.github.com/repos/docker/compose/tags" |
- # Get all tag names
- jq -r '.[]|.name' |
- # Get latest "vx.x.x" pattern without additional characters
- grep -P -m 1 'v[0-9]+\.[0-9]+\.[0-9]+$'
- }
- function fetch_version_k9s {
- # Get latest k9s version and print result
- sleep "$delay"
- curl -s "https://api.github.com/repos/derailed/k9s/tags" |
- # Get all tag names
- jq -r '.[]|.name' |
- # Get latest "vx.x.x" pattern without additional characters
- grep -P -m 1 'v[0-9]+\.[0-9]+\.[0-9]+$'
- }
- function fetch_version_eza {
- # Get latest eza version and print result
- sleep "$delay"
- curl -s "https://api.github.com/repos/eza-community/eza/tags" |
- # Get all tag names
- jq -r '.[]|.name' |
- # Get latest "vx.x.x" pattern without additional characters
- grep -P -m 1 'v[0-9]+\.[0-9]+\.[0-9]+$'
- }
- function fetch_version_bat {
- # Get latest bat version and print result
- sleep "$delay"
- curl -s "https://api.github.com/repos/sharkdp/bat/tags" |
- # Get all tag names
- jq -r '.[]|.name' |
- # Get latest "vx.x.x" pattern without additional characters
- grep -P -m 1 'v[0-9]+\.[0-9]+\.[0-9]+$'
- }
- function fetch_version_starship {
- # Get latest starship version and print result
- sleep "$delay"
- curl -s "https://api.github.com/repos/starship/starship/tags" |
- # Get all tag names
- jq -r '.[]|.name' |
- # Get latest "vx.x.x" pattern without additional characters
- grep -P -m 1 'v[0-9]+\.[0-9]+\.[0-9]+$'
- }
- function fetch_version_mcfly {
- # Get latest mcfly version and print result
- sleep "$delay"
- curl -s "https://api.github.com/repos/cantino/mcfly/tags" |
- # Get all tag names
- jq -r '.[]|.name' |
- # Get latest "vx.x.x" pattern without additional characters
- grep -P -m 1 'v[0-9]+\.[0-9]+\.[0-9]+$'
- }
- function fetch_version_fzf {
- # Get latest fzf version and print result
- sleep "$delay"
- curl -s "https://api.github.com/repos/junegunn/fzf/tags" |
- # Get all tag names
- jq -r '.[]|.name' |
- # Get latest "x.x.x" pattern without additional characters
- grep -P -m 1 '[0-9]+\.[0-9]+\.[0-9]+$'
- }
- function fetch_version_jq {
- # Get latest jq version and print result
- sleep "$delay"
- curl -s "https://api.github.com/repos/jqlang/jq/tags" |
- # Get all tag names
- jq -r '.[]|.name' |
- # Get latest "jq-x.x" pattern without additional characters
- grep -P -m 1 'jq-[0-9]+\.[0-9]+$'
- }
- function fetch_version_htmlq {
- # Get latest htmlq version and print result
- sleep "$delay"
- curl -s "https://api.github.com/repos/mgdm/htmlq/tags" |
- # Get all tag names
- jq -r '.[]|.name' |
- # Get latest "vx.x.x" pattern without additional characters
- grep -P -m 1 'v[0-9]+\.[0-9]+\.[0-9]+$'
- }
- function fetch_version_yq {
- # Get latest yq version and print result
- sleep "$delay"
- curl -s "https://api.github.com/repos/mikefarah/yq/tags" |
- # Get all tag names
- jq -r '.[]|.name' |
- # Get latest "vx.x.x" pattern without additional characters
- grep -P -m 1 'v[0-9]+\.[0-9]+\.[0-9]+$'
- }
- # TODO
- function fetch_version_ripgrep {
- # Get latest ripgrep version and print result
- sleep "$delay"
- curl -s "https://api.github.com/repos/BurntSushi/ripgrep/tags" |
- # Get all tag names
- jq -r '.[]|.name' |
- # Get latest "vx.x.x" pattern without additional characters
- grep -P -m 1 'v[0-9]+\.[0-9]+\.[0-9]+$'
- }
- function fetch_version_fd {
- # Get latest fd version and print result
- sleep "$delay"
- curl -s "https://api.github.com/repos/sharkdp/fd/tags" |
- # Get all tag names
- jq -r '.[]|.name' |
- # Get latest "vx.x.x" pattern without additional characters
- grep -P -m 1 'v[0-9]+\.[0-9]+\.[0-9]+$'
- }
- function fetch_version_upx {
- # Get latest fd version and print result
- sleep "$delay"
- curl -s "https://api.github.com/repos/upx/upx/tags" |
- # Get all tag names
- jq -r '.[]|.name' |
- # Get latest "vx.x.x" pattern without additional characters
- grep -P -m 1 'v[0-9]+\.[0-9]+\.[0-9]+$'
- }
- case $1 in
- all)
- warning_msg "Installing all binaries: ${binaries}"
- # Create an array from string
- bins=($binaries)
- for b in "${bins[@]}"; do
- # Execute self with all binaries and bin path
- eval "${0} ${b} ${bin_dir}"
- done
- # Create Y/N prompt
- if yes_no_prompt "Compress downloads binaries with upx?"; then
- for b in "${bins[@]}"; do
- # Compress binaries in array
- #sudo upx --best --lzma "${bin_dir}/*"
- if [[ -w "${bin_dir}" ]]; then
- upx --best --lzma "${bin_dir}/${b}"
- else
- sudo upx --best --lzma "${bin_dir}/${b}"
- fi
- done
- success_msg "Binaries compressed with upx!"
- else
- info_msg "Skipping compression"
- fi
- ;;
- docker-compose)
- info_msg "Fetching latest ${1} tag from GitHub"
- version=$(fetch_version_docker_compose)
- [[ -n "${version}" ]] || error_msg "Error fetching version" 1
- info_msg "Setting version to: ${UNDERLINE}${version}"
- url="https://github.com/docker/compose/releases/download/${version}/${1}-$(uname -s)-$(uname -m)"
- sleep "$delay"
- [[ $(check_url "${url}") -ne 0 ]] && error_msg "Bad url" 6
- success_msg "Valid url: ${UNDERLINE}${url}"
- if [[ -w "${bin_dir}" ]]; then
- curl -L "${url}" -o "${bin_dir}/${1}"
- chmod +x "${bin_dir}/${1}"
- else
- sudo curl -L "${url}" -o "${bin_dir}/${1}"
- sudo chmod +x "${bin_dir}/${1}"
- fi
- success_msg "${1} installed"
- docker-compose --version
- ;;
- k9s)
- info_msg "Fetching latest ${1} tag from GitHub"
- version=$(fetch_version_k9s)
- [[ -n "${version}" ]] || error_msg "Error fetching version" 1
- info_msg "Setting version to: ${UNDERLINE}${version}"
- url="https://github.com/derailed/k9s/releases/download/${version}/${1}_$(uname -s)_amd64.tar.gz"
- sleep "$delay"
- [[ $(check_url "${url}") -ne 0 ]] && error_msg "Bad url" 6
- success_msg "Valid url: ${UNDERLINE}${url}"
- [[ -n $(is_x86) ]] || error_msg "Can only download x86 binary. Your arch: $(uname -m)" 1
- # Set vars for file download and untar dir
- down_file="${url##*/}"
- untar_dir="${1}-${version}"
- mkdir -pv "/tmp/${untar_dir}"
- # Download archive and unpack
- curl -L "${url}" -o "/tmp/${down_file}"
- tar -xvf "/tmp/${down_file}" -C "/tmp/${untar_dir}"
- # Make binary excutable and move to bin directory
- chmod +x "/tmp/${untar_dir}/${1}"
- sudo_or_mv "/tmp/${untar_dir}/${1}" "${bin_dir}/"
- # Remove tmp files
- rm -rf "/tmp/${down_file}" "/tmp/${untar_dir}"
- success_msg "${1} installed"
- # k9s version
- ;;
- eza)
- info_msg "Fetching latest ${1} tag from GitHub"
- version=$(fetch_version_eza)
- [[ -n "${version}" ]] || error_msg "Error fetching version" 1
- info_msg "Setting version to: ${UNDERLINE}${version}"
- url="https://github.com/eza-community/eza/releases/download/${version}/${1}_$(uname -m)-unknown-linux-musl.tar.gz"
- sleep "$delay"
- [[ $(check_url "${url}") -ne 0 ]] && error_msg "Bad url" 6
- success_msg "Valid url: ${UNDERLINE}${url}"
- [[ -n $(is_linux) ]] || error_msg "Can only download Linux binary. Your OS: $(uname -s)" 1
- # Set vars for file download and untar dir
- down_file="${url##*/}"
- untar_dir="${1}-${version}"
- mkdir -pv "/tmp/${untar_dir}"
- # Download archive and unpack
- curl -L "${url}" -o "/tmp/${down_file}"
- tar -xvf "/tmp/${down_file}" -C "/tmp/${untar_dir}"
- # Make binary excutable and move to bin directory
- chmod +x "/tmp/${untar_dir}/${1}"
- sudo_or_mv "/tmp/${untar_dir}/${1}" "${bin_dir}/"
- # Remove tmp files
- rm -rf "/tmp/${down_file}" "/tmp/${untar_dir}"
- success_msg "${1} installed"
- # eza --version
- ;;
- bat)
- info_msg "Fetching latest ${1} tag from GitHub"
- version=$(fetch_version_bat)
- [[ -n "${version}" ]] || error_msg "Error fetching version" 1
- info_msg "Setting version to: ${UNDERLINE}${version}"
- url="https://github.com/sharkdp/bat/releases/download/${version}/${1}-${version}-$(uname -m)-unknown-linux-musl.tar.gz"
- sleep "$delay"
- [[ $(check_url "${url}") -ne 0 ]] && error_msg "Bad url" 6
- success_msg "Valid url: ${UNDERLINE}${url}"
- [[ -n $(is_linux) ]] || error_msg "Can only download Linux binary. Your OS: $(uname -s)" 1
- # Set vars for file download and untar dir
- down_file="${url##*/}"
- untar_dir="${1}-${version}"
- mkdir -pv "/tmp/${untar_dir}"
- # Download archive and unpack
- curl -L "${url}" -o "/tmp/${down_file}"
- tar -xvf "/tmp/${down_file}" -C "/tmp/${untar_dir}"
- # Make binary excutable and move to bin directory
- chmod +x "/tmp/${untar_dir}/${1}-${version}-$(uname -m)-unknown-linux-musl/${1}"
- sudo_or_mv "/tmp/${untar_dir}/${1}-${version}-$(uname -m)-unknown-linux-musl/${1}" "${bin_dir}/"
- # Remove tmp files
- rm -rf "/tmp/${down_file}" "/tmp/${untar_dir}"
- success_msg "${1} installed"
- # bat --version
- ;;
- starship)
- info_msg "Fetching latest ${1} tag from GitHub"
- version=$(fetch_version_starship)
- [[ -n "${version}" ]] || error_msg "Error fetching version" 1
- info_msg "Setting version to: ${UNDERLINE}${version}"
- url="https://github.com/starship/starship/releases/download/${version}/${1}-$(uname -m)-unknown-linux-musl.tar.gz"
- sleep "$delay"
- [[ $(check_url "${url}") -ne 0 ]] && error_msg "Bad url" 6
- success_msg "Valid url: ${UNDERLINE}${url}"
- [[ -n $(is_linux) ]] || error_msg "Can only download Linux binary. Your OS: $(uname -s)" 1
- # Set vars for file download and untar dir
- down_file="${url##*/}"
- untar_dir="${1}-${version}"
- mkdir -pv "/tmp/${untar_dir}"
- # Download archive and unpack
- curl -L "${url}" -o "/tmp/${down_file}"
- tar -xvf "/tmp/${down_file}" -C "/tmp/${untar_dir}"
- # Make binary excutable and move to bin directory
- chmod +x "/tmp/${untar_dir}/${1}"
- sudo_or_mv "/tmp/${untar_dir}/${1}" "${bin_dir}/"
- # Remove tmp files
- rm -rf "/tmp/${down_file}" "/tmp/${untar_dir}"
- success_msg "${1} installed"
- # starship --version
- ;;
- mcfly)
- info_msg "Fetching latest ${1} tag from GitHub"
- version=$(fetch_version_mcfly)
- [[ -n "${version}" ]] || error_msg "Error fetching version" 1
- info_msg "Setting version to: ${UNDERLINE}${version}"
- url="https://github.com/cantino/mcfly/releases/download/${version}/${1}-${version}-$(uname -m)-unknown-linux-musl.tar.gz"
- sleep "$delay"
- [[ $(check_url "${url}") -ne 0 ]] && error_msg "Bad url" 6
- success_msg "Valid url: ${UNDERLINE}${url}"
- [[ -n $(is_linux) ]] || error_msg "Can only download Linux binary. Your OS: $(uname -s)" 1
- # Set vars for file download and untar dir
- down_file="${url##*/}"
- untar_dir="${1}-${version}"
- mkdir -pv "/tmp/${untar_dir}"
- # Download archive and unpack
- curl -L "${url}" -o "/tmp/${down_file}"
- tar -xvf "/tmp/${down_file}" -C "/tmp/${untar_dir}"
- # Make binary excutable and move to bin directory
- chmod +x "/tmp/${untar_dir}/${1}"
- sudo_or_mv "/tmp/${untar_dir}/${1}" "${bin_dir}/"
- # Remove tmp files
- rm -rf "/tmp/${down_file}" "/tmp/${untar_dir}"
- success_msg "${1} installed"
- # mcfly --version
- ;;
- fzf)
- info_msg "Fetching latest ${1} tag from GitHub"
- version=$(fetch_version_fzf)
- [[ -n "${version}" ]] || error_msg "Error fetching version" 1
- info_msg "Setting version to: ${UNDERLINE}${version}"
- url="https://github.com/junegunn/fzf/releases/download/${version}/${1}-${version}-linux_amd64.tar.gz"
- sleep "$delay"
- [[ $(check_url "${url}") -ne 0 ]] && error_msg "Bad url" 6
- success_msg "Valid url: ${UNDERLINE}${url}"
- [[ -n $(is_linux) ]] || error_msg "Can only download Linux binary. Your OS: $(uname -s)" 1
- [[ -n $(is_x86) ]] || error_msg "Can only download x86 binary. Your arch: $(uname -m)" 1
- # Set vars for file download and untar dir
- down_file="${url##*/}"
- untar_dir="${1}-${version}"
- mkdir -pv "/tmp/${untar_dir}"
- # Download archive and unpack
- curl -L "${url}" -o "/tmp/${down_file}"
- tar -xvf "/tmp/${down_file}" -C "/tmp/${untar_dir}"
- # Make binary excutable and move to bin directory
- chmod +x "/tmp/${untar_dir}/${1}"
- sudo_or_mv "/tmp/${untar_dir}/${1}" "${bin_dir}/"
- # Remove tmp files
- rm -rf "/tmp/${down_file}" "/tmp/${untar_dir}"
- success_msg "${1} installed"
- # fzf --version
- ;;
- jq)
- info_msg "Fetching latest ${1} tag from GitHub"
- version=$(fetch_version_jq)
- [[ -n "${version}" ]] || error_msg "Error fetching version" 1
- info_msg "Setting version to: ${UNDERLINE}${version}"
- url="https://github.com/jqlang/jq/releases/download/${version}/${1}-linux-amd64"
- sleep "$delay"
- [[ $(check_url "${url}") -ne 0 ]] && error_msg "Bad url" 6
- success_msg "Valid url: ${UNDERLINE}${url}"
- [[ -n $(is_linux) ]] || error_msg "Can only download Linux binary. Your OS: $(uname -s)" 1
- if [[ -w "${bin_dir}" ]]; then
- curl -L "${url}" -o "${bin_dir}/${1}"
- chmod +x "${bin_dir}/${1}"
- else
- sudo curl -L "${url}" -o "${bin_dir}/${1}"
- sudo chmod +x "${bin_dir}/${1}"
- fi
- success_msg "${1} installed"
- # jq --version
- ;;
- htmlq)
- info_msg "Fetching latest ${1} tag from GitHub"
- version=$(fetch_version_htmlq)
- [[ -n "${version}" ]] || error_msg "Error fetching version" 1
- info_msg "Setting version to: ${UNDERLINE}${version}"
- url="https://github.com/mgdm/htmlq/releases/download/${version}/${1}-$(uname -m)-linux.tar.gz"
- sleep "$delay"
- [[ $(check_url "${url}") -ne 0 ]] && error_msg "Bad url" 6
- success_msg "Valid url: ${UNDERLINE}${url}"
- [[ -n $(is_linux) ]] || error_msg "Can only download Linux binary. Your OS: $(uname -s)" 1
- # Set vars for file download and untar dir
- down_file="${url##*/}"
- untar_dir="${1}-${version}"
- mkdir -pv "/tmp/${untar_dir}"
- # Download archive and unpack
- curl -L "${url}" -o "/tmp/${down_file}"
- tar -xvf "/tmp/${down_file}" -C "/tmp/${untar_dir}"
- # Make binary excutable and move to bin directory
- chmod +x "/tmp/${untar_dir}/${1}"
- sudo_or_mv "/tmp/${untar_dir}/${1}" "${bin_dir}/"
- # Remove tmp files
- rm -rf "/tmp/${down_file}" "/tmp/${untar_dir}"
- success_msg "${1} installed"
- # htmlq --version
- ;;
- yq)
- info_msg "Fetching latest ${1} tag from GitHub"
- version=$(fetch_version_yq)
- [[ -n "${version}" ]] || error_msg "Error fetching version" 1
- info_msg "Setting version to: ${UNDERLINE}${version}"
- url="https://github.com/mikefarah/yq/releases/download/${version}/${1}_linux_amd64"
- sleep "$delay"
- [[ $(check_url "${url}") -ne 0 ]] && error_msg "Bad url" 6
- success_msg "Valid url: ${UNDERLINE}${url}"
- [[ -n $(is_linux) ]] || error_msg "Can only download Linux binary. Your OS: $(uname -s)" 1
- [[ -n $(is_x86) ]] || error_msg "Can only download x86 binary. Your arch: $(uname -m)" 1
- if [[ -w "${bin_dir}" ]]; then
- curl -L "${url}" -o "${bin_dir}/${1}"
- chmod +x "${bin_dir}/${1}"
- else
- sudo curl -L "${url}" -o "${bin_dir}/${1}"
- sudo chmod +x "${bin_dir}/${1}"
- fi
- success_msg "${1} installed"
- # yq --version
- ;;
- fd)
- info_msg "Fetching latest ${1} tag from GitHub"
- version=$(fetch_version_fd)
- [[ -n "${version}" ]] || error_msg "Error fetching version" 1
- info_msg "Setting version to: ${UNDERLINE}${version}"
- url="https://github.com/sharkdp/fd/releases/download/${version}/${1}-${version}-$(uname -m)-unknown-linux-musl.tar.gz"
- sleep "$delay"
- [[ $(check_url "${url}") -ne 0 ]] && error_msg "Bad url" 6
- success_msg "Valid url: ${UNDERLINE}${url}"
- [[ -n $(is_linux) ]] || error_msg "Can only download Linux binary. Your OS: $(uname -s)" 1
- # Set vars for file download and untar dir
- down_file="${url##*/}"
- untar_dir="${1}-${version}"
- mkdir -pv "/tmp/${untar_dir}"
- # Download archive and unpack
- curl -L "${url}" -o "/tmp/${down_file}"
- tar -xvf "/tmp/${down_file}" -C "/tmp/${untar_dir}"
- # Make binary excutable and move to bin directory
- chmod +x "/tmp/${untar_dir}/${1}-${version}-$(uname -m)-unknown-linux-musl/${1}"
- sudo_or_mv "/tmp/${untar_dir}/${1}-${version}-$(uname -m)-unknown-linux-musl/${1}" "${bin_dir}/"
- # Remove tmp files
- rm -rf "/tmp/${down_file}" "/tmp/${untar_dir}"
- success_msg "${1} installed"
- # fd --version
- ;;
- upx)
- info_msg "Fetching latest ${1} tag from GitHub"
- version=$(fetch_version_upx)
- [[ -n "${version}" ]] || error_msg "Error fetching version" 1
- info_msg "Setting version to: ${UNDERLINE}${version}"
- url="https://github.com/upx/upx/releases/download/${version}/${1}-${version##*v}-amd64_linux.tar.xz"
- sleep "$delay"
- [[ $(check_url "${url}") -ne 0 ]] && error_msg "Bad url" 6
- success_msg "Valid url: ${UNDERLINE}${url}"
- [[ -n $(is_linux) ]] || error_msg "Can only download Linux binary. Your OS: $(uname -s)" 1
- [[ -n $(is_x86) ]] || error_msg "Can only download x86 binary. Your arch: $(uname -m)" 1
- # Set vars for file download and untar dir
- down_file="${url##*/}"
- untar_dir="${1}-${version}"
- mkdir -pv "/tmp/${untar_dir}"
- # Download archive and unpack
- curl -L "${url}" -o "/tmp/${down_file}"
- tar -xvf "/tmp/${down_file}" -C "/tmp/${untar_dir}"
- # Make binary excutable and move to bin directory
- chmod +x "/tmp/${untar_dir}/${1}-${version##*v}-amd64_linux/${1}"
- sudo_or_mv "/tmp/${untar_dir}/${1}-${version##*v}-amd64_linux/${1}" "${bin_dir}/"
- # Remove tmp files
- rm -rf "/tmp/${down_file}" "/tmp/${untar_dir}"
- success_msg "${1} installed"
- # upx --version
- ;;
- *)
- error_msg "Unknown program: ${CLEAR}${UNDERLINE}${1}"
- error_msg "List of available binaries: ${CLEAR}${UNDERLINE}${binaries}" 1
- ;;
- esac
|