You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.9 KiB
Bash
74 lines
1.9 KiB
Bash
4 years ago
|
#!/usr/bin/env bash
|
||
|
# shellcheck disable=SC2230
|
||
|
# vim:ts=4:sts=4:sw=4:et
|
||
|
#
|
||
|
# Author: Hari Sekhon
|
||
|
# Date: 2020-08-15 11:52:44 +0100 (Sat, 15 Aug 2020)
|
||
|
#
|
||
2 years ago
|
# https://github.com/HariSekhon/DevOps-Bash-tools
|
||
4 years ago
|
#
|
||
|
# 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
|
||
|
#
|
||
2 years ago
|
# https://www.linkedin.com/in/HariSekhon
|
||
4 years ago
|
#
|
||
|
|
||
|
set -euo pipefail
|
||
|
[ -n "${DEBUG:-}" ] && set -x
|
||
3 years ago
|
srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||
4 years ago
|
|
||
|
# shellcheck source=lib/utils.sh
|
||
|
. "$srcdir/lib/utils.sh"
|
||
|
|
||
|
vagrantfiles="$(find "${1:-.}" -maxdepth 3 -name Vagrantfile)"
|
||
|
|
||
|
if [ -z "$vagrantfiles" ]; then
|
||
|
return 0 &>/dev/null || :
|
||
|
exit 0
|
||
|
fi
|
||
|
|
||
|
section "V a g r a n t"
|
||
|
|
||
|
start_time="$(start_timer)"
|
||
|
|
||
4 years ago
|
# catches $VAGRANT_HOME/Vagrantfile instead of validating the one we are targeting
|
||
|
unset VAGRANT_HOME
|
||
|
|
||
4 years ago
|
if type -P vagrant &>/dev/null; then
|
||
3 years ago
|
type -P vagrant
|
||
|
vagrant --version
|
||
|
echo
|
||
4 years ago
|
echo "Validating Vagrantfiles:"
|
||
|
echo
|
||
|
while read -r vagrantfile; do
|
||
|
pushd "$(dirname "$vagrantfile")" >/dev/null
|
||
4 years ago
|
|
||
|
# create host directories to avoid this Vagrantfile validation error in GitHub Actions "CI Mac" builds:
|
||
|
#
|
||
|
# vm:
|
||
|
# * The host path of the shared folder is missing: ~/github
|
||
|
#
|
||
4 years ago
|
awk '/^[[:space:]]*config.vm.synced_folder/{print$2}' Vagrantfile |
|
||
4 years ago
|
sed 's/,$//; s/"//g' |
|
||
|
sed "s/'//" |
|
||
|
while read -r directory; do
|
||
4 years ago
|
# Mac is silent even with -v and
|
||
|
# creates literal ~/ subdirectory path unless eval'd, leaving validation to fail with the real path missing
|
||
|
eval mkdir -p -v "$directory"
|
||
4 years ago
|
done
|
||
|
|
||
4 years ago
|
echo -n "$vagrantfile => "
|
||
|
vagrant validate
|
||
|
popd >/dev/null
|
||
|
done <<< "$vagrantfiles"
|
||
|
else
|
||
|
echo "WARNING: 'vagrant' is not installed, skipping..."
|
||
|
echo
|
||
|
exit 0
|
||
|
fi
|
||
|
|
||
|
time_taken "$start_time"
|
||
|
section2 "Vagrantfile validation SUCCEEDED"
|
||
|
echo
|