-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·185 lines (158 loc) · 4.02 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
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
#!/bin/bash
set -e
DEST="$HOME/"
# config destination for programs that resolves home by UID (SSH -.-")
# Linux
if command -v getent &> /dev/null
then
DEST_UID="$(zsh -c "echo ~$(getent passwd "$UID" | cut -d: -f1)")"
# system without getent (macOS)
else
DEST_UID="$HOME"
fi
# paths which will be only copied once (NOT symlinked!)
is_oneshot()
{
[ "$1" = "./uid/.ssh/config.real" ] || [ "$1" = "./uid/.ssh/config" ]
}
# get a specific replacement for the given file
get_drop_in()
{
# Private IServ configuration
if [ -x /usr/sbin/iservchk ] && [ -f "./iserv-private/$1" ] && [[ "$(hostname -f)" =~ \.?(felix\.test-iserv\.de|jacobi-(bs\.de|hamburg\.net)|stsbl\.de|felix\.iserv\.dev)$ ]]
then
realpath -m "$PWD/iserv-private/$1"
return
fi
# IServ configuration for root
if [ "$EUID" = "0" ] && [ "$USER" = "root" ] && [ -x /usr/sbin/iservchk ] && [ -f "./iserv-root/$1" ]
then
realpath -m "$PWD/iserv-root/$1"
return
fi
# IServ configuration
if [ -x /usr/sbin/iservchk ] && [ -f "./iserv/$1" ]
then
realpath -m "$PWD/iserv/$1"
return
fi
# Work PC/VM
if ! uname -a | grep -q Darwin
then
if ([[ "$(hostname -f)" =~ (|\.)iserv.eu$ ]] || [[ "$(hostname -f)" =~ \.?(mein-iserv\.de|i\.local)$ ]]) &&
[ -f "./work/$1" ]
then
realpath -m "$PWD/work/$1"
return
fi
fi
echo "$2"
}
install_file()
{
rf="$1"
rd="$2"
if ! { [[ $rd =~ .config/autostart ]] || [[ $rd =~ .local/share/applications ]]; }
then
if [ "$(readlink -f "$rd")" = "$rf" ]
then
return
elif [ -L "$rd" ]
then
echo "Replacing existing symlink $rd with one to $rf."
ln -sf "$rf" "$rd"
return
fi
fi
mkdir -pv "$(dirname "$rd")"
if ! [ -e "$rd" ]
then
if [[ $rd =~ .config/autostart ]] || [[ $rd =~ .local/share/applications ]]
then
echo "Copying $rf to $rd."
cp -a "$rf" "$rd"
else
echo "Creating new symlink $rd to $rf."
ln -sf "$rf" "$rd"
fi
return
fi
if [[ $rd =~ .config/autostart ]] || [[ $rd =~ .local/share/applications ]]
then
if diff -u "$DEST/$f" "$rf"
then
# same file
true
else
echo "$rd is a real file. Difference with $rf:"
diff -u "$DEST/$f" "$rd" || true
replace=n
echo -n "Do you want to replace it? (y/N) "
read replace
if [ "$replace" = "y" ] || [ "$replace" = "Y" ]
then
echo "Replacing file $rd with copy of $rf."
rm -f "$DEST/$f"
cp -a "$rf" "$DEST/$f"
return
fi
fi
else
echo "$rd is a real file. Difference with $rf:"
diff -u "$DEST/$f" "$rf" || true
replace=n
echo -n "Do you want to replace it? (y/N) "
read replace
if [ "$replace" = "y" ] || [ "$replace" = "Y" ]
then
echo "Replacing file $rd with symlink to $rf."
ln -sf "$rf" "$rd"
return
fi
fi
}
for f in $(find -type f -not \( -path './uid/*' -or -path './.git/*' -or \
-path './install.sh' -or -path './README.md' -or \
-path './LICENSE' -or -path './iserv/*' -or \
-path './iserv-root/*' -or -path './work/*' \)
)
do
rf="$(realpath -sm "$f")"
rd="$(realpath -sm "$DEST/$f")"
install_file "$(get_drop_in "$f" "$rf")" "$rd"
done
for f in $(find -type f -path './uid/*')
do
rf="$(realpath -sm "$f")"
rd="$(realpath -sm "$DEST_UID/$(echo $f | sed -E 's#^\./uid##g')")"
if is_oneshot "$f"
then
if [ ! -e "$rd" ]
then
cp -av "$(get_drop_in "$f" "$rf")" "$rd"
fi
continue
fi
install_file "$(get_drop_in "$f" "$rf")" "$rd"
done
if command -v php &> /dev/null && ! command -v phive &> /dev/null
then
~/bin/install-phive
fi
if command -v phive &> /dev/null
then
(cd ~/bin; phive install) || true
fi
if ! [ -d ~/git/ssh_config ]
then
echo "Cloning SSH config..."
mkdir -p ~/git
git clone git@git.jacobi-bs.de:cfg/ssh_config.git ~/git/ssh_config
echo "Done."
fi
echo "Pulling SSH config..."
git -C ~/git/ssh_config pull
echo "Done."
echo "Installing SSH config..."
(cd ~/git/ssh_config; make install)
echo "Installed."