-
Notifications
You must be signed in to change notification settings - Fork 1
/
install
executable file
·164 lines (148 loc) · 3.33 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
#!/bin/sh
cd "$(dirname "$0")"
DOTFILES=$(pwd)
_all=yes
_link=
_shell=
_external=
_force=
while case "$#,$1" in
0,*) break ;;
*,--) shift; break ;;
*,-l | *,--link) _all= ; _link=yes ;;
*,-s | *,--shell) _all= ; _shell=yes ;;
*,-e | *,--external) _all= ; _external=yes ;;
*,-f | *,--force) _force=yes ;;
*,-V | *,--vim) _vim=yes ;;
esac
do
shift
done
# Verify that we tracked that file with Git history before
# If yes, force relink, otherwise, warn them
if test -n "$_force"
then
vlink() {
rm -f "$2"
cp -fp "$1" "$2"
}
else
if test "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = true
then
vtracked() {
_ohash=$(git hash-object "$1")
test "$(git cat-file -t "$_ohash" 2>/dev/null)" = blob
}
else
vtracked() {
return 1
}
fi
vlink() {
if test ! -f "$2"
then
cp -fp "$1" "$2"
elif cmp -s "$1" "$2"
then
:
elif vtracked "$2"
then
rm -f "$2"
cp -fp "$1" "$2"
else
printf "%s \n" "NO LINK: '$2' exists and not tracked."
fi
}
fi
test -n "$_all$_external" &&
git submodule update --init || :
# There's a bug in stow --dotfiles
# When the dot-dir already exists.
# https://lists.gnu.org/archive/html/bug-stow/2020-05/msg00000.html
# Roll my own
find home -type d |
sed -n "s,home/,$HOME/.,p" |
xargs mkdir -p
mkdir -p ~/bin
# stow --ignore='\.sw.' --dotfiles -t "$HOME" home
for _file in bin/*
do
vlink "$_file" "$HOME/$_file"
done
mksupervise() {
if test ! -L "$HOME/.local/service/$2/supervise"; then
ln -s "/run/x-user/$USER/runit/supervise.$1" \
"$HOME/.local/service/$2/supervise"
fi
}
do_link() {
for _src in home/local/service/*; do
_target=".${_src#home/}"
_sv=${_src##*/}
if test -f "$_src/log/run"; then
mksupervise "$_sv-log" "$_sv/log"
vlink "$_src/log/run" "$HOME/$_target/log/run"
fi
mksupervise "$_sv" "$_sv"
for _file in "$_src"/*; do
case "$_file" in
*/run|*/log) ;;
*/down) : >"$HOME/$_target/down" ;;
*) vlink "$_file" "$HOME/$_target/${_file##*/}" ;;
esac
done
vlink "$_src/run" "$HOME/$_target/run"
done
find home -path home/local/service -prune \
-o -name '*.sw?' -prune \
-o -name '#*#' -prune \
-o -type f -print \
-o -type l -print |
while read -r _src; do
_target=".${_src#home/}"
if test -L "$_src"; then
cp "$_src" "$HOME/$_target"
elif test -f "$_src"; then
vlink "$DOTFILES/$_src" "$HOME/$_target"
fi
done
}
merge_shrc() {
printf '%s\n' *.sh *."$1" *."$1".in *."$1.$(uname -s)" |
sort |
while read f; do
case "$f" in
"*."*) ;;
*.in) sed "s,[$]DOTFILES,$DOTFILES," "$f" ;;
*) cat "$f" ;;
esac
done
}
mk_rc() {
cd sh
if command -v bash >/dev/null 2>&1; then
merge_shrc bash >"$HOME/.bashrc"
fi
if command -v zsh >/dev/null 2>&1; then
merge_shrc zsh >"$HOME/.zshrc"
zsh -c "zcompile $HOME/.zshrc"
fi
cd ..
}
test -n "$_all$_link" && do_link
test -n "$_all$_shell" && mk_rc
if test -n "$_vim" && test ! -L ~/.vim/pack/bundle/start; then
mkdir -p ~/.vim/pack/bundle
ln -s $DOTFILES/external/vim ~/.vim/pack/bundle/start
fi
mkdir -p ~/.emacs.d/elisp
_tmpfile=$(mktemp)
for dir in "$DOTFILES"/external/emacs/*
do
test -d "$dir" &&
printf "(add-to-list 'load-path \"%s\")\\n" "$dir"
done >"$_tmpfile"
if ! cmp "$_tmpfile" ~/.emacs.d/elisp/local-generated.el; then
cp "$_tmpfile" ~/.emacs.d/elisp/local-generated.el
fi
test -f ~/.config/git/local.conf || touch ~/.config/git/local.conf