forked from natecavanaugh/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·119 lines (99 loc) · 2.47 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
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
REPLACE_ALL=0
KEEP_BACKUPS=0
QUIET=0
AUTO_RELOAD=1
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
function usage {
cat << EOF
usage: $0 options
This script will install these dotfiles into your \$HOME directory
OPTIONS:
-h Show this message
-b Backup file in the home before linking it
-m Prevent auto reloading of the bash_profile after install
-q Disable output status messages
EOF
}
while getopts "bqh?" OPTION
do
case $OPTION in
b)
KEEP_BACKUPS=1
;;
q)
QUIET=1
;;
m)
AUTO_RELOAD=0
;;
h)
usage
exit 1
;;
?)
usage
exit
;;
esac
done
function status {
[[ $QUIET != 1 ]] && echo "$1"
}
function replace_file {
if [[ $KEEP_BACKUPS != 0 ]]; then
status "Backing up $1 to $1_bak"
mv "$1" "$1_bak"
else
status "Deleting $1"
rm -rf "$1"
fi
link_file "$1" "$2"
}
function link_file {
status "Linking $2 -> $1"
ln -s "$2" "$1"
status ""
}
for f in `ls -l "$DIR" | awk 'NR!=1 {print $NF}' | grep -v -E "README\.md|install\.sh|.*_private|.*_build|misc"`; do
file="$DIR/$f"
private_file="${file}_private"
if [[ -f "$private_file" ]]; then
build_file="${file}_build"
cat "$file" > "$build_file"
echo >> "$build_file"
cat "$private_file" >> "$build_file"
file="$build_file"
fi
file_name="$HOME/.$f"
# if [[ -d "$file" ]]; then
# file_name="$HOME/$f"
# fi
if [[ -e "$file_name" || -L "$file_name" ]]; then
if [[ "$REPLACE_ALL" == 0 ]]; then
read -p "Replace '$file_name' with a link to '$file'? [(y)es, (n)o, (a)ll, (q)uit]: " replace
[[ "$replace" == "a" || "$replace" == "all" ]] && REPLACE_ALL=1
REPLACE=0
if [[ "$replace" == "q" || "$replace" == "quit" ]]; then
exit 1;
elif [[ "$replace" == "n" || "$replace" == "no" ]]; then
status "Skipping $f";
continue;
elif [[ "$REPLACE_ALL" || "$replace" == "y" || "$replace" == "yes" ]]; then
REPLACE=1
fi
else
REPLACE=1
fi
[[ "$REPLACE" ]] && replace_file "$file_name" "$file"
else
link_file "$file_name" "$file"
fi
done
if [[ "$AUTO_RELOAD" ]]; then
source "$HOME/.bash_profile"
install_details="Your dotfiles are now loaded and available."
else
install_details='Type "source ~/.bash_profile to kick things into gear (or just close and reopen this terminal window)".'
fi
status "Installation successful. $install_details"
exit 0;