-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcreate_symlinks.sh
More file actions
executable file
·331 lines (273 loc) · 10 KB
/
create_symlinks.sh
File metadata and controls
executable file
·331 lines (273 loc) · 10 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
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#!/bin/bash
# create symlinks for config files mostly under ~/ and other directories
# Do NOT run as root, as this will cause the $HOME variable to default
# to '/root' instead of ~/username and cause $USER to become 'root'
# instead of local user.
#
# Last updated 2017-02-18
# by Jun Go
create_sym()
{
# this function takes 2 string arguments:
# (1) original file with full path
# (2) replacement file with full path
#
# Given (1), the function will check if the file exists and is a symlink.
# Depending on what it finds it will do the following
# + File exists and _is not_ a symlink
# - file will be renamed to 'file.old'
# - create a symlink from (2) to (1)
# + File exists and _is_ a symlink
# - exit the function
# + File does not exist
# - create a symlink from (2) to (1)
#
# USAGE:
# create_sym <orig file w/path> <replacement file w/path>
ORIG=$1
REPLACE=$2
if [[ -f "$ORIG" && ! -L "$ORIG" ]]; then
mv "$ORIG" "$ORIG".old
ln -s "$REPLACE" "$ORIG"
elif [[ -f "$ORIG" && -L "$ORIG" ]]; then
printf "%s\n" "$ORIG exists and is already a symlink."
else
ln -s "$REPLACE" "$ORIG"
fi
}
printf "%s\n" "##################################################"
printf "%s\n" "# Check that the script is not being run as root #"
printf "%s\n" "##################################################"
if [ "$USER" = "root" ]; then
printf "%s\n" "This script must not be executed as root."
exit 1
fi
printf "%s\n" "##################################################"
printf "%s\n" "# Create Symlinks to dotfiles directly below ~/ #"
printf "%s\n" "##################################################"
DOTFILES="bashrc conkyrc emacs mrconfig screenrc vimrc xinitrc \
pylintrc"
for i in $DOTFILES; do
create_sym "$HOME/.$i" "$HOME/dotfiles/$i"
done
######################################################
# Create Symlinks to files in subdirectories of $HOME
######################################################
#CMUS CONFIG
if [ -f /usr/bin/cmus ]; then
create_sym "$HOME/.config/cmus/lib.pl" "$HOME/dotfiles/cmus_libpl"
else
printf "%s\n" "CMUS is not installed on this machine"
fi
#LXTERMINAL CONFIG
if [ -f /usr/bin/lxterminal ]; then
create_sym "$HOME/.config/lxterminal/lxterminal.conf" \
"$HOME/dotfiles/lxterminal"
else
printf "%s\n" "lxterminal is not installed on this machine"
fi
#MAME CONFIG
if [ -f /usr/bin/sdlmame ]; then
mkdir -p "$HOME/.mame/ini"
create_sym "$HOME/.mame/ini/mame.ini" "$HOME/dotfiles/mame.ini"
else
printf "%s\n" "sdlmame is not installed on this machine"
fi
#TERMINATOR CONFIG
if [ -f /usr/bin/terminator ]; then
create_sym "$HOME/.config/terminator/config" "$HOME/dotfiles/terminator"
else
printf "%s\n" "terminator is not installed on this machine"
fi
#IRSSI CONFIG
if [ -f /usr/bin/irssi ]; then
if [ ! -d "$HOME/.irssi" ]; then
mkdir "$HOME/.irssi"
fi
create_sym "$HOME/.irssi/config" "$HOME/dotfiles/irssi-config"
if [ -f "$HOME/SpiderOak Hive/keys/irssi.pem" ]; then
ln -s "$HOME/SpiderOak Hive/keys/irssi.pem" "$HOME/.irssi/"
fi
else
printf "%s\n" "irssi is not installed on this machine"
fi
#QUODLIBET CONFIG
if [ -f /usr/bin/quodlibet ]; then
create_sym "$HOME/.quodlibet/stations" "$HOME/dotfiles/quod_stations"
else
printf "%s\n" "quodlibet is not installed on this machine"
fi
# Note: Recent versions of quodlibet overwrite the symlinked
# 'stations' file and replace it with a regular file
#SSH CONFIG
if ! [ -d "$HOME/.ssh" ]; then
mkdir -p "$HOME/.ssh"
chmod 700 "$HOME/.ssh"
fi
create_sym "$HOME/.ssh/config" "$HOME/dotfiles/ssh-config"
chmod 600 "$HOME/.ssh/config"
######################################################
# Create Openbox Symlinks
######################################################
#OPENBOX AUTOSTART
if [ -f /usr/sbin/openbox-session ]; then
create_sym "$HOME/.config/openbox/autostart" \
"$HOME/dotfiles/openbox/openbox-autostart"
else
printf "%s\n" "openbox DE is not installed on this machine"
fi
######################################################
# Create XFCE4 Symlinks
######################################################
# XFCE4 TERMINAL CONFIG
if [ -f /usr/bin/xfce4-terminal ]; then
create_sym "$HOME/.config/xfce4/terminal/terminalrc" \
"$HOME/dotfiles/xfce4/xfceTerm"
else
printf "%s\n" "xfce-terminal is not installed on this machine"
fi
# XFCE4 MENU
#if [ -f /usr/bin/startxfce4 ]; then
# create_sym "" "$HOME/dotfiles/xfce4/"
#fi
# XFCE4 PANEL
# XFCE4 KEYBOARD SHORTCUTS
if [ -f /usr/bin/startxfce4 ]; then
create_sym "$HOME/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml" \
"$HOME/dotfiles/xfce4-keyboard-shortcuts.xml"
else
printf "%s\n" "xfce4 is not installed on this machine"
fi
######################################################
# Create Symlinks to files under /root
######################################################
# NOTE: to create symlinks from root_bashrc to /root/.bashrc
# your regular user needs to have rwx permissions on /root
# and subdir's; make sure to run 'setACL_symlinks.sh' first
create_sym "/root/.bashrc" "$HOME/dotfiles/root_bashc"
create_sym "/root/.vimrc" "$HOME/dotfiles/vimrc"
######################################################
# Create Symlinks to files under /etc
######################################################
# NOTE: to create symlinks from ~/dotfiles/anacrontab
# to /etc/anacrontab, for example, the regular user needs
# to have rwx permissions on /etc and subdir's;
# make sure to run 'setACL_symlinks.sh' first
if [ -f /etc/redhat-release ]; then
create_sym "/etc/anacrontab" "$HOME/dotfiles/anacrontab_fedora"
else
create_sym "/etc/anacrontab" "$HOME/dotfiles/anacrontab"
fi
if [ -f /usr/bin/dnsmasq ]; then
create_sym "/etc/dnsmasq.conf" "$HOME/dotfiles/dnsmasq"
create_sym "/usr/local/dnsmasq/resolv-file" "$HOME/dotfiles/dnsmasq_resolv_file"
else
printf "%s\n" "dnsmasq is not installed on this machine"
fi
# NOTE ABOUT dnsmasq and SELINUX
# When you create a symlink from $HOME/dotfiles/dnsmasq to
# /etc/dnsmasq.conf, the SELINUX context will be
# 'unconfined_u:object_r:etc_t:s0'
# but the context should be
# 'system_u:system_r:dnsmasq_t:s0'
# To set 'dnsmasq_t' to permissive mode, execute the following:
# sudo semanage permissive -a dnsmasq_t
# OR
# You can change the context on ~/dotfiles/dnsmasq which is
# symlinked to /etc/dnsmasq.conf as follows:
# `sudo semanage fcontext -a -t dnsmasq_etc_t /home/fedjun/dotfiles/dnsmasq`
# `sudo restorecon -v /home/fedjun/dotfiles/dnsmasq`
if [ -f /usr/sbin/pacman ]; then
create_sym "/etc/pacman.conf" "$HOME/dotfiles/pacman.conf"
create_sym "/etc/pacman.d/mirrorlist" "$HOME/dotfiles/pacman_mirrorlist"
else
printf "%s\n" "This system is not running Archlinux"
fi
if which bitlbee; then
if grep "Fedora" /etc/redhat-release; then
create_sym "/etc/bitlbee/bitlbee.conf" "$HOME/dotfiles/bitlbee_fedora"
else
create_sym "/etc/bitlbee/bitlbee.conf" "$HOME/dotfiles/bitlbee"
fi
else
printf "%s\n" "bitlbee is not installed on this machine"
fi
if [ -f /usr/bin/vsftpd ]; then
create_sym "/etc/vsftpd.conf" "$HOME/dotfiles/vsftpd.conf"
else
printf "%s\n" "vsftpd is not installed on this machine"
fi
if [ -f /usr/bin/motion ]; then
SYSINFO=$(sudo dmidecode | grep -i "System Information" -A 8)
# If machine is U36JC, use motion-u36jc.conf
if [[ "$SYSINFO" = *U36JC* ]]; then
create_sym "/etc/motion/motion.conf" "$HOME/dotfiles/motion-u36jc.conf"
# For all other machines use regular motion-4.conf
else
create_sym "/etc/motion/motion.conf" "$HOME/dotfiles/motion-4.conf"
fi
else
printf "%s\n" "motion is not installed on this machine"
fi
# Set config for ssh daemon
create_sym "/etc/ssh/sshd_config" "$HOME/dotfiles/sshd_config"
if [ -f /usr/bin/ansible ]; then
create_sym "/etc/ansible/ansible.cfg" "$HOME/dotfiles/ansible/ansible.cfg"
create_sym "/etc/ansible/hosts" "$HOME/dotfiles/ansible/hosts"
mkdir -p /etc/ansible/group_vars/
create_sym "/etc/ansible/group_vars/ubuntu_base" \
"$HOME/dotfiles/ansible/group_vars/ubuntu_base"
else
printf "%s\n" "ansible is not installed on this machine"
fi
# Note: qemu.conf is Archlinux-specific customized
# TODO: create an alternate version for Fedora and cond'l check
if [ -f /usr/bin/libvirtd ]; then
create_sym "/etc/libvirt/qemu.conf" "$HOME/dotfiles/qemu.conf"
else
printf "%s\n" "libvirt is not installed on this machine"
fi
######################################################
# Vim-specific config files etc.
######################################################
# Create tmp dir's for vim
if ! [ -d "$HOME/tmp" ]; then
mkdir "$HOME"/tmp
fi
if ! [ -d /root/tmp ]; then
printf "%s\n" "Make sure to create /root/tmp for when vim is run as 'root'"
fi
# Create symlinks for vim syntax files
if ! [ -d "$HOME"/.vim/after/ftplugin ]; then
mkdir -p "$HOME"/.vim/after/ftplugin
fi
create_sym "$HOME/.vim/after/ftplugin/yaml.vim" "$HOME/dotfiles/vim/yaml.vim"
create_sym "$HOME/.vim/after/ftplugin/sh.vim" "$HOME/dotfiles/vim/sh.vim"
######################################################
# Create symlinks for SSH keys on SpiderOak
######################################################
KEYS=(junAUR
archjun_rsa
cloud
fx8350
)
KEYLIST=$HOME/keylist.txt
for i in ${KEYS[*]}; do
find "$HOME/SpiderOak Hive/keys/ssh" -type f -name "${i}*" >> "$KEYLIST"
done
while read -r key; do
keyname=$(basename "$key")
if ! [ -f "$HOME/.ssh/$keyname" ]; then
printf "%s\n" "### Create symlink to ~/.ssh for $keyname ###"
ln -s "$key" "$HOME/.ssh/"
fi
done<"$KEYLIST"
printf "%s\n" "####################################################"
printf "%s\n" "# Setup git user name and email #"
printf "%s\n" "####################################################"
git config --global user.email "gojun077@gmail.com"
git config --global user.name "$USER"
printf "%s\n" "####################################################"
printf "%s\n" "# Setup Mnemosyne #"
printf "%s\n" "####################################################"
ln -s "$HOME/Dropbox/mnemosyne" "$HOME/.local/share/"