-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·117 lines (102 loc) · 3.05 KB
/
install
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
#!/bin/bash
# 1. Sets up a local Python environment via virtualenv
# 2. Installs Ansible prerequisites
# 3. Hands off to Ansible to complete actual installation of dotfiles etc
set -e
ANSIBLE_ENV_SETUP=vendor/ansible/hacking/env-setup
VIRTUALENV_SETUP=vendor/virtualenv/virtualenv.py
VIRTUALENV_TARGET_DIR=python
VIRTUALENV_ACTIVATE=$VIRTUALENV_TARGET_DIR/bin/activate
usage() {
echo "./install [options] [roles...]"
echo "Supported options:"
echo " -f/--force"
echo " -h/--help"
echo " -v/--verbose (repeat for more verbosity)"
echo "Other options (passed through to Ansible):"
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
if [ ! -e $VIRTUALENV_SETUP ]; then
echo "Not found: $VIRTUALENV_SETUP"
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
if [[ ! -e $VIRTUALENV_ACTIVATE || $FORCE ]]; then
python $VIRTUALENV_SETUP $VIRTUALENV_TARGET_DIR &> $DEV_NULL
elif [ -e $VIRTUALENV_ACTIVATE ]; then
echo "Skipping virtualenv install (already exists); use --force to override"
fi
source $VIRTUALENV_ACTIVATE
# Troubleshooting during OS upgrades, or new machine installs: may need:
#
# sudo -H pip install --upgrade cryptography
# pip install --upgrade pip
#
if [[ -z $(pip show paramiko PyYAML Jinja2 httplib2) || $FORCE ]]; then
if ! pip install paramiko pycrypto PyYAML Jinja2 httplib2 &> $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
source vendor/ansible/hacking/env-setup &> $DEV_NULL
HOST_OS=$(uname)
if [ "$HOST_OS" = 'Darwin' ]; then
ansible-playbook --ask-become-pass -i inventory ${VERBOSE+-v} ${ROLES} "${EXTRA_ARGS[@]}" darwin.yml
elif [ "$HOST_OS" = 'Linux' ]; then
ansible-playbook -i inventory ${VERBOSE+-v} ${ROLES} "${EXTRA_ARGS[@]}" linux.yml
else
echo "Unknown host OS: $HOST_OS"
exit 1
fi
trap - EXIT