-
Notifications
You must be signed in to change notification settings - Fork 3
/
install-macos.sh
executable file
·172 lines (128 loc) · 4.48 KB
/
install-macos.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
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
#!/usr/bin/env bash
############################
# Install the dotfiles on macOS systems.
############################
set -o errexit
set -o nounset
fail() {
echo "${1}"
exit 1
}
createSymlinks() {
local sourceDirectory=${1}
local targetDirectory=${2}
local backupDirectory=${3}
local withDot=${4}
declare -a symlinks=("${!5}")
if [ ! -d "${sourceDirectory}" ]; then
fail "Directory ${sourceDirectory} does not exist."
fi
if [ ! -d "${targetDirectory}" ]; then
fail "Directory ${targetDirectory} does not exist."
fi
for symlink in "${symlinks[@]}"; do
if [ "${withDot}" -eq "1" ]; then
local fullLinkTarget="${targetDirectory}/.${symlink}"
else
local fullLinkTarget="${targetDirectory}/${symlink}"
fi
# continue if already a symlink
if [ -h "${fullLinkTarget}" ]; then
echo "Skipping ${symlink}, symlink already exists"
continue;
fi
# move any existing files/dirs to $backupDirectory
if [ -a "${fullLinkTarget}" ]; then
echo "${backupDirectory}"
# create backupDirectory if it does not exist
if [ ! -d "${backupDirectory}" ]; then
mkdir -p "${backupDirectory}"
fi
echo "Moving existing ${symlink} to ${backupDirectory}"
mv "${fullLinkTarget}" "${backupDirectory}/${symlink}"
fi
echo "Creating symlink ${fullLinkTarget}."
ln -s "${sourceDirectory}/${symlink}" "${fullLinkTarget}"
done
# unset otherwise symlink contains last iteration value
unset symlink
}
setupHome() {
local scriptPath
scriptPath=$( cd "$( dirname "$0" )" && pwd )
# backup directory
local backupDir="${HOME}/dotfiles_backup"
# list of files/folders to symlink in homedir
local dotfiles=("bashrc" "bash_profile" "config" "zshenv" "puppet-lint.rc" "mavenrc" "gradle" "zprofile")
# setup symlinks in homedir
createSymlinks "${scriptPath}" "${HOME}" "${backupDir}" 1 dotfiles[@]
}
setupBin() {
local scriptPath
scriptPath=$( cd "$( dirname "$0" )" && pwd )
# backup directory
local backupDir="${HOME}/dotfiles_backup/bin"
# list of files/folders to symlink in homedir
local binfiles=("update-everything" "base64-encode-stdin.sh" "yarn-link")
mkdir -p "${HOME}/bin"
# setup symlinks in homedir/bin
createSymlinks "${scriptPath}/bin" "${HOME}/bin" "${backupDir}" 0 binfiles[@]
}
setupSublime() {
local scriptPath
scriptPath=$( cd "$( dirname "$0" )" && pwd )
local sublimeDir="${HOME}/Library/Application Support/Sublime Text 3/Packages"
# backup directory
local backupDir="${sublimeDir}/dotfiles_backup"
# the folders to symlink for Sublime
local sublimeFolders=("User" "User (OS Settings)")
if [ -d "${sublimeDir}" ]; then
# setup symlinks for sublime
createSymlinks "${scriptPath}/sublime" "${sublimeDir}" "${backupDir}" 0 sublimeFolders[@]
fi
}
setupAtom() {
local scriptPath
scriptPath=$( cd "$( dirname "$0" )" && pwd )
local atomDir="${HOME}/.atom"
# backup directory
local backupDir="${HOME}/dotfiles_backup"
# list of files/folders to symlink in homedir/.atom
local atomFiles=("config.cson" "init.coffee" "keymap.cson" "snippets.cson" "styles.less")
if [ -d "${atomDir}" ]; then
# setup symlinks for atom
createSymlinks "${scriptPath}/atom" "${atomDir}" "${backupDir}" 0 atomFiles[@]
fi
}
setupVSCode() {
local scriptPath
scriptPath=$( cd "$( dirname "$0" )" && pwd )
local vsCodeDir="${HOME}/Library/Application Support/Code"
# backup directory
local backupDir="${vsCodeDir}/dotfiles_backup"
# the folders to symlink for visual studio code
local vsCodeFolders=("User")
if [ -d "${vsCodeDir}" ]; then
# setup symlinks for visual studio code
createSymlinks "${scriptPath}/vscode" "${vsCodeDir}" "${backupDir}" 0 vsCodeFolders[@]
fi
}
setupSdkman() {
local scriptPath
scriptPath=$( cd "$( dirname "$0" )" && pwd )
local sdkmanDir="${HOME}/.sdkman"
# backup directory
local backupDir="${HOME}/dotfiles_backup/sdkman"
# the folders to symlink
local sdkmanFolders=("etc")
if [ -d "${sdkmanDir}" ]; then
# setup symlinks for visual studio code
createSymlinks "${scriptPath}/sdkman" "${sdkmanDir}" "${backupDir}" 0 sdkmanFolders[@]
fi
}
setupHome
setupBin
setupSublime
setupAtom
setupVSCode
setupSdkman