-
Notifications
You must be signed in to change notification settings - Fork 0
/
run
executable file
·180 lines (159 loc) · 4.61 KB
/
run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/bin/bash
# 1. Installs Xcode, if it is missing
# 2. Sets up a local Python environment via pyenv
# 3. Installs the Ansible prerequisites
# 4. Hands off to Ansible to ensure the local system matches the desired state
# Store the current PATH and PYENV_ROOT and then reset to default values
SYSTEM_PATH=$PATH
unset PATH
PATH="/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
export PATH
# Store the curent PYENV_ROOT/PYENV_VERSION and reset to the submodule version
SYSTEM_PYENV_ROOT=$PYENV_ROOT
SYSTEM_PYENV_VERSION=$PYENV_VERSION
unset PYENV_ROOT
unset PYENV_VERSION
PYENV_ROOT="$(pwd)/vendor/pyenv"
export PYENV_ROOT
ANSIBLE_ENV_SETUP=vendor/ansible/hacking/env-setup
PYENV_INIT="${PYENV_ROOT}/bin/pyenv"
PATH="${PYENV_ROOT}/bin:$PATH"
PYTHON_39="${PYENV_ROOT}/versions/3.9.13"
progress(){
echo -ne "\r["
printf "%0.s=" `seq $1`
echo -n ">"
}
usage() {
echo "Usage: run [options...] [roles...]"
echo "Options:"
echo " -f, --force"
echo " -h, --help"
echo " -v, --verbose (repeat for more verbosity)"
echo "Ansible options:"
echo " --check"
echo " --step"
echo " --start-at-task='role | task'"
echo "Supported roles:"
for ROLE in $(ls roles); do
echo " $ROLE"
echo " $(cat roles/$ROLE/description)"
done
}
EXTRA_ARGS=()
while [ $# -gt 0 ]; do
if [ "$1" = '--force' -o "$1" = '-f' ]; then
FORCE=1
elif [ "$1" = '--verbose' -o "$1" = '-v' ]; then
VERBOSE=$((VERBOSE + 1))
elif [ "$1" = '--help' -o "$1" = '-h' -o "$1" = 'help' ]; then
usage
exit
elif [ -n "$1" ]; then
if [ -d "roles/$1" ]; then
if [ -z "$ROLES" ]; then
ROLES="--tags $1"
else
ROLES="$ROLES,$1"
fi
elif [[ "$1" == --* ]]; then
EXTRA_ARGS+=("$1")
else
echo "Unrecognized argument(s): $*"
usage
exit 1
fi
fi
shift
done
if [[ $VERBOSE ]]; then
DEV_NULL=/dev/stdout
if [ $VERBOSE -gt 1 ]; then
echo 'Enabling extremely verbose output'
set -x
fi
else
trap 'echo "Exiting: run with -v/--verbose for more info"' EXIT
DEV_NULL=/dev/null
fi
# Install Xcode, if it is missing
check=$((xcode-select --install) 2>&1)
str="xcode-select: note: install requested for command line developer tools"
if [[ "$check" == "$str" ]]; then
echo "Installing Xcode..."
i=0
while [[ "$check" == "$str" ]];
do
check=$((xcode-select --install) 2>&1)
i=$((i+1))
progress $i
sleep 1
done
fi
if [ ! -e $PYENV_INIT ]; then
echo "Not found: $PYENV_INIT"
echo "Did you forget to 'git submodule update --init --recursive'?"
exit 1
fi
#if [ ! -e $ANSIBLE_ENV_SETUP ]; then
# echo "Not found: $ANSIBLE_ENV_SETUP"
# echo "Did you forget to 'git submodule update --init --recursive'?"
# exit 1
#fi
# Install pyenv 3.9.13 version, if missing or forced
eval "$(pyenv init -)"
if [ ! -e "$PYTHON_39" ]; then
echo "Installing Python 3.9.13..."
pyenv install 3.9.13 &> $DEV_NULL
elif [ -e "$PYTHON_39" ] && [ "$FORCE" ]; then
echo "Forcing reinstall of Python 3.9.13..."
pyenv install -f 3.9.13 &> $DEV_NULL
elif [ -e "$PYTHON_39" ]; then
echo "Skipping Python 3.9.13 pyenv install (already exists); use --force to override"
fi
# Activate pyenv 3.9.13 environment
pyenv global 3.9.13
# Troubleshooting during OS upgrades, or new machine installs: may need:
#
# sudo -H pip install --upgrade cryptography
# pip install --upgrade pip
#
if [[ -z $(pip show jinja2 PyYAML cryptography packaging resolvelib) || $FORCE ]]; then
if ! pip install -r vendor/ansible/requirements.txt &> $DEV_NULL; then
echo "Failed: pip install"
echo "Did you forget to 'export https_proxy=fwdproxy:8080' or similar?"
exit 1
fi
elif [[ ! $FORCE ]]; then
echo "Skipping pip installs (already exists); use --force to override"
fi
# Activate Ansible
source vendor/ansible/hacking/env-setup &> $DEV_NULL
if [[ $VERBOSE ]]; then
# Print Python, pip, and Ansible versions
python --version
pip --version
ansible --version
fi
HOST_OS=$(uname)
if [ "$HOST_OS" = 'Darwin' ]; then
ansible-galaxy collection install community.general
ansible-playbook --ask-become-pass --ask-vault-pass -i inventory ${VERBOSE+-v} ${ROLES} "${EXTRA_ARGS[@]}" macos.yml
elif [ "$HOST_OS" = 'Linux' ]; then
# ansible-playbook -i inventory ${VERBOSE+-v} ${ROLES} "${EXTRA_ARGS[@]}" linux.yml
echo "Ansible playbook for Linux not yet available"
else
echo "Unknown host OS: $HOST_OS"
exit 1
fi
# Restore the previous PATH value
unset PATH
PATH=$SYSTEM_PATH
export PATH
# Restore the previous PYENV_ROOT/PYENV_VERSION value
unset PYENV_ROOT
PYENV_ROOT=$SYSTEM_PYENV_ROOT
PYENV_VERSION=$SYSTEM_PYENV_VERSION
export PYENV_ROOT
export PYENV_VERSION
trap - EXIT