-
Notifications
You must be signed in to change notification settings - Fork 5
/
install
executable file
·182 lines (151 loc) · 3.71 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
#!/usr/bin/env bash
verbose() { if (( VERBOSE )); then echo "dotinstall: $*"; fi; }
have() { command -v "$1" >&/dev/null; }
trash() {
local trashdir=~/tmp file
for file in "$@"; do
if [ -k "$file" ]; then
trace "ignoring sticky $file"
elif [ -e "$file" ] || [ -h "$file" ]; then
echo "backing up $file -> $trashdir"
mkdir -pm 0700 "$trashdir"
mv "$file" "$trashdir/old_${file##*/}"
fi
done
}
link() {
local target=$dotdir/${1%/}
local link=${2:-$HOME/.$1}
if [ ! -e "$target" ]; then
err "link target is missing: $link -> $target"
return
elif [ -e "$link" ]; then
if [ -k "$link" ]; then
trace "ignoring sticky $link"
return
elif [ -h "$link" ]; then
rm -f "$link"
else
trash "$link"
fi
else
local linkdir=${link%/*}
if [ ! -d "$linkdir" ]; then
mkdir -p "$linkdir"
fi
fi
trace "linking $link -> $target"
sym -f "$target" "$link"
}
check_owner() {
local f
for f in "$@"; do
if [ -h "$f" ]; then
continue
elif [ -e "$f" ] && [ ! -O "$f" ]; then
case $f in
*/.mysql_history)
continue ;;
*)
notice "file '$f' not owned by me, replacing"
trash "$f" ;;
esac
(umask 077; touch "$f")
elif [ -d "$f" ] && [ ! -O "$f" ]; then
notice "dir '$f' not owned by me, replacing"
trash "$f"
(umask 077; mkdir "$f")
fi
done
}
umask 077
export PATH="$HOME/bin:$HOME/bin/bin:$PATH" # TODO: bin/bin/sym
. lib.bash || exit
update=false
foreign=false
while getopts ":uv" OPT; do
case $OPT in
u) update=true;;
v) VERBOSE=1;;
*) lib::die_getopts;;
esac
done; shift $((OPTIND-1))
if [[ -t 0 ]]; then
VERBOSE=1
fi
dotdir="$(dirname "$(sym -R "$0")")"
trashdir=~/tmp
cd "$dotdir" || exit
# TODO: In update mode, only adjust existing links, do not create new ones.
if $update; then
verbose "Updating ~/.ssh/config"
ssh/generate
exit 0
fi
# Remove undesired files
trash ~/.{login,logout}
trash ~/.bash_{login,profile,logout}
trash ~/.{sh,csh}rc
# Ensure permissions for config directories
check_owner ~/.{cache,config,local,local/{share,state}}
mkdir -p ~/.{cache,config,local,local/{share,state}}
chmod go= ~/.{cache,config,local,local/{share,state}}
# Check frequent root-ownership accidents
check_owner ~/.*_history ~/.gnupg ~/.rnd
rm -f ~/.lesshst
# Install shell profiles
link bashrc
link inputrc
link profile
# OpenSSH
ssh/generate
link ssh/known_hosts
# Git
link git ~/.config/git
touch ~/.config/git/credentials
chmod go= ~/.config/git/credentials
mkdir -p ~/.local/share/tig
chmod go= ~/.local/share/tig
touch ~/.local/share/tig/history
chmod go= ~/.local/share/tig/history
# lftp
link lftprc ~/.config/lftp/rc
# msmtp
link msmtprc ~/.config/msmtp/config
chmod go= msmtprc
# tmux (XDG paths are supported starting with tmux 3.1)
link tmux.conf ~/.config/tmux/tmux.conf
# vim & NeoVim
link vim ~/.vim
link vim ~/.config/nvim
link micro ~/.config/micro
rm -f ~/.viminfo
mkdir -p -m go= ~/.local/share/nvim/{backup,shada,swap,undo}
chmod go= ~/.local/share/nvim
chmod go= ~/.config/micro
# Mutt & NeoMutt
if have mutt || have neomutt; then
if [ ! -e ~/.config/mutt/muttrc ]; then
xdotdir=${dotdir/#"$HOME/"/"~/"}
mkdir -p ~/.config/mutt
echo "source \"$xdotdir/muttrc\"" > ~/.config/mutt/muttrc
echo "source \"$xdotdir/muttrc.sh|\"" >> ~/.config/mutt/muttrc
fi
if [ ! -e ~/.config/neomutt ]; then
ln -nsf mutt ~/.config/neomutt
fi
fi
# Install GUI configs
if [ "$DISPLAY" ]; then
# Systemd --user environment.d(5) generator
# (see also systemd-environment-d-generator(8))
link environ-desktop ~/.config/environment.d/20-desktop.conf
if [ ! -d ~/.config/fontconfig ]; then
link fontconfig ~/.config/fontconfig
fi
link XCompose ~/.XCompose
fi
if [ -e environ-$HOSTNAME ]; then
link environ-$HOSTNAME ~/.config/environment.d/80-host.conf
fi
exit 0