3 source /a
/bin
/bash-bear-trap
/bash-bear
5 echo 1 >~
/.local
/conflink
11 Usage: ${0##*/} [OPTIONS]
12 Link or otherwise install configuration files.
14 -f For fast. Dont use lnf, use ln -sf. Good for updating existing files.
15 -v Verbose show all the files getting linked and whatnot.
30 lnf
() { /a
/exe
/lnf
"$@"; }
34 ##### begin command line parsing ########
36 # ensure we can handle args with spaces or empty.
37 ret
=0; getopt
-T || ret
=$?
38 [[ $ret == 4 ]] ||
{ echo "Install util-linux for enhanced getopt" >&2; exit 1; }
42 temp
=$
(getopt
-l help hvf
"$@") || usage
1
50 *) echo "$0: unexpected args: $*" >&2 ; usage
1 ;;
56 ##### end command line parsing ########
61 lnf
() { ln -sf "$@"; }
75 # If we make a link back to the root, we stop going deeper into subdir_files.
76 # This makes it so we can do subdir directories. eg
77 # /p/c/subdir_files/.config/gajim -> ../../gagim
79 # Also note, under filesystem/, symlinks are expanded.
85 targets
=( "$2"/!(.git|..|.|.
#*) )
87 for f
in "$1"/!(.git|..|.|.
#*); do
88 if [[ -d $f ]]; then targets
+=("$f"); fi
92 below
="$( readlink -f "$root/..
")"
93 for path
in "${targets[@]}"; do
95 fullpath
="$(readlink -f "$path")"
96 if [[ -f $path || $
(dirname "$fullpath") == "$below" ]]; then
97 m lnf
-T "$path" "$HOME/${path#$root/}"
98 elif [[ -d "$path" ]]; then
99 subdir-link-r
"$root" "$path"
105 common-file-setup
() {
106 local dir fs x f reload_systemd
107 local -a restart_services
109 # note, i ran chmod -R g-s on the filesystem dirs
110 # so i could keep permissions of secret files
113 if [[ -e $fs && $user =~ ^iank?$
]]; then
114 # we dont want t, instead c for checksum.
115 # That way we dont set times on directories.
117 # -A is acls, implies -p
118 cmd
=( s rsync
-rclgoDiSAX --chmod=Dg-s
--chown=root
:root
119 --exclude=/etc
/dovecot
/users
120 --exclude='/etc/exim4/passwd*'
121 --exclude='/etc/exim4/*.pem'
124 "${cmd[@]}" |
tee $tmpf
125 while read -r line
; do
128 etc
/prometheus
/rules
/iank.yml|etc
/prometheus
/prometheus.yml
)
131 if systemctl is-active prometheus
&>/dev
/null
; then
132 v s systemctl reload prometheus
137 etc
/systemd
/system
/*)
141 restart_services
+=(dnsmasq
)
143 etc
/systemd
/resolved.conf.d
/*)
144 restart_services
+=(systemd-resolved
)
147 # Previously did this with tar, but it doesn't
148 # update directory permissions.
150 # S = do spare files efficiently
152 # X = preserve extended attributes
157 if ! $fast && [[ -e $dir/subdir_files
]]; then
158 m subdir-link-r
$dir/subdir_files
160 local x
=( $dir/!(binds|subdir_files|filesystem|machine_specific|..|.|.
#*) )
161 (( ${#x[@]} >= 1 )) ||
continue
164 if $reload_systemd; then
165 v s systemctl daemon-reload
167 for service
in ${restart_services[@]}; do
168 if systemctl is-active
$service >/dev
/null
; then
169 v s systemctl restart
$service
175 all_dirs
=({/a
/bin
/ds
,/p
/c
}{,/machine_specific
/$HOSTNAME})
176 # note, we assume a group of hosts does not have the
177 # same name as a single host, which is no problem on our scale.
178 for x
in /p
/c
/machine_specific
/*.hosts
/a
/bin
/ds
/machine_specific
/*.hosts
; do
179 if grep -qxF $HOSTNAME $x; then all_dirs
+=( ${x%.hosts} ); fi
183 c_dirs
=(/a
/c
{,/machine_specific
/$HOSTNAME})
187 for t
in systemstatus epanicclean btrfsmaintstop dynamicipupdate
; do
188 f
=/etc
/systemd
/system
/$t.timer
190 v systemctl stop
$t.timer
191 v systemctl disable
$t.timer
197 if [[ -e /etc
/cron.daily
/check-lets-encrypt-ssl-settings
]]; then
198 m s
rm -f /etc
/cron.daily
/check-lets-encrypt-ssl-settings
200 # conversion from whole folder subdir to individual files.
201 if [[ -L /home
/iank
/.config
/copyq
]]; then
202 rm -fv /home
/iank
/.config
/copyq
205 /a
/bin
/ds
/install-my-scripts
206 files
=(/p
/c
/machine_specific
/*/filesystem
/etc
/ssh
/*_key
207 /p
/c
/machine_specific
/*/filesystem
/etc
/openvpn
/client
/*.key
208 /p
/c
/filesystem
/etc
/openvpn
/client
/*.key
209 /p
/c
/filesystem
/etc
/openvpn
/easy-rsa
/keys
/*.key
211 if [[ -e ${files[0]} ]]; then
212 chmod 600 ${files[@]}
214 # p needs to go first so .ssh link is created, then config link inside it
215 m common-file-setup
${all_dirs[@]}
217 #### begin special extra stuff ####
218 install -d -m700 ~
/gpg-agent-socket
222 # reset to the original permissions.
226 s bash
-c 'shopt -s nullglob; for f in /etc/bind/*.key /etc/bind/*.private /etc/bind/key.*; do chgrp bind $f; done'
227 if [[ -e /etc
/caldav-htpasswd
]] && getent group www-data
&>/dev
/null
; then
228 s chgrp www-data
/etc
/caldav-htpasswd
230 if [[ -e /var
/lib
/znc
]] && getent group znc
; then
231 s chown
-R znc
:znc
/var
/lib
/znc
233 if [[ -e /p
/c
/user-specific
]]; then
234 if getent passwd prometheus
&>/dev
/null
; then
235 v s rsync
-clpgoDiSAX --chmod=Dg-s
--chown=root
:prometheus
/p
/c
/user-specific
/prometheus
/prometheus-pass
/etc
236 v s rsync
-clpgoDiSAX --chmod=Dg-s
--chown=root
:prometheus
/p
/c
/user-specific
/prometheus
/prometheus
/ssl
/* /etc
/prometheus
/ssl
238 if getent passwd www-data
&>/dev
/null
; then
239 v s rsync
-clpgoDiSAX --chmod=Dg-s
--chown=root
:www-data
/p
/c
/user-specific
/www-data
/* /etc
243 if [[ -d /var
/lib
/bitcoind
&& -d /p
/c
/user-specific
/bitcoin
]]; then
244 s rsync
-clpgoDiSAX --chmod=Dg-s
--chown=bitcoin
:bitcoin
/p
/c
/user-specific
/bitcoin
/settings.json
/var
/lib
/bitcoind
245 s rsync
-rclpgoDiSAX --chmod=Dg-s
--chown=root
:bitcoin
/p
/c
/user-specific
/bitcoin
/bitcoin
/etc
247 ##### end special extra stuff #####
250 m s
-H -u user2
"${BASH_SOURCE[0]}"
253 f
=/a
/bin
/distro-setup
/system-status
258 echo 0 >~
/.local
/conflink
262 m common-file-setup
${c_dirs[@]}
265 echo "$0: error: unexpected user"; exit 1