forked from skeeto/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·101 lines (90 loc) · 2.35 KB
/
install.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
#!/bin/sh
set -e
IFS='
'
lnflags=-s
install_scripts=yes
install_private=no
usage() {
cat << EOF
usage: install.sh [options]
OPTIONS:
-l Install config files as hard links
-p Install private dotfiles
-h Show this message
EOF
exit $1
}
## Parse command line switches
while getopts "lph" option; do
case "$option" in
l) lnflags= ;;
p) install_private=yes ;;
h) usage 0 ;;
?) usage 1 ;;
esac
done
## Install scripts
bin=~/.local/bin
mkdir -p "$bin"
if [ $install_scripts = yes ]; then
echo Installing scripts
for script in $(find bin -type f -perm -+x); do
ln -fs -- "$(pwd)/$script" "$bin"
done
fi
## Installs an individual dotfile
install() {
dotfile="$1"
dest="$HOME/.${dotfile#./_*}"
if [ "$dotfile" = "${dotfile##*.enchive}" ]; then
echo Installing "$dotfile"
mkdir -p -m 700 "$(dirname "$dest")"
chmod go-rwx "$dotfile"
ln -f $lnflags "$(pwd)/$dotfile" "$dest"
elif [ $install_private = yes ]; then
dest="${dest%.enchive}"
if [ ! -e "$dest" -o "$dotfile" -nt "$dest" ]; then
echo Decrypting "$dotfile"
mkdir -p -m 700 "$(dirname "$dest")"
(umask 0177;
enchive --agent extract "$dotfile" "$dest")
else
echo Skipping "$dotfile"
fi
fi
}
## Install each _-prefixed file
for source in $(find . -name '_*' | sort); do
if [ -d "$source" ]; then
for dotfile in $(find "$source" -type f | sort); do
install "$dotfile"
done
else
install "$source"
fi
done
## Special cases
mkdir -p ~/.vim/spell
ln -sf /dev/null ~/.bash_history
chmod -w _config/vlc/vlcrc # Disables annoying VLC clobbering
## Reload .Xresources
if [ -n "$DISPLAY" ]; then
width=$(xdpyinfo 2> /dev/null | \
grep 'dimensions:' | tr x ' ' | awk '{print $2}')
if [ -z "$width" ] || [ "$width" -gt 1440 ]; then
font_size=10
else
font_size=9
fi
echo "#define FONT_SIZE $font_size" > ~/.Xresources.h
xrdb -I$HOME -merge ~/.Xresources 2> /dev/null
elif [ ! -e ~/.Xresources.h ]; then
echo "#define FONT_SIZE 9" > ~/.Xresources.h
fi
## Compile ssh config
printf "## WARNING: do not edit directly\n" > ~/.ssh/config
for f in ~/.ssh/config.d/*; do
printf '\n' >> ~/.ssh/config
cat "$f" >> ~/.ssh/config
done