-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·137 lines (115 loc) · 2.89 KB
/
install.sh
File metadata and controls
executable file
·137 lines (115 loc) · 2.89 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
130
131
132
133
134
135
136
137
#!/bin/bash
#
# Symlinks dotfiles to $HOME.
# Prints usage
usage() {
cat << EOF
usage: $0 [-s|--submodules] [-h|--help]
OPTIONS:
-s | --submodules Initialize and update included git submodules
EOF
}
# Exits with given error message
die() {
echo "$@"
exit 1
}
# Minifies shell script files in place
minify_shell_script_file_in_place() {
# 1. Convert tabs to spaces
# 2. Remove blank lines
# 3. Remove beginning spaces
# 4. Remove whole line comments
# 5. Remove trailing spaces
# Set LANG as C to treat all ASCII characters as themselves and all
# non-ASCII characters as literals
env LANG=C sed 's/ / /g' "$@" |
env LANG=C sed '/^$/d' |
env LANG=C sed 's/^[ ]*//' |
env LANG=C sed '/^[ ]*#/d' |
env LANG=C sed 's/[ ]*$//' > tmp
# Copy tmp to the given file and remove tmp
cp tmp "$@"
rm tmp
}
here=$(dirname "$0") && here=$(cd "$here" && pwd -P)
while :
do
case "$1" in
-h | --help )
usage
exit 0
;;
-s | --submodules )
cd "$here"
echo "Initializing git submodules"
(git submodule init && git submodule update) \
|| die "Could not update git submodules"
shift
;;
-- )
shift
break
;;
-* )
echo "Unknown option: $1"
usage
exit 1
;;
* )
break
;;
esac
done
echo
echo "Linking files to \$HOME"
# Link all but the specified files to $HOME
for file in "${here}"/*; do
filename="$(basename "$file")"
target="${HOME}/.${filename}"
if [ "$filename" != ".gitignore" ] &&
[ "$filename" != "bash_profile" ] &&
[ "$filename" != "bin" ] &&
[ "$filename" != "build" ] &&
[ "$filename" != "install.sh" ] &&
[ "$filename" != "lesskey" ] &&
[ "$filename" != "shrc" ]; then
ln -sfv "$file" "$target"
else
echo "Ignoring ${filename}"
fi
done
echo
echo "Compiling and minifying bash_profile"
# Compile shrc/* into build/bash_profile
if [ ! -d "${here}/build" ]; then
mkdir "${here}/build"
fi
touch "${here}/build/bash_profile"
cat /dev/null > "${here}/build/bash_profile"
for file in "$here"/shrc/*; do
filename="$(basename "$file")"
if [ "$filename" != "minimal.sh" ]; then
if [ "$filename" = "osx.sh" ] && [ "$(uname -s)" = "Darwin" ]; then
cat "$file" >> "${here}/build/bash_profile"
elif [ "$filename" != "osx.sh" ]; then
cat "$file" >> "${here}/build/bash_profile"
fi
fi
done
# Minify compiled bash_profile
minify_shell_script_file_in_place "${here}/build/bash_profile"
# Link compiled bash_profile to $HOME
ln -sfv "${here}/build/bash_profile" "${HOME}/.bash_profile"
echo
echo "Linking files in bin"
# Create $HOME/bin if it doesn't already exist
if [ ! -d "${HOME}/bin" ]; then
mkdir -v "${HOME}/bin"
fi
# Link files in bin to $HOME/bin
for file in "${here}/bin"/*; do
filename="$(basename "$file")"
ln -sfv "${here}/bin/${filename}" "${HOME}/bin/${filename}"
done
exec /bin/bash -l