-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·129 lines (109 loc) · 3.36 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·129 lines (109 loc) · 3.36 KB
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
#!/bin/bash
set -euo pipefail
readonly SCRIPT_NAME="$(basename "$0")"
readonly OS_TYPE="$(uname -s)"
# Parse command line arguments
SKIP_GALAXY=false
for arg in "$@"; do
case "$arg" in
--skip-galaxy)
SKIP_GALAXY=true
shift
;;
esac
done
log() {
echo "[${SCRIPT_NAME}] $*" >&2
}
error() {
log "ERROR: $*"
exit 1
}
check_dependencies() {
log "Checking dependencies..."
if ! command -v git >/dev/null 2>&1; then
error "git is required but not installed"
fi
case "$OS_TYPE" in
Darwin)
if ! command -v brew >/dev/null 2>&1; then
error "Homebrew is required on macOS. Install from https://brew.sh"
fi
;;
Linux)
if ! command -v apt >/dev/null 2>&1; then
error "apt package manager is required on Linux"
fi
;;
*)
error "Unsupported operating system: $OS_TYPE"
;;
esac
}
install_ansible() {
if command -v ansible >/dev/null 2>&1; then
log "Ansible is already installed"
return 0
fi
log "Installing Ansible..."
case "$OS_TYPE" in
Darwin)
log "Updating Homebrew..."
brew update
log "Installing Ansible via Homebrew..."
brew install ansible
;;
Linux)
log "Updating package lists..."
sudo apt update
# ansible-core, not the `ansible` metapackage. The metapackage is the
# full community bundle (~35k files to extract); ansible-core is a few
# MB, and the one collection this playbook needs (community.general)
# is installed separately below.
log "Installing ansible-core via apt..."
sudo apt install -y ansible-core
;;
esac
log "Ansible installation completed"
}
setup_submodules() {
log "Initializing git submodules..."
git submodule update --init --recursive
}
install_ansible_collections() {
if [ "$SKIP_GALAXY" = true ]; then
log "Skipping Ansible galaxy collections installation (--skip-galaxy flag used)"
return 0
fi
# No --force. It re-downloads and re-extracts the collection on every run
# even when it is already present, which is pure cost on a repeat install.
# `collection list` exits 0 whether or not the collection is present, so
# match on the output rather than the exit code.
if ansible-galaxy collection list community.general 2>/dev/null | grep -q '^community\.general '; then
log "community.general collection already installed"
return 0
fi
log "Installing required Ansible collections..."
ansible-galaxy collection install community.general
}
run_playbook() {
# Filter out --skip-galaxy from arguments passed to ansible-playbook
local playbook_args=()
for arg in "$@"; do
if [ "$arg" != "--skip-galaxy" ]; then
playbook_args+=("$arg")
fi
done
log "Running Ansible playbook..."
ansible-playbook --ask-become-pass main.yml "${playbook_args[@]}"
}
main() {
log "Starting dotfiles installation..."
check_dependencies
install_ansible
setup_submodules
install_ansible_collections
run_playbook "$@"
log "Installation completed successfully!"
}
main "$@"