forked from zetavg/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
executable file
·162 lines (132 loc) · 4.97 KB
/
install
File metadata and controls
executable file
·162 lines (132 loc) · 4.97 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
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
#! /bin/bash
time_stamp=$(date +%Y%m%d_%H%M%S)
# Function to create symbolic link and made a backup if target exists
link_file() {
source="$1"
target="$2"
if [[ -e "$target" ]] && [[ ! -L "$target" ]]; then
echo "Creating backup for $target: $target.$time_stamp.bak"
mv -f "$target" "$target.$time_stamp.bak"
elif [[ -L "$target" ]]; then
rm "$target"
fi
echo "Linking $source to $target"
ln -sf "$source" "$target"
}
# Switch to the dotfiles directory
BASEDIR=$(cd "$(dirname "$0")"; pwd)
cd "$BASEDIR"
# Check if git exists
if ! git rev-parse --git-dir > /dev/null 2>&1; then
echo "Error: can't find git."
exit -1
fi
# Update git submodules
echo "Updating git submodules..."
git submodule init
git submodule update
# Create symbolic links for dotfiles
echo "Linking all dotfiles..."
for i in _*
do
source="$BASEDIR/$i"
target="$HOME/${i/_/.}"
link_file "$source" "$target"
done
# Create symbolic links for Sublime Text 2
if [[ -e "$BASEDIR/subl2" ]]; then
source="$BASEDIR/subl2"
if [[ $(uname) == "Darwin" ]]; then
test ! -e "$HOME/Library/Application Support/Sublime Text 2/Packages" && mkdir -p "$HOME/Library/Application Support/Sublime Text 2/Packages"
target="$HOME/Library/Application Support/Sublime Text 2/Packages/User"
else
test ! -e "$HOME/.config/sublime-text-2/Packages" && mkdir -p "$HOME/.config/sublime-text-2/Packages"
target="$HOME/.config/sublime-text-2/Packages/User"
fi
if [[ -e "$target" ]]; then
echo "Backing up old settings for subl2 ..."
mv -f "$target" "$target.$time_stamp.bak"
fi
echo "Restoring subl2 settings to $target"
cp -rf "$source" "$target"
fi
# Create symbolic links for Sublime Text 3
if [[ -e "$BASEDIR/subl3" ]]; then
source="$BASEDIR/subl3"
if [[ $(uname) == "Darwin" ]]; then
test ! -e "$HOME/Library/Application Support/Sublime Text 3/Packages" && mkdir -p "$HOME/Library/Application Support/Sublime Text 3/Packages"
target="$HOME/Library/Application Support/Sublime Text 3/Packages/User"
else
test ! -e "$HOME/.config/sublime-text-3/Packages" && mkdir -p "$HOME/.config/sublime-text-3/Packages"
target="$HOME/.config/sublime-text-3/Packages/User"
fi
link_file "$source" "$target"
fi
# Create symbolic links for Visual Studio Code
if [[ -e "$BASEDIR/vscode/User" ]]; then
source="$BASEDIR/vscode/User"
if [[ $(uname) == "Darwin" ]]; then
test ! -e "$HOME/Library/Application Support/Code" && mkdir -p "$HOME/Library/Application Support/Code"
target="$HOME/Library/Application Support/Code/User"
fi
link_file "$source" "$target"
fi
if [[ -e "$BASEDIR/vscode/custom" ]]; then
source="$BASEDIR/vscode/custom"
if [[ $(uname) == "Darwin" ]]; then
test ! -e "$HOME/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/electron-browser" && mkdir -p "$HOME/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/electron-browser"
target="$HOME/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/electron-browser/custom"
fi
link_file "$source" "$target"
fi
# Deal with secret files
if [[ -e "$BASEDIR/secret" ]]; then
echo "Chmod..."
chmod -R o-r "$BASEDIR/secret"
chmod -R o-w "$BASEDIR/secret"
chmod -R o-x "$BASEDIR/secret"
chmod -R g-r "$BASEDIR/secret"
chmod -R g-w "$BASEDIR/secret"
chmod -R g-x "$BASEDIR/secret"
echo "Copying private profiles..."
if [[ -e "$BASEDIR/secret/subl2" ]]; then
source="$BASEDIR/secret/subl2"
if [[ $(uname) == "Darwin" ]]; then
test ! -e "$HOME/Library/Application Support/Sublime Text 2/Packages" && mkdir -p "$HOME/Library/Application Support/Sublime Text 2/Packages/User"
target="$HOME/Library/Application Support/Sublime Text 2/Packages/User"
else
test ! -e "$HOME/.config/sublime-text-2/Packages" && mkdir -p "$HOME/.config/sublime-text-2/Packages/User"
target="$HOME/.config/sublime-text-2/Packages/User"
fi
cp -f "$source"/* "$target"/
fi
if [[ -e "$BASEDIR/secret/subl3" ]]; then
source="$BASEDIR/secret/subl3"
if [[ $(uname) == "Darwin" ]]; then
test ! -e "$HOME/Library/Application Support/Sublime Text 3/Packages" && mkdir -p "$HOME/Library/Application Support/Sublime Text 3/Packages/User"
target="$HOME/Library/Application Support/Sublime Text 3/Packages/User"
else
test ! -e "$HOME/.config/sublime-text-3/Packages" && mkdir -p "$HOME/.config/sublime-text-3/Packages/User"
target="$HOME/.config/sublime-text-3/Packages/User"
fi
cp -f "$source"/* "$target"/
fi
if [[ -e "$BASEDIR/secret/gitcfg" ]]; then
source="$BASEDIR/secret/gitcfg"
test ! -e "$HOME/.config" && mkdir -p "$HOME/.config"
target="$HOME/.config/gitcfg"
if [[ -e "$target" ]]; then
mv -f "$target" "$target.$time_stamp.bak"
fi
cp -rf "$source" "$target"
fi
echo "Linking secret dotfiles..."
for i in secret/_*
do
source="$BASEDIR/$i"
target="$HOME/${i/secret\/_/.}"
link_file "$source" "$target"
done
fi
# Done
echo "Done."