-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinstall
103 lines (81 loc) · 2.95 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
#!/usr/bin/env sh
set -o errexit
ANSIBLE_REPO_PATH="${HOME}/ansible.$(date +%H%M%S)"
ANSIBLE_REPO_BRANCH="main"
ANSIBLE_REPO_URL="https://github.com/bradleyfrank/ansible.git"
ANSIBLE_REPO_HOSTVARS="${HOME}/.ansible/inventory/host_vars/localhost.yml"
ANSIBLE_REPO_INVENTORY="$(mktemp)"
HOMEBREW_INSTALL_ON_LINUX=1; export HOMEBREW_INSTALL_ON_LINUX
HOMEBREW_INSTALL_SCRIPT="https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh"
install_homebrew() {
case "$ID" in
fedora) sudo dnf install -y procps-ng file @development-tools ;;
debian|ubuntu|linuxmint|pop) sudo apt-get install -y build-essential procps file ;;
macos) sudo softwareupdate --install-rosetta ;;
esac
NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL $HOMEBREW_INSTALL_SCRIPT)"
}
bootstrap_mac() {
pgrep caffeinate >/dev/null || (caffeinate -d -i -m -u &)
export PATH="/opt/homebrew/bin:/usr/local/bin:${PATH}"
ID=macos install_homebrew
brew install python3 git
}
bootstrap_linux() {
sudo systemctl stop packagekit
# shellcheck disable=SC1091
. /etc/os-release
case "$ID" in
fedora)
sudo dnf clean all
sudo dnf makecache
sudo dnf install -y python3 python3-devel python3-pip python3-wheel gcc git redhat-lsb-core
;;
debian|ubuntu|linuxmint|pop)
sudo apt-get clean
sudo apt-get update
sudo apt-get install -y python3 python3-pip python3-venv git lsb-release
;;
*) exit 1 ;;
esac
[ -n "$HOMEBREW_INSTALL_ON_LINUX" ] && install_homebrew
}
while getopts ':hbg:' opt; do
case "$opt" in
h) echo "[-h] | [-b] [-g <branch>]" ;;
b) unset HOMEBREW_INSTALL_ON_LINUX ;;
g) ANSIBLE_REPO_BRANCH="$OPTARG" ;;
*) exit 1 ;;
esac
done
case $(uname -m) in (aarch*|arm*)
unset HOMEBREW_INSTALL_ON_LINUX ;;
esac
case $(uname -s) in
Darwin) bootstrap_mac ;;
Linux) bootstrap_linux ;;
*) exit 1 ;;
esac
git clone "$ANSIBLE_REPO_URL" "$ANSIBLE_REPO_PATH"
cd "$ANSIBLE_REPO_PATH" >/dev/null
git checkout "$ANSIBLE_REPO_BRANCH"
PATH="$(python3 -m site --user-base)/bin:${PATH}"; export PATH
python3 -m venv venv
#shellcheck disable=SC1091
. venv/bin/activate
pip install --no-cache-dir --requirement requirements.txt
echo "localhost ansible_connection=local" > "$ANSIBLE_REPO_INVENTORY"
ansible-playbook playbooks/install_requirements.yml --inventory "$ANSIBLE_REPO_INVENTORY"
ansible-playbook playbooks/build_inventory.yml --inventory "$ANSIBLE_REPO_INVENTORY"
grep "^(#|-|$)" roles/*/defaults/main.yml \
--invert-match \
--no-filename \
--extended-regexp \
--color=never \
| sed "s/^/# /g" >> "$ANSIBLE_REPO_HOSTVARS"
vim -c "e ${ANSIBLE_REPO_HOSTVARS}|redraw|echom 'Save and quit to continue running the install script.'"
export ANSIBLE_VAULT_PASSWORD_FILE="${HOME}/.ansible/vault"
ansible-playbook playbooks/site.yml --ask-become-pass --tags "all,never"
ansible-playbook playbooks/password_manager.yml
printf "\nVault passphrase: %s\n" "$(cat "$ANSIBLE_VAULT_PASSWORD_FILE")"
rm -f "$ANSIBLE_VAULT_PASSWORD_FILE"