-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup
executable file
·174 lines (138 loc) · 6.35 KB
/
setup
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
#!/bin/bash
detect_shell() {
if [ -n "${ZSH_VERSION}" ]; then
echo "zsh"
elif [ -n "${BASH_VERSION}" ]; then
echo "bash"
elif [ -n "${FISH_VERSION}" ]; then
echo "fish"
else
echo "<unknown>"
fi
}
SCRIPT_DIRECTORY="$(readlink -e "$(dirname "${BASH_SOURCE[0]}")")"
perform_uninstall() {
if [[ -d "$HOME/.old_scripts" ]]; then
echo "Starting uninstall"
if [[ $(detect_shell) = "zsh" ]]; then
rm "$HOME/.zprofile"
rm "$HOME/.zlogout"
rm "$HOME/.zshrc"
rm "$HOME/.zshenv"
cp "$HOME/.old_scripts/.z*" "$HOME"
find "$HOME/.old_scripts" -name ".z*" -mindepth 1 -delete
if [ -z "$(ls -A "$HOME/.old_scripts")" ]; then
rm -r "$HOME/.old_scripts"
fi
elif [[ $(detect_shell) = "bash" ]]; then
rm "$HOME/.bashrc"
rm "$HOME/.bash_profile"
rm "$HOME/.bash_logout"
rm "$HOME/.profile"
cp "$HOME/.old_scripts/.bash"* "$HOME"
cp "$HOME/.old_scripts/.profile" "$HOME"
rm -r "$HOME/.old_scripts"
fi
rm "$HOME/.mytheme.omp.json"
rm "$HOME/.clang-format"
echo "Finished uninstall"
else
echo "Nothing to uninstall"
fi
}
perform_install() {
echo "Starting install"
if [[ $OSTYPE = "darwin" ]] ; then
source ./preinstall/mac
elif [[ $OSTYPE = "linux-gnu" ]] ; then
source ./preinstall/linux
fi
hash -r
cp "$SCRIPT_DIRECTORY/configs/.mytheme.omp.json" "$HOME/"
cp "$SCRIPT_DIRECTORY/configs/clang-format.template" "$HOME/"
mv "$HOME/clang-format.template" "$HOME/.clang-format"
mkdir "$HOME/.old_scripts"
if [[ $(detect_shell) = "zsh" ]]; then
mv "$HOME/.zshenv" "$HOME/.old_scripts/.zshenv" \
&& echo "source \"$HOME/.old_scripts/.zshenv\"" > "$HOME/.zshenv"
mv "$HOME/.zprofile" "$HOME/.old_scripts/.zprofile" \
&& echo "source \"$HOME/.old_scripts/.zprofile\"" > "$HOME/.zprofile"
mv "$HOME/.zshrc" "$HOME/.old_scripts/.zshrc" \
&& echo "source \"$HOME/.old_scripts/.zshrc\"" > "$HOME/.zshrc"
mv "$HOME/.zlogout" "$HOME/.old_scripts/.zlogout" \
&& echo "source \"$HOME/.old_scripts/.zlogout\"" > "$HOME/.zlogout"
mv "$HOME/.zlogin" "$HOME/.old_scripts/.zlogin"
if [ ! -f "$HOME/.zprofile" ] && [ -f "$HOME/.old_scripts/.zlogin" ]; then
echo "source \"$HOME/.old_scripts/.zlogin\"" > "$HOME/.zprofile"
fi
touch "$HOME/.zshenv"
touch "$HOME/.zprofile"
touch "$HOME/.zshrc"
touch "$HOME/.zlogout"
echo "source \"$SCRIPT_DIRECTORY/sys_scripts/env_zsh\"" >> "$HOME/.zshenv"
echo "source \"$SCRIPT_DIRECTORY/sys_scripts/login_zsh\"" >> "$HOME/.zprofile"
echo "source \"$SCRIPT_DIRECTORY/sys_scripts/interactive_zsh\"" >> "$HOME/.zshrc"
echo "source \"$SCRIPT_DIRECTORY/sys_scripts/logout_zsh\"" >> "$HOME/.zlogout"
cat <(echo "SCRIPT_DIRECTORY=$SCRIPT_DIRECTORY") "$HOME/.zshenv" > "$HOME/.zshenv_tmp" \
&& mv "$HOME/.zshenv_tmp" "$HOME/.zshenv"
cat <(echo "SCRIPT_DIRECTORY=$SCRIPT_DIRECTORY") "$HOME/.zprofile" > "$HOME/.zprofile_tmp" \
&& mv "$HOME/.zprofile_tmp" "$HOME/.zprofile"
cat <(echo "SCRIPT_DIRECTORY=$SCRIPT_DIRECTORY") "$HOME/.zshrc" > "$HOME/.zshrc_tmp" \
&& mv "$HOME/.zshrc_tmp" "$HOME/.zshrc"
cat <(echo "SCRIPT_DIRECTORY=$SCRIPT_DIRECTORY") "$HOME/.zlogout" > "$HOME/.zlogout_tmp" \
&& mv "$HOME/.zlogout_tmp" "$HOME/.zlogout"
elif [[ $(detect_shell) = "bash" ]]; then
mv "$HOME/.bash_profile" "$HOME/.old_scripts/.bash_profile" \
&& echo "source \"$HOME/.old_scripts/.bash_profile\"" > "$HOME/.bash_profile"
mv "$HOME/.bashrc" "$HOME/.old_scripts/.bashrc" \
&& echo "source \"$HOME/.old_scripts/.bashrc\"" > "$HOME/.bashrc"
mv "$HOME/.profile" "$HOME/.old_scripts/.profile" \
&& echo "source $HOME/.old_scripts/.profile"
mv "$HOME/.bash_logout" "$HOME/.old_scripts/.bash_logout" \
&& echo "source \"$HOME/.old_scripts/.bash_logout\"" > "$HOME/.bash_logout"
mv "$HOME/.bash_login" "$HOME/.old_scripts/.bash_login"
if [ ! -f "$HOME/.bash_profile" ] && [ -f "$HOME/.old_scripts/.bash_login" ]; then
echo "source \"$HOME/.old_scripts/.bash_login\"" > "$HOME/.bash_profile"
fi
touch "$HOME/.bash_profile"
touch "$HOME/.bashrc"
touch "$HOME/.bash_logout"
touch "$HOME/.profile"
{
echo "if [[ -z \$USERSCRIPTS_ENV_LOADED ]] || [[ \$USERSCRIPTS_ENV_LOADED = 0 ]]; then"
echo " source \"$SCRIPT_DIRECTORY/sys_scripts/env_bash\""
echo " USERSCRIPTS_ENV_LOADED=1"
echo "fi"
} >> "$HOME/.bash_profile"
{
echo "if [[ -z \$USERSCRIPTS_ENV_LOADED ]] || [[ \$USERSCRIPTS_ENV_LOADED = 0 ]]; then"
echo " source \"$SCRIPT_DIRECTORY/sys_scripts/env_bash\""
echo " USERSCRIPTS_ENV_LOADED=1"
echo "fi"
} >> "$HOME/.bashrc"
echo "source \"$SCRIPT_DIRECTORY/sys_scripts/login_bash\"" >> "$HOME/.bash_profile"
echo "[[ \$- = *i* ]] && source \"\$HOME/.bashrc\"" >> "$HOME/.bash_profile"
echo "source \"$SCRIPT_DIRECTORY/sys_scripts/interactive_bash\"" >> "$HOME/.bashrc"
echo "source \"$SCRIPT_DIRECTORY/sys_scripts/profile_bash\"" >> "$HOME/.profile"
echo "source \"$SCRIPT_DIRECTORY/sys_scripts/logout_bash\"" >> "$HOME/.bash_logout"
cat <(echo "SCRIPT_DIRECTORY=$SCRIPT_DIRECTORY") "$HOME/.bash_profile" > "$HOME/.bash_profile_tmp" \
&& mv "$HOME/.bash_profile_tmp" "$HOME/.bash_profile"
cat <(echo "SCRIPT_DIRECTORY=$SCRIPT_DIRECTORY") "$HOME/.bashrc" > "$HOME/.bashrc_tmp" \
&& mv "$HOME/.bashrc_tmp" "$HOME/.bashrc"
cat <(echo "SCRIPT_DIRECTORY=$SCRIPT_DIRECTORY") "$HOME/.bash_logout" > "$HOME/.bash_logout_tmp" \
&& mv "$HOME/.bash_logout_tmp" "$HOME/.bash_logout"
cat <(echo "SCRIPT_DIRECTORY=$SCRIPT_DIRECTORY") "$HOME/.profile" > "$HOME/.profile_tmp" \
&& mv "$HOME/.profile_tmp" "$HOME/.profile"
elif [[ $(detect_shell) = "fish" ]]; then
echo "Unsupported"
# TODO: Handle startup scripts
elif [[ $(detect_shell) = "csh" ]]; then
echo "Unsopported"
# TODO: Handle startup scripts
fi
}
perform_reinstall() {
perform_uninstall
perform_install
}
perform_reinstall