-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.sh
executable file
·86 lines (75 loc) · 2.6 KB
/
bootstrap.sh
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
#!/bin/bash
set -e
set -u
# Fail fast with a concise message when not using bash
# Single brackets are needed here for POSIX compatibility
# shellcheck disable=SC2292
if [ -z "${BASH_VERSION:-}" ]
then
echo "Bash is required to interpret this script."
exit 1
fi
declare DOTFILES_DIR
if [[ "$0" == "/bin/bash" || "$0" == "bash" ]]; then
DOTFILES_DIR="$HOME/.dotfiles"
else
DOTFILES_DIR="$(dirname "$(realpath "$0")")"
fi
# Define variables
#DOTFILES_DIR="${DOTFILES_DIR:-"$HOME/.dotfiles"}"
GITHUB_USER=${GITHUB_USER:-usma0118}
declare -r DOTFILES_REPO="https://github.com/${GITHUB_USER}/dotfiles.git"
# Ensure required environment variables are set
declare -r env_variables=("GITHUB_USER" "DOTFILES_REPO" "DOTFILES_DIR")
for env_var in "${env_variables[@]}"; do
if [ -z "${!env_var}" ]; then
abort "Error: $env_var is not set"
fi
done
# shellcheck disable=SC1091
source "$DOTFILES_DIR/lib/log.sh"
# Check if dotfiles directory exists, clone repo if not
if [ ! -d "$DOTFILES_DIR" ]; then
log_warning "Cloning $DOTFILES_REPO into $DOTFILES_DIR"
git clone "$DOTFILES_REPO" "$DOTFILES_DIR" --recurse-submodules --depth=1
fi
# Install dependencies based on OS
# shellcheck disable=SC1091
source "$DOTFILES_DIR/lib/utils.sh"
# shellcheck disable=SC2154
log_info "Running on OS: $os_family"
if ! command -v ansible &>/dev/null ; then
if [ -n "$CODESPACES" ] || [ -n "$container" ]; then
abort "Make sure code space includes ansible"
elif [[ "$os_family" == 'debian' || "$os_family" == 'ubuntu' ]]; then
if ! grep -q "ansible/ansible" /etc/apt/sources.list /etc/apt/sources.list.d/*; then
sudo apt-add-repository ppa:ansible/ansible -y && apt update -y
fi
sudo apt-get install direnv ansible software-properties-common git -y
elif [[ "$os_family" != 'alpine' ]]; then
log_warning "Missing ansible, installing now.."
sudo apk add ansible
elif [[ "$os_family" == 'darwin' ]]; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
fi
# shellcheck disable=SC1091
source "$DOTFILES_DIR/lib/updater.sh"
# check and ensure direnv is hooked to shell
if ! command -v direnv &>/dev/null; then
eval "$(direnv export "$0")"
else
ANSIBLE_CONFIG=$(realpath ansible.cfg)
export ANSIBLE_CONFIG
fi
# shellcheck source=/dev/null
pushd "$DOTFILES_DIR/playbooks"
log_info "Running playbooks"
# shellcheck disable=SC1091
source "./install"
log_info "Rollout completed"
popd
if [[ "$os_family" == 'alpine' ]]; then
log_info "Unset gpg.ssh.program"
git config --global --unset gpg.ssh.program
fi