-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall
executable file
·332 lines (290 loc) · 9.5 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
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
332
#!/bin/bash
# Installer script to set up symlinks for configuration files.
# Assumes it is being run as `./install <path>`, i.e. from the directory
# it lives in.
# TODO(sdh): add conditional logic to the patch scripts, so that
# we can do feature testing rather than whitelist machines.
# TODO(sdh): support a NOCOMMENT directive in patches
# TODO(sdh): automatically download and install monofur-powerline fonts ?
# TODO(sdh): fallback on apt-get for terminal emulator (maybe switch to alacritty
# instead of urxvt?)
# TODO(sdh): merge tmux changes, consider pushing upstream?
verbose=false
conf=$(dirname "$0")
conf=${conf-.}
cd $conf
conf=$(pwd -P)
home=$HOME
function whisper {
if $verbose; then echo "$@"; fi
}
function safe_patch {
whisper SAFE_PATCH "$@"
source_orig=$1
patch=$2
target=$3
comment=$(grep 'COMMENT=' $patch | sed 's/^.*COMMENT=//')
interp=$(head -n 1 $patch | grep '^#!' | sed 's/^#!//')
comment=${comment:-#}
if [ ! -e "$target" ] ||
[ -h "$target" -a "$(readlink $target)" = "$source_orig" ] ||
grep -q 'DO NOT EDIT' $target; then
if [ -h "$target" ]; then unlink $target; fi
cat > $target <<EOF
$comment --------------------------------------------------------------
$comment ATTENTION: THIS FILE IS AUTOMATICALLY GENERATED! DO NOT EDIT!
$comment Instead edit one of the following
$comment $source_orig
$comment $patch
$comment and then re-run $conf/install
$comment --------------------------------------------------------------
EOF
$interp $patch $source_orig >> $target
else
echo "Refusing to write $target: file exists." >&2
fi
}
function safe_link {
# First set parameters/defaults
whisper SAFE_LINK "$@"
local target=${2:-.$1}
if [ -n "${target%%/*}" ]; then # allow absolute paths
target="$home/$target"
fi
local source="$conf/$1"
if [ ! -e "$source" ]; then
echo "ERROR: $source does not exist" >&2
return
fi
# Now see if it's a dir, in which case we make a symlink tree
# TODO(sdh): should probably just flatten with `find`.
if [ -d "$source" -a ! -e "$source/.linkdir" ]; then
if [ -e "$target" -a ! -d "$target" ]; then
echo "Cannot symlink tree $source -> $target: file exists." >&2
fi
mkdir -p $target
for a in $(ls -a $source); do
if [ "$a" = . -o "$a" = .. -o -h "$source/$a" ]; then continue; fi
safe_link $1/$a ${2:-.$1}/$a
done
return
fi
# Check for a hostname-specific patch
if [ -e $source.patch.$(hostname -s) ]; then
safe_patch $source $source.patch.$(hostname -s) $target
return
fi
# Otherwise do some safety checks and make the link
if [ -h "$target" -a "$(readlink $target)" = "$source" ]; then
# it's already there
:
elif [ -s "$target" ] && diff -q "$source" "$target" &> /dev/null; then
# identical file: remove and symlink
rm "$target"
ln -s "$source" "$target"
elif [ -s "$target" -o -d "$target" ]; then
echo "Cannot symlink $source -> $target: file exists." >&2
else
ln -s "$source" "$target"
fi
}
function install_files {
echo "Installing config files from $conf into $home..."
safe_link XCompose
safe_link Xdefaults
safe_link tmux.conf
safe_link alacritty.yml
safe_link bashrc
safe_link zshrc
safe_link gitconfig
safe_link gitignore_global
safe_link imwheelrc
safe_link aspell.en.pws
safe_link dot-emacs .emacs
safe_link dot-config .config
sudo rm /etc/udev/rules.d/10-uinput.rules
sudo rm /etc/udev/rules.d/85-usb.rules
sudo ln -s $PWD/udev/*.rules /etc/udev/rules.d/
# Link everything in the bash directory
cd sh
mkdir -p $home/.sh.d
for a in *; do
a=${a#*~}
[ -f "$a" ] && safe_link sh/$a .sh.d/$a
done
if [ ! -e $home/.sh.d/functions ]; then
ln -s $PWD/functions $home/.sh.d/
fi
# Unlink everything in the disabled directory
if [ -d disabled ]; then
cd disabled
for a in *; do
a=${a#*~}
if [ -f "$a" ]; then
target="$home/.sh.d/$a"
if [ -h $target -a "$(readlink $target)" = "$conf/sh/$a" ]; then
rm -f $target
elif [ -s "$target" ]; then
echo "Refusing to delete non-symlink $target even though disabled."
fi
fi
done
cd ..
fi
cd ..
# Link everything in the bin directory
mkdir -p $home/local/bin
for a in bin/*; do
safe_link $a local/$a
done
# Perl lib dir - will link entire dirs
mkdir -p $home/local/lib/perl
for a in perl/*; do
safe_link $a local/lib/$a
done
# Make bash completion dir so somebody doesn't complain
mkdir -p $home/.sh.d/completion
# Make sure history dir exists
mkdir -p $home/history
mkdir -p $home/.emacs_backups
# Install urxvt extensions
#install_urxvt
# Link all the emacs files
#cd emacs
#mkdir -p $home/.emacs.d
#for a in *.el; do
# safe_link emacs/$a .emacs.d/$a
#done
# Install .gitconfig.d
mkdir -p $home/.gitconfig.d/templates
if [ -e /usr/share/git-core/templates ]; then
cp -nr /usr/share/git-core/templates/* $home/.gitconfig.d/templates
chmod a-x $home/.gitconfig.d/templates/hooks/*.sample
fi
if [ -e git ]; then # this is safe to remove if we ever add a git/ dir
for a in git/*; do
safe_link $a .gitconfig.d/${a#git/}
done
fi
}
function install_fonts {
# Also available at ...
# https://github.com/powerline/fonts/raw/master/Monofur/Monofur%20for%20Powerline.ttf
# https://github.com/powerline/fonts/raw/master/Monofur/Monofur%20Italic%20for%20Powerline.ttf
(
sudo mkdir -p /usr/share/fonts/truetype/monofur
cd /usr/share/fonts/truetype/monofur
sudo wget 'https://github.com/kakkoyun/linux.files/blob/master/fonts/Monofur.ttf?raw=true'
# sudo wget https://github.com/rsrsl/ttf-monofur-powerline/raw/master/monof55.ttf
# sudo wget https://github.com/rsrsl/ttf-monofur-powerline/raw/master/monof56.ttf
sudo fc-cache -fv .
)
safe_link dot-fonts .fonts
}
function install_term {
# Install the tmux-256color terminfo config
echo "Installing terminfo..."
mkdir -p $HOME/.terminfo
tic -x "$(dirname "$0")"/terminfo.src
}
function install_gtk {
# Set up chrome/emacs keybindings using the tool instead
# Also set up focus follows mouse and window buttons
# NOTE: this only works in we're running locally
echo "Configuring gtk keybindings..."
safe_link gtkrc-2.0
safe_link dot-config/gtk-3.0 .config/gtk-3.0
if which gsettings &>/dev/null; then
gsettings set org.cinnamon.desktop.interface gtk-key-theme "Emacs"
gsettings set org.gnome.desktop.interface gtk-key-theme Emacs
gsettings set org.gnome.desktop.wm.preferences focus-mode sloppy
gsettings set org.gnome.desktop.wm.preferences auto-raise false
gsettings set org.gnome.desktop.wm.preferences button-layout \
'menu:minimize,maximize,close'
gsettings set org.gnome.desktop.wm.preferences \
action-double-click-titlebar 'toggle-shade'
gsettings set org.gnome.desktop.wm.preferences \
resize-with-right-button true
fi
if which gconftool-2 &>/dev/null; then
gconftool-2 --set /desktop/gnome/interface/gtk_key_theme Emacs \
--type string
gconftool-2 --set /apps/metacity/general/focus_mode sloppy \
--type string
gconftool-2 --set /apps/metacity/general/auto-raise false \
--type bool
gconftool-2 --set /apps/metacity/general/button_layout \
'menu:minimize,maximize,close' --type string
gconftool-2 --set /apps/metacity/general/action_double_click_titlebar \
'toggle_shade' --type string
gconftool-2 --set /apps/metacity/general/resize_with_right_button \
true --type bool
fi
}
# function install_urxvt {
# # Detects URXVT install dir and installs it - called from install_files
# if ! which urxvt &> /dev/null; then return; fi
# local urxvt=$(readlink -f $(which urxvt))
# local perldir=${urxvt%/bin*}/lib/urxvt/perl
# safe_link urxvt/mycopy-osc ${perldir}/mycopy-osc
# }
function install_fzf {
# NOTE: Should happen after git and go are both installed...
echo "Installing fzf"
(
mkdir -p ~/local/opt
cd ~/local/opt
git clone --depth=1 https://github.com/junegunn/fzf
cd fzf
yes | ./install
# Fix TMUX environment variable overriding (broken)
sed 's/TMUX=\$([^)]*) //g' bin/fzf-tmux > ~/local/bin/fzf-tmux
chmod +x ~/local/bin/fzf-tmux
# Fix ^T to ^F for inserting a filename.
sed -i 's/\^T/^F/g' shell/*.zsh
sed -i 's/\\C-t/\\C-f/g' shell/*.sh
)
}
function print_usage {
cat <<EOF
Usage: install [home dir] [files|term|gtk|all]...
Note that the home dir MUST come first if it is given
Functions:
files - symlink all dot-files
term - generate the tmux-256color terminfo
gtk - configure gtk apps to use emacs keybindings
all - all of the above
EOF
exit 1
}
if [ $# -eq 0 ]; then
print_usage
fi
while [ $# -gt 0 ]; do
case "$1" in
(files) install_files ;;
(term) install_term ;;
(gtk) install_gtk ;;
(all) install_files; install_term; install_gtk ;;
(fzf) install_fzf ;;
(fonts) install_fonts ;;
(*) if [ -f $1 ]; then
home=$1
else
print_usage
fi
;;
esac
shift
done
cat >&2 <<EOF
Next steps:
git clone [email protected]:shicks/repoline ~/local/src/repoline
ln -s ~/local/src/repoline/{ansi,repo}line ~/local/bin/
sudo apt install aptitude emacs-lucid imwheel xinput awesome cmake rust-all \
pkg-config python3 python3-pip libfreetype6-dev libfontconfig1-dev \
libxcb-xfixes0-dev libxkbcommon-dev
cargo install alacritty
sudo pip3 install xkeysnail
echo "blacklist pcspkr" | sudo tee -a /etc/modprobe.d/blacklist.conf
EOF