merged github

pull/2/head
Hari Sekhon 4 years ago
commit 730caea7a3

@ -40,6 +40,7 @@ alias dockerimg='$EDITOR "$bash_tools/setup/docker-images.txt"'
alias dockerrm='docker rm $(docker ps -qf status=exited)'
alias dockerr=dockerrunrm
alias dock=dockerr
alias dockere=dockerexec
alias de=dockere

@ -29,7 +29,7 @@ doesn't detect shell code properly
[![Alpine](https://img.shields.io/badge/Linux-Alpine-0D597F?logo=alpine%20linux&color=0D597F)](https://alpinelinux.org/)
[![CentOS](https://img.shields.io/badge/Linux-CentOS-red?logo=centos&color=262577&logoColor=white)](https://www.centos.org/)
[![Debian](https://img.shields.io/badge/Linux-Debian-red?logo=debian&color=A81D33)](https://www.debian.org/)
[![Fedora](https://img.shields.io/badge/Linux-Fedora-294172?logo=fedora)](https://www.redhat.com/en)
[![Fedora](https://img.shields.io/badge/Linux-Fedora-294172?logo=fedora)](https://getfedora.org/)
[![Redhat](https://img.shields.io/badge/Linux-Redhat-red?logo=red%20hat)](https://www.redhat.com/en)
[![Ubuntu](https://img.shields.io/badge/Linux-Ubuntu-orange?logo=ubuntu&logoColor=white)](https://ubuntu.com/)
[![Mac Homebrew](https://img.shields.io/badge/Mac-Homebrew-999999?logo=apple&logoColor=white)](https://brew.sh/)
@ -346,6 +346,17 @@ etc.
- `spotify_api.sh` - query any Spotify [API](https://developer.spotify.com/documentation/web-api/reference/) endpoint with authentication, used by all other scripts
- `json2yaml.sh` - converts JSON to YAML
- `yaml2json.sh` - converts YAML to JSON - needed for some APIs like GitLab CI linting (see `gitlab_*.sh` section above)
- OS / Distro Package Management:
- `install_packages.sh` - installs package lists from arguments, files or stdin on major linux distros and Mac, detecting the package manager and invoking the right install commands, with `sudo` if not root. Works on [RHEL](https://www.redhat.com/en) / [CentOS](https://www.centos.org/) / [Fedora](https://getfedora.org/), [Debian](https://www.debian.org/) / [Ubuntu](https://ubuntu.com/), [Alpine](https://alpinelinux.org/), and [Mac Homebrew](https://brew.sh/). Leverages and supports all features of the distro / OS specific install scripts listed below
- `install_packages_if_absent.sh` - installs package lists if they're not already installed, saving time and minimizing install logs / CI logs, same support list as above
- `yum_install_packages.sh` / `yum_remove_packages.sh` - installs RPM lists from arguments, files or stdin. Handles Yum + Dnf behavioural differences, calls `sudo` if not root, auto-attempts variations of python/python2/python3 package names. Avoids yum slowness by checking if rpm is installed before attempting to install it, accepts `NO_FAIL=1` env var to ignore unavailable / changed package names (useful for optional packages or attempts for different package names across RHEL/CentOS/Fedora versions)
- `yum_install_if_absent.sh` - installs RPMs only if not already installed and not a metapackage provided by other packages (eg. `vim` metapackage provided by `vim-enhanced`), saving time and minimizing install logs / CI logs, plus all the features of `yum_install_packages.sh` above
- `apt_install_packages.sh` / `apt_remove_packages.sh` - installs Deb package lists from arguments, files or stdin. Auto calls `sudo` if not root, accepts `NO_FAIL=1` env var to ignore unavailable / changed package names (useful for optional packages or attempts for different package names across Debian/Ubuntu distros/versions)
- `apt_install_if_absent.sh` - installs Deb packages only if not already installed, saving time and minimizing install logs / CI logs, plus all the features of `apt_install_packages.sh` above
- `apk_install_packages.sh` / `apk_remove_packages.sh` - installs Alpine apk package lists from arguments, files or stdin. Auto calls `sudo` if not root, accepts `NO_FAIL=1` env var to ignore unavailable / changed package names (useful for optional packages or attempts for different package names across Alpine versions)
- `apk_install_if_absent.sh` - installs Alpine apk packages only if not already installed, saving time and minimizing install logs / CI logs, plus all the features of `apk_install_packages.sh` above
- `brew_install_packages.sh` / `brew_remove_packages.sh` - installs Mac Hombrew package lists from arguments, files or stdin. Accepts `NO_FAIL=1` env var to ignore unavailable / changed package names (useful for optional packages or attempts for different package names across versions)
- `brew_install_if_absent.sh` - installs Mac Homebrew packages only if not already installed, saving time and minimizing install logs / CI logs, plus all the features of `brew_install_packages.sh` above
- all builds across all my GitHub repos now `make system-packages` before `make pip` / `make cpan` to shorten how many packages need installing, reducing chances of build failures
- `check_*.sh` - extensive collection of generalized tests - these run against all my GitHub repos via [CI](https://bitbucket.org/harisekhon/devops-bash-tools/src/master/STATUS.md). Some examples:

@ -0,0 +1,51 @@
#!/bin/sh
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2020-08-24 00:05:26 +0100 (Mon, 24 Aug 2020)
#
# https://github.com/harisekhon/bash-tools
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
#
# https://www.linkedin.com/in/harisekhon
#
set -euo pipefail
[ -n "${DEBUG:-}" ] && set -x
srcdir="$(dirname "$0")"
# shellcheck disable=SC1090
. "$srcdir/lib/packages.sh"
# shellcheck disable=SC2154
usage(){
cat <<EOF
Checks a given list of APK packages and returns those already installed
$package_args_description
Tested on Alpine
usage: ${0##*/} <packages>
EOF
exit 3
}
for arg; do
case "$arg" in
-*) usage
;;
esac
done
installed_packages="$(mktemp)"
trap 'rm -f "$installed_packages"' EXIT
installed_apk > "$installed_packages"
process_package_args "$@" |
grep -Fx -f "$installed_packages"

@ -0,0 +1,51 @@
#!/bin/sh
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2020-08-24 00:05:26 +0100 (Mon, 24 Aug 2020)
#
# https://github.com/harisekhon/bash-tools
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
#
# https://www.linkedin.com/in/harisekhon
#
set -euo pipefail
[ -n "${DEBUG:-}" ] && set -x
srcdir="$(dirname "$0")"
# shellcheck disable=SC1090
. "$srcdir/lib/packages.sh"
# shellcheck disable=SC2154
usage(){
cat <<EOF
Checks a given list of APK packages and returns those not installed
$package_args_description
Tested on Alpine
usage: ${0##*/} <packages>
EOF
exit 3
}
for arg; do
case "$arg" in
-*) usage
;;
esac
done
installed_packages="$(mktemp)"
trap 'rm -f "$installed_packages"' EXIT
installed_apk > "$installed_packages"
process_package_args "$@" |
grep -vFx -f "$installed_packages"

@ -30,9 +30,9 @@ srcdir="$(dirname "$0")"
usage(){
echo "Installs Alpine APK package lists"
echo
echo "Takes a list of apk packages as arguments or .txt files containing lists of packages (one per line)"
echo "Takes a list of apk packages as arguments or via stdin, and for any arguments that are plaintext files, reads the packages from those given files (one package per line)"
echo
echo "usage: ${0##*} <list_of_packages>"
echo "usage: ${0##*/} <list_of_packages>"
echo
exit 3
}

@ -0,0 +1,48 @@
#!/bin/sh
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2019-02-15 21:31:10 +0000 (Fri, 15 Feb 2019)
#
# https://github.com/harisekhon/bash-tools
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
#
# https://www.linkedin.com/in/harisekhon
#
set -eu
[ -n "${DEBUG:-}" ] && set -x
srcdir="$(dirname "$0")"
# shellcheck disable=SC1090
. "$srcdir/lib/packages.sh"
# shellcheck disable=SC2154
usage(){
cat <<EOF
Installs Alpine APK package lists if the packages aren't already installed
$package_args_description
Tested on Alpine
usage: ${0##*/} <packages>
EOF
exit 3
}
for arg; do
case "$arg" in
-*) usage
;;
esac
done
process_package_args "$@" |
"$srcdir/apk_filter_not_installed.sh" |
xargs -r "$srcdir/apk_install_packages.sh"

@ -30,9 +30,9 @@ srcdir="$(dirname "$0")"
usage(){
echo "Installs Debian / Ubuntu deb package lists"
echo
echo "Takes a list of deb packages as arguments or .txt files containing lists of packages (one per line)"
echo "Takes a list of deb packages as arguments or via stdin, and for any arguments that are plaintext files, reads the packages from those given files (one package per line)"
echo
echo "usage: ${0##*} <list_of_packages>"
echo "usage: ${0##*/} <list_of_packages>"
echo
exit 3
}

@ -0,0 +1,45 @@
#!/usr/bin/env bash
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2020-08-23 18:38:39 +0100 (Sun, 23 Aug 2020)
#
# https://github.com/harisekhon/bash-tools
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
#
# https://www.linkedin.com/in/harisekhon
#
set -eu
[ -n "${DEBUG:-}" ] && set -x
srcdir="$(dirname "${BASH_SOURCE[0]}")"
# shellcheck disable=SC1090
. "$srcdir/lib/utils.sh"
# shellcheck disable=SC1090
. "$srcdir/lib/packages.sh"
# shellcheck disable=SC2034,SC2154
usage_description="
Installs Debian / Ubuntu deb package lists if the packages aren't already installed
$package_args_description
Tested on Debian and Ubuntu
"
# used by usage() in lib/utils.sh
# shellcheck disable=SC2034
usage_args="<packages>"
help_usage "$@"
export DEBIAN_FRONTEND=noninteractive
process_package_args "$@" |
"$srcdir/debs_filter_not_installed.sh" |
xargs --no-run-if-empty "$srcdir/apt_install_packages.sh"

@ -0,0 +1,58 @@
#!/usr/bin/env bash
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2020-08-24 00:42:27 +0100 (Mon, 24 Aug 2020)
#
# https://github.com/harisekhon/bash-tools
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
#
# https://www.linkedin.com/in/harisekhon
#
set -euo pipefail
[ -n "${DEBUG:-}" ] && set -x
srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck disable=SC1090
. "$srcdir/lib/utils.sh"
# shellcheck disable=SC1090
. "$srcdir/lib/packages.sh"
# shellcheck disable=SC2034,SC2154
usage_description="
Checks a given list of Mac Homebrew packages and returns those already installed
$package_args_description
Support TAP=1 or CASK=1 environment variables for checking taps or casks respectively
Tested on Mac Homebrew
"
# used by usage() in lib/utils.sh
# shellcheck disable=SC2034
usage_args="<packages>"
help_usage "$@"
process_package_args "$@" |
if [ -n "${TAP:-}" ]; then
if [ -n "${NO_FAIL:-}" ]; then
set +e
fi
installed_packages="$(brew list)"
while read -r tap package; do
grep -Fxq "$package" <<< "$installed_packages" &&
echo "$tap $package"
done
else
# do not quote cask, blank quotes break shells and there will never be any token splitting anyway
# shellcheck disable=SC2046
tr ' ' '\n' |
grep -Fx -f <(brew $([ -z "${CASK:-}" ] || echo cask) list)
fi

@ -0,0 +1,58 @@
#!/usr/bin/env bash
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2020-08-24 00:42:27 +0100 (Mon, 24 Aug 2020)
#
# https://github.com/harisekhon/bash-tools
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
#
# https://www.linkedin.com/in/harisekhon
#
set -euo pipefail
[ -n "${DEBUG:-}" ] && set -x
srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck disable=SC1090
. "$srcdir/lib/utils.sh"
# shellcheck disable=SC1090
. "$srcdir/lib/packages.sh"
# shellcheck disable=SC2034,SC2154
usage_description="
Checks a given list of Mac Homebrew packages and returns those not installed
$package_args_description
Supports TAP=1 or CASK=1 environment variables for checking taps or casks respectively
Tested on Mac Homebrew
"
# used by usage() in lib/utils.sh
# shellcheck disable=SC2034
usage_args="<packages>"
help_usage "$@"
process_package_args "$@" |
if [ -n "${TAP:-}" ]; then
if [ -n "${NO_FAIL:-}" ]; then
set +e
fi
installed_packages="$(brew list)"
while read -r tap package; do
grep -Fxq "$package" <<< "$installed_packages" ||
echo "$tap $package"
done
else
# do not quote cask, blank quotes break shells and there will never be any token splitting anyway
# shellcheck disable=SC2046
tr ' ' '\n' |
grep -vFx -f <(brew $([ -z "${CASK:-}" ] || echo cask) list)
fi

@ -0,0 +1,46 @@
#!/usr/bin/env bash
# shellcheck disable=SC2086
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2020-08-23 19:03:51 +0100 (Sun, 23 Aug 2020)
#
# https://github.com/harisekhon/bash-tools
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
#
# https://www.linkedin.com/in/harisekhon
#
# Mac OSX - HomeBrew install packages in a forgiving way
set -eu #o pipefail # undefined in /bin/sh
[ -n "${DEBUG:-}" ] && set -x
srcdir="$(dirname "${BASH_SOURCE[0]}")"
# shellcheck disable=SC1090
. "$srcdir/lib/utils.sh"
# shellcheck disable=SC1090
. "$srcdir/lib/packages.sh"
# shellcheck disable=SC2034,SC2154
usage_description="
Installs Mac Homebrew package lists if the packages aren't already installed
$package_args_description
Tested on CentOS
"
# used by usage() in lib/utils.sh
# shellcheck disable=SC2034
usage_args="<packages>"
help_usage "$@"
process_package_args "$@" |
"$srcdir/brew_filter_not_installed.sh" |
gxargs --no-run-if-empty "$srcdir/brew_install_packages.sh"

@ -0,0 +1,44 @@
#!/usr/bin/env bash
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2020-08-23 23:25:39 +0100 (Sun, 23 Aug 2020)
#
# https://github.com/harisekhon/bash-tools
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
#
# https://www.linkedin.com/in/harisekhon
#
set -euo pipefail
[ -n "${DEBUG:-}" ] && set -x
srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck disable=SC1090
. "$srcdir/lib/utils.sh"
# shellcheck disable=SC1090
. "$srcdir/lib/packages.sh"
# shellcheck disable=SC2034,SC2154
usage_description="
Checks a given list of Deb packages and returns those already installed
$package_args_description
Tested on Debian and Ubuntu
"
# used by usage() in lib/utils.sh
# shellcheck disable=SC2034
usage_args="<packages>"
help_usage "$@"
export DEBIAN_FRONTEND=noninteractive
process_package_args "$@" |
grep -Fx -f <(installed_debs)

@ -0,0 +1,44 @@
#!/usr/bin/env bash
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2020-08-23 23:25:39 +0100 (Sun, 23 Aug 2020)
#
# https://github.com/harisekhon/bash-tools
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
#
# https://www.linkedin.com/in/harisekhon
#
set -euo pipefail
[ -n "${DEBUG:-}" ] && set -x
srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck disable=SC1090
. "$srcdir/lib/utils.sh"
# shellcheck disable=SC1090
. "$srcdir/lib/packages.sh"
# shellcheck disable=SC2034,SC2154
usage_description="
Checks a given list of Deb packages and returns those not installed
$package_args_description
Tested on Debian and Ubuntu
"
# used by usage() in lib/utils.sh
# shellcheck disable=SC2034
usage_args="<packages>"
help_usage "$@"
export DEBIAN_FRONTEND=noninteractive
process_package_args "$@" |
grep -vFx -f <(installed_debs)

@ -17,8 +17,6 @@ set -euo pipefail
[ -n "${DEBUG:-}" ] && set -x
srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
#. "$srcdir/lib/utils.sh"
if type -P apk &>/dev/null; then
"$srcdir/apk_install_packages.sh" "$@"
elif type -P apt-get &>/dev/null; then

@ -0,0 +1,39 @@
#!/usr/bin/env bash
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2020-08-23 17:28:41 +0100 (Sun, 23 Aug 2020)
#
# https://github.com/harisekhon/bash-tools
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
#
# https://www.linkedin.com/in/harisekhon
#
# Caveat: doesn't catch metapackages eg. vim on centos is resolved to vim-enhanced and doesn't match to prevent trying to install again
set -euo pipefail
[ -n "${DEBUG:-}" ] && set -x
srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
packages=("$@")
check_bin(){
type -P "$@" &>/dev/null
}
if check_bin apk; then
"$srcdir/apk_install_packages_if_absent.sh" "${packages[@]}"
elif check_bin apt-get dpkg; then
"$srcdir/apt_install_packages_if_absent.sh" "${packages[@]}"
elif check_bin yum rpm; then
"$srcdir/yum_install_packages_if_absent.sh" "${packages[@]}"
elif check_bin brew; then
"$srcdir/brew_install_packages_if_absent.sh" "${packages[@]}"
else
echo "Unsupported OS / Package Manager"
exit 1
fi

@ -0,0 +1,86 @@
#!/bin/sh
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2020-08-23 23:30:31 +0100 (Sun, 23 Aug 2020)
#
# https://github.com/harisekhon/bash-tools
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
#
# https://www.linkedin.com/in/harisekhon
#
# Used on Alpine so needs to be /bin/sh
set -euo pipefail
[ -n "${DEBUG:-}" ] && set -x
# used in client code
# shellcheck disable=SC2034
package_args_description="Takes a list of packages as arguments or via stdin, and for any arguments that are plaintext files, reads the packages from those given files (one package per line)"
packages=""
_process_package_args(){
for arg; do
if [ -f "$arg" ] && file "$arg" | grep -q ASCII; then
echo "adding packages from file: $arg" >&2
packages="$packages $(sed 's/#.*//;/^[[:space:]]*$$/d' "$arg")"
echo >&2
else
packages="$packages $arg"
fi
done
# Homebrew tap package lists are in format "tap package" and those lines should not be split
echo "$packages" |
if [ -n "${TAP:-}" ]; then
cat
else
tr ' ' '\n' |
sort -u
fi |
grep -v '^[[:space:]]*$'
}
process_package_args(){
if [ -n "${*:-}" ]; then
_process_package_args "$@"
else
# shellcheck disable=SC2046
_process_package_args $(cat)
fi
}
installed_apk(){
apk info 2>/dev/null
}
installed_debs(){
dpkg-query -W -f '${db:Status-Abbrev}\t${binary:Package}\n' |
awk '/^i/{print $2}' |
sed 's/:.*$//' |
sort -u
}
installed_rpms(){
rpm -qa --queryformat '%{RPMTAG_NAME}\n'
}
rpms_filter_provided(){
while read -r rpm; do
# accounts for vim being provided by vim-enhanced, so we don't try to install the metapackage again and again
rpm -q --whatprovides "$rpm" >/dev/null 2>&1 &&
echo "$rpm"
done
}
rpms_filter_not_provided(){
while read -r rpm; do
# accounts for vim being provided by vim-enhanced, so we don't try to install the metapackage again and again
rpm -q --whatprovides "$rpm" >/dev/null 2>&1 ||
echo "$rpm"
done
}

@ -0,0 +1,42 @@
#!/usr/bin/env bash
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2020-08-23 23:53:52 +0100 (Sun, 23 Aug 2020)
#
# https://github.com/harisekhon/bash-tools
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
#
# https://www.linkedin.com/in/harisekhon
#
set -euo pipefail
[ -n "${DEBUG:-}" ] && set -x
srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck disable=SC1090
. "$srcdir/lib/utils.sh"
# shellcheck disable=SC1090
. "$srcdir/lib/packages.sh"
# shellcheck disable=SC2034,SC2154
usage_description="
Checks a given list of RPM packages and returns those already installed
$package_args_description
Tested on CentOS
"
# used by usage() in lib/utils.sh
# shellcheck disable=SC2034
usage_args="<packages>"
help_usage "$@"
process_package_args "$@" |
grep -Fx -f <(installed_rpms)

@ -0,0 +1,42 @@
#!/usr/bin/env bash
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2020-08-23 23:53:52 +0100 (Sun, 23 Aug 2020)
#
# https://github.com/harisekhon/bash-tools
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
#
# https://www.linkedin.com/in/harisekhon
#
set -euo pipefail
[ -n "${DEBUG:-}" ] && set -x
srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck disable=SC1090
. "$srcdir/lib/utils.sh"
# shellcheck disable=SC1090
. "$srcdir/lib/packages.sh"
# shellcheck disable=SC2034,SC2154
usage_description="
Checks a given list of RPM packages and returns those not installed
$package_args_description
Tested on CentOS
"
# used by usage() in lib/utils.sh
# shellcheck disable=SC2034
usage_args="<packages>"
help_usage "$@"
process_package_args "$@" |
grep -vFx -f <(installed_rpms)

@ -3,7 +3,7 @@
# Date: 2011-06-01 16:58:33 +0000 (Wed, 01 Jun 2011)
#
# CASK=1 ../brew_install_packages.sh brew-packages-desktop-casks.txt
# run: CASK=1 ../brew_install_packages.sh brew-packages-desktop-casks.txt
anaconda
atom

@ -3,7 +3,7 @@
# Date: 2019-12-19 15:08:01 +0000 (Thu, 19 Dec 2019)
#
# TAP=1 ../brew_install_packages.sh brew-packages-desktop-taps.txt
# run: TAP=1 ../brew_install_packages.sh brew-packages-desktop-taps.txt
# tap package
# do via install script to load token

@ -16,14 +16,14 @@
azure-cli
cmake
coreutils
cpanm
cpanminus
direnv
findutils
gawk
git-secrets
gnu-sed
gnu-tar
golang
go
grep # gnu version better than Mac version
jq
jwhois

@ -29,4 +29,7 @@ if ! [ -e "$target" ]; then
git clone https://github.com/gmarik/Vundle.vim.git "$target"
fi
vim +PluginInstall +qall
date "+%F %T Installing Vim Vundle plugins..."
# this tends to mess up the terminal and requires a reset afterwards
vim --not-a-term +PluginInstall +qall >/dev/null
date "+%F %T Finished installing Vim Vundle plugins"

@ -56,14 +56,14 @@ for filename in $conf_files; do
mkdir -pv ~/"$dirname"
# want opt expansion
# shellcheck disable=SC2086
ln -sv $opts "$PWD/$dirname/$filename" ~/"$dirname"/ || continue
ln -sv $opts "$PWD/$dirname/$filename" ~/"$dirname"/ || :
else
# want opt expansion
# shellcheck disable=SC2086
ln -sv $opts "$PWD/$filename" ~ || continue
# if we link .vimrc then run the vundle install and get plugins to prevent vim errors every startup
if [ "$filename" = .vimrc ]; then
"$srcdir/setup/install_vundle.sh" || continue
"$srcdir/setup/install_vundle.sh" || :
fi
fi
done

@ -70,6 +70,6 @@ timestamp "installing: $packages"
# want splitting
# shellcheck disable=SC2086
./install_packages.sh $packages
./install_packages_if_absent.sh $packages
} 2>&1 | tee -a /vagrant/logs/provision.log

@ -49,7 +49,7 @@ elif [ -f /vagrant/Vagrantfile ]; then
# auto-detect when running inside a Vagrant VM
Vagrantfile=/vagrant/Vagrantfile
else
usage "Vagrantfile not specified and no Vagrantfile found in \$PWD"
usage "Vagrantfile not specified and no Vagrantfile found in \$PWD or /vagrant/"
fi
sed 's/#.*//; /^[[:space:]]*$/d' "$Vagrantfile" |

@ -0,0 +1,55 @@
#!/usr/bin/env bash
# vim:ts=4:sts=4:sw=4:et
# args: vagrant/kubernetes/Vagrantfile
#
# Author: Hari Sekhon
# Date: 2020-08-23 23:08:43 +0100 (Sun, 23 Aug 2020)
#
# https://github.com/harisekhon/bash-tools
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
#
# https://www.linkedin.com/in/harisekhon
#
set -euo pipefail
[ -n "${DEBUG:-}" ] && set -x
srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck disable=SC1090
. "$srcdir/lib/utils.sh"
# shellcheck disable=SC2034,SC2154
usage_description="
Calculates the total combined RAM in MB allocated to all VMs in one or more Vagrantfiles
Accepts one or more Vagrantfiles as arguments, otherwise tries to read \$PWD/Vagrantfile or /vagrant/Vagrantfile for convenience
Tested on vagrant/kubernetes/Vagrantfile in this repo
"
# used by usage() in lib/utils.sh
# shellcheck disable=SC2034
usage_args="<Vagrantfile>"
help_usage "$@"
if [ $# -gt 0 ]; then
Vagrantfiles=("$@")
elif [ -f Vagrantfile ]; then
Vagrantfiles=(Vagrantfile)
elif [ -f /vagrant/Vagrantfile ]; then
# auto-detect when running inside a Vagrant VM
Vagrantfiles=(/vagrant/Vagrantfile)
else
usage "Vagrantfile not specified and no Vagrantfile found in \$PWD or /vagrant/"
fi
grep -E '^[^#]+\.memory' "${Vagrantfiles[@]}" |
sed 's/.*=[[:space:]]*//' |
grep -E '^[[:digit:]]+(\.[[:digit:]]+)?$' |
tr '\n' '+' |
sed 's/+$//' |
bc -l

@ -25,11 +25,11 @@ set -eu
[ -n "${DEBUG:-}" ] && set -x
usage(){
echo "Installs Yum RPM packages"
echo "Installs Yum RPM package lists"
echo
echo "Takes a list of yum packages as arguments or .txt files containing lists of modules (one per line)"
echo "Takes a list of yum packages as arguments or via stdin, and for any arguments that are plaintext files, reads the packages from those given files (one package per line)"
echo
echo "usage: ${0##*} <list_of_packages>"
echo "usage: ${0##/*} <list_of_packages>"
echo
exit 3
}
@ -45,7 +45,7 @@ packages=""
process_args(){
for arg; do
if [ -f "$arg" ]; then
if [ -f "$arg" ] && file "$arg" | grep -q ASCII; then
echo "adding packages from file: $arg"
packages="$packages $(sed 's/#.*//;/^[[:space:]]*$$/d' "$arg")"
echo

@ -0,0 +1,45 @@
#!/usr/bin/env bash
# shellcheck disable=SC2230
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2020-08-23 18:32:06 +0100 (Sun, 23 Aug 2020)
#
# https://github.com/harisekhon/bash-tools
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
#
# https://www.linkedin.com/in/harisekhon
#
set -eu
[ -n "${DEBUG:-}" ] && set -x
srcdir="$(dirname "${BASH_SOURCE[0]}")"
# shellcheck disable=SC1090
. "$srcdir/lib/utils.sh"
# shellcheck disable=SC1090
. "$srcdir/lib/packages.sh"
# shellcheck disable=SC2034,SC2154
usage_description="
Installs Yum RPM package lists if the packages aren't already installed
$package_args_description
Tested on CentOS
"
# used by usage() in lib/utils.sh
# shellcheck disable=SC2034
usage_args="<packages>"
help_usage "$@"
process_package_args "$@" |
"$srcdir/rpms_filter_not_installed.sh" |
rpms_filter_not_provided |
xargs --no-run-if-empty "$srcdir/yum_install_packages.sh"
Loading…
Cancel
Save