-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
install.sh
executable file
·44 lines (39 loc) · 1.45 KB
/
install.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
#!/usr/bin/env bash
set -eu
install_git_if_needed() {
SUDO_IF_NEEDED=''
if [[ $EUID > 0 ]]; then
SUDO_IF_NEEDED=sudo
fi
if ! hash git 2>/dev/null; then
${SUDO_IF_NEEDED} apt-get install --yes git
fi
}
HOLDING_LOCATION="${HOME}/.homesick/repos/dotfiles"
if [[ ! -d ${HOLDING_LOCATION} ]]; then
install_git_if_needed
git clone --recursive https://github.com/ylogx/dotfiles.git ${HOLDING_LOCATION}
fi
cd ${HOLDING_LOCATION}
if [[ -d ${HOLDING_LOCATION}/.git ]]; then
# if [[ ! -f ~/.dev_aliases ]]; then # TODO: Use better proxy to figure out if installation has finished.
if [[ ! `git status --porcelain --untracked-files=no` ]]; then # No local git changes, can pull safely
if [[ "$(git branch --show-current --quiet)" == "master" ]]; then
echo "Switching from master to main branch"
if [[ ! $(git show-ref --verify --quiet "refs/heads/main") ]]; then
echo "Fetching latest main branch"
git fetch --all
git checkout main
git remote set-head origin main
fi
echo "Pulling latest changes for main branch from dotfiles repo."
git pull --set-upstream origin main
fi
if $(git show-ref --verify --quiet "refs/heads/main"); then
install_git_if_needed
echo "Pulling latest changes from dotfiles repo."
git pull origin main
fi
fi
fi
./run_ansible.sh