forked from amarshall/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstall.sh
executable file
·87 lines (75 loc) · 2.37 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
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
#!/bin/bash
COLOR_NONE='\033[0m'
COLOR_RED='\033[0;31m'
COLOR_GREEN='\033[0;32m'
COLOR_YELLOW='\033[0;33m'
CURRENT_DIR="$(cd "$(dirname "$0")" && pwd)"
EXCLUDE=(install.sh LICENSE README.markdown)
NO_DOT=(bin)
linkfile() {
symbolic=$1;
original=$2;
if [ -e "$symbolic" ]; then
if [[ $(readlink "$symbolic") != "$original" ]]; then
printf $COLOR_YELLOW
printf "\"%s\" already exists, skipping.\n" $symbolic
else
printf $COLOR_NONE
printf "\"%s\" is already linked.\n" $symbolic
fi
else
if ln -s "$original" "$symbolic"; then
printf $COLOR_GREEN
printf "\".%s\" linked.\n" $symbolic
else
printf $COLOR_RED
printf "\".%s\" linking failed.\n" $symbolic
fi
fi
}
if [[ ! -e ~/.sh_pre ]]; then
echo "export SH_USERNAME=\"$(whoami)\"" > ~/.sh_pre
fi
printf "Initializing and updating git submodules..."
if (cd "$CURRENT_DIR" && git submodule sync && git submodule update --init --recursive); then
printf "\r$COLOR_GREEN"
printf "Submodules successfully initialized & updated.\n"
else
printf "\r$COLOR_YELLOW"
printf "Submodules could not be initialized/updated.\n"
fi
for filename in $(ls "$CURRENT_DIR"); do
[[ ${EXCLUDE[@]} =~ $filename ]] && continue
original="$CURRENT_DIR/$filename"
if [[ ${NO_DOT[@]} =~ $filename ]]; then
symbolic="$HOME/$filename"
else
symbolic="$HOME/.$filename"
fi
linkfile $symbolic $original
done
for filename in $(ls "$HOME/.localrcs"); do
original="$HOME/.localrcs/$filename"
symbolic="$HOME/.$(printf $filename | cut -d'.' -f 2)"
current_host="$(printf $(hostname) | cut -d'.' -f 1 | awk '{print tolower($0)}')"
target_host="$(printf $filename | cut -d'.' -f 1 | awk '{print tolower($0)}')"
if [[ $target_host == $current_host ]]; then
linkfile $symbolic $original
fi
done
if grep Darwin <(uname) &> /dev/null; then
if ! which brew &> /dev/null ; then
printf "\r$COLOR_YELLOW"
printf 'Homebrew is not installed or is not in the $PATH'
printf "\n"
elif ! grep "$(brew --prefix)/bin" <(echo $PATH) &> /dev/null; then
printf "\r$COLOR_YELLOW"
printf 'Homebrew prefix is not in $PATH'
printf "\n"
elif egrep "(\A|:)(/usr/bin|/bin):(.*:)?$(brew --prefix)/bin" <(echo $PATH) &> /dev/null; then
printf "\r$COLOR_YELLOW"
printf 'Homebrew prefix is not before /usr/bin or /bin in $PATH'
printf "\n"
fi
fi
printf $COLOR_NONE