-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall
executable file
·209 lines (178 loc) · 6.71 KB
/
install
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/bin/bash
# Install script to set up a general unix / linux capable computer as a
# development machine
#
# We don't use set -eu -o pipfail here because the program abuses lenient
# evaluation. Also failing here, is not so good because this is a script that
# intends to install stuff, and installing as much as possible is better than
# failing most likely.
function usage_info () {
echo "Usage: $0 [options]"
echo "Install dotfiles and do any other necessary configuration"
echo ""
echo " --update update the configuration that is currently installed"
echo " --minimal install a minimal set of files that can be completely"
echo " uninstalled using the --uninstall option"
echo " --all install everything, intended for new systems or for where"
echo " the defaults do not install everything necessary"
echo " --force overwrite existing configuration when installing files"
echo " --uninstall symlink configuration to its proper location"
echo " --help show this help and then quit"
echo " --verbose show verbose level output"
}
# print data if verbose >= level
function log () {
[ "$verbose" -ge "$1" ] && shift && echo "$@"
}
# Set Operating System Variables
if [ "$(uname)" == "Darwin" ]; then
export DARWIN=1
elif [ "$(uname)" == "Linux" ]; then
export LINUX=1
fi
# represents the number of features to install
# 0 := none, 1 := minimal, 2 := default, 3 := all, "uninstall" := uninstall
features=2
# the verbosity of the program
# 0 := info/default, 1 := debug, 2 := verbose, 3 := trace (set -x)
verbose=0
for arg; do
case "$arg" in
--update)
update=1;;
--minimal)
features=1;;
--all)
features=3;;
--force)
force=1;;
--uninstall)
features=uninstall;;
--verbose|-v)
verbose=$((verbose + 1));;
-vv)
verbose=$((verbose + 2));;
-vvv)
verbose=$((verbose + 3));;
-vvvv)
verbose=$((verbose + 4));;
--help)
usage_info
exit 0;;
*)
echo "invalid option"
usage_info
exit 1;;
esac
done
[ "$verbose" -ge 3 ] && set -x
if [ "$features" == "uninstall" ]; then
# uninstall the dotfiles
echo "uninstalling is currently unimplemented"
exit 0
fi
log 0 "Installing dotfiles..."
# Get the location of the dotfiles
pushd "$(dirname "$0")" > /dev/null || exit 0
DOTFILES="$(pwd -P)"
popd > /dev/null || exit 0
# Create a file at ~/.dotfiles if no file is present there and not installed there
if [ "$DOTFILES" != "$HOME/.dotfiles" ]; then
# test if a file or symlink is present at ~/.dotfiles
if [ -e "$HOME/.dotfiles" ] || [ -h "$HOME/.dotfiles" ]; then
# exit the program as this cannot be sucessfully installed then
log 0 "A file or directory is present at $HOME/.dotfiles... Aborting."
exit 1
fi
# put the location of dotfiles at ~/.dotfiles in a file
echo "$DOTFILES" > "$HOME/.dotfiles"
fi
# Set XDG_CONFIG_HOME if unset
[ -n "$XDG_CONFIG_HOME" ] || export XDG_CONFIG_HOME="$HOME/.config"
# links files on $path with $suffix mapping them using $mapper where $suffix is
# implicitly removed with a maximum depth of $depth
function linkfiles () {
local path="$1"
local suffix="$2"
local depth="$3"
local mapper="$4"
log 1 "linking files with: "
log 1 " path=$path"
log 1 " suffix=$suffix"
log 1 " depth=$depth"
log 1 " mapper=$mapper"
tolink=$(find -H "$DOTFILES$path" -mindepth 1\
-maxdepth "$depth" -name "*$suffix")
for file in $tolink; do
local target
target="$("$mapper" "$(basename "$file" "$suffix")")"
log 1 " Processing file=$file"
log 1 " target=$target"
log 1 " force=$force update=$update"
if [ ! -e "$target" ]; then
ln -f -s "$file" "$target"
log 0 "Created symlink for $file"
elif [ -n "$force" ] || { [ -n "$update" ] && [ -h "$target" ]; }; then
rm -rf "$target"
ln -f -s "$file" "$target"
log 0 "Overwrote symlink for $file"
else
log 0 "$target exists... Skipping."
fi
done
}
if [ "$features" -ge 1 ]; then
log 1 ""
log 0 "Creating symlinks..."
function symdot_mapper { echo "$HOME/.$1"; }
# Symlink files to be symlinked to every platform
linkfiles "" ".symdot" 5 "symdot_mapper"
# Symlink OS X specific files
[ -n "$DARWIN" ] && linkfiles "" ".symdot.osx" 5 "symdot_mapper"
# Make sure XDG_CONFIG_HOME exists
mkdir -p "$HOME/.config"
function config_mapper { echo "$HOME/.config/$1"; }
# symlink files that should go in xdg_config_home
linkfiles "" ".symconfig" 5 "config_mapper"
# special purpose needed for .ghcup/config.yml file
function ghcup_mapper { echo "$HOME/.ghcup/$1"; }
linkfiles "" ".symghcup" 5 "ghcup_mapper"
# xcode configuration files are stored under this directory
xcode_userdata_path="$HOME/Library/Developer/Xcode/UserData"
function xcode_userdata_mapper { echo "$xcode_userdata_path/$1"; }
[ -n "$DARWIN" ] && linkfiles "" ".sym-xcodeuserdata" 5 "xcode_userdata_mapper"
fi
# Setup fzf
if [ "$features" -ge 2 ] && [ ! -d "$HOME/.fzf" ]; then
log 1 ""
log 0 "Installing fzf..."
git clone https://github.com/junegunn/fzf.git --depth 1 "$HOME/.fzf" >/dev/null &&\
"$HOME/.fzf/install" --bin || echo "Failed to install fzf!"
fi
if [ -n "$DARWIN" ] && [ "$features" -ge 2 ]; then
log 1 ""
log 0 "Setting up macOS system keybindings"
source "$DOTFILES/install_keybindings.macos.sh"
log 2 "Finished setting up macOS system keybindings"
fi
if [ -n "$DARWIN" ] && [ "$features" -ge 3 ]; then
# Install homebrew and brew everything in Brewfile
log 1 ""
log 0 "Installing xcode commandline tools..."
xcode-select --install >/dev/null 2>&1 || true
# Install homebrew if nescessary
brew help >/dev/null 2>&1 || \
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# make homebrew available now
[ -x "/opt/homebrew/bin/brew" ] && eval "$(/opt/homebrew/bin/brew shellenv)"
[ -x "/usr/local/bin/brew" ] && eval "$(/opt/homebrew/bin/brew shellenv)"
log 1 ""
log 0 "Brewing formulas..."
# Use brew-bundle to install homebrew formulas in a good order
brew bundle --file="$DOTFILES/Brewfile"
# allow unsigned qlgenerators to be used
# workaround documented/taken from here: https://github.com/whomwah/qlstephen#readme
xattr -cr ~/Library/QuickLook/*.qlgenerator
qlmanage -r
qlmanage -r cache
fi