1d46eeeefa14af91291f8aa1a335363539ccbb9d
[zsh.git] / .zsh / functions / udh
1 # -*- mode:sh -*-
2
3 SPECBASE=${HOME}/.dotfiles
4 CRONBASE=${HOME}/.crontabs
5
6 if [ "$ZDOTDIR" = "" ]; then
7 echo "Sorry, need to run within a configured zsh environment"
8 return
9 fi
10 mr update
11
12 # Now we check if we have something specific for this host, that we need
13 # to link into the homedir
14
15 typeset -a specdirs
16 specdirs=(
17 "${SPECBASE}/net:$DOMAIN"
18 "${SPECBASE}/host:$HOST"
19 "${SPECBASE}/sys:$OSNAME"
20 "${SPECBASE}/distri:$DISTRI"
21 "${SPECBASE}/user:$USER"
22 "${SPECBASE}/user:$SUDO_USER"
23 "${SPECBASE}/net:$DOMAIN/host:$HOST"
24 "${SPECBASE}/net:$DOMAIN/sys:$OSNAME"
25 "${SPECBASE}/net:$DOMAIN/distri:$DISTRI"
26 "${SPECBASE}/net:$DOMAIN/user:$USER"
27 "${SPECBASE}/net:$DOMAIN/user:$SUDO_USER"
28 "${SPECBASE}/net:$DOMAIN/host:$HOST/sys:$OSNAME"
29 "${SPECBASE}/net:$DOMAIN/host:$HOST/distri:$DISTRI"
30 "${SPECBASE}/net:$DOMAIN/host:$HOST/user:$USER"
31 "${SPECBASE}/net:$DOMAIN/host:$HOST/user:$SUDO_USER"
32 "${SPECBASE}/net:$DOMAIN/host:$HOST/sys:$OSNAME"
33 "${SPECBASE}/net:$DOMAIN/host:$HOST/sys:$OSNAME/distri:$DISTRI"
34 "${SPECBASE}/net:$DOMAIN/host:$HOST/sys:$OSNAME/user:$USER"
35 "${SPECBASE}/net:$DOMAIN/host:$HOST/sys:$OSNAME/user:$SUDO_USER"
36 "${SPECBASE}/host:$HOST/sys:$OSNAME"
37 "${SPECBASE}/host:$HOST/distri:$DISTRI"
38 "${SPECBASE}/host:$HOST/user:$USER"
39 "${SPECBASE}/host:$HOST/user:$SUDO_USER"
40 "${SPECBASE}/host:$HOST/sys:$OSNAME/distri:$DISTRI"
41 "${SPECBASE}/host:$HOST/sys:$OSNAME/user:$USER"
42 "${SPECBASE}/host:$HOST/sys:$OSNAME/user:$SUDO_USER"
43 )
44
45 typeset -a workdirs
46 for entry in $specdirs[@]; do
47 for file in ${entry}/**/*(N.); do
48 workdirs+=$file
49 done
50 done
51 typeset -U workdirs
52
53 # Now link stuff
54 for entry in $workdirs[@]; do
55 base=${entry:t}
56 dirn=${entry:h}
57 dirn=${dirn//$SPECBASE/}
58 dirn=${dirn//net:$DOMAIN/}
59 dirn=${dirn//host:$HOST/}
60 dirn=${dirn//sys:$OSNAME/}
61 dirn=${dirn//distri:$DISTRI/}
62 dirn=${dirn//user:$USER/}
63 dirn=${dirn//user:$SUDO_USER/}
64 dirn=${${(j:/:)dirn}//\/\/##/}
65 if [ -n "${dirn}" ]; then
66 mkdir -p "${HOME}/${dirn}"
67 if [ ! -L ${HOME}/${dirn}/${base} ]; then
68 echo "Linking ${entry} to ${HOME}/${dirn}"
69 ln -rs ${entry} ${HOME}/${dirn}
70 fi
71 else
72 if [ ! -L ${HOME}/${dirn}/${base} ]; then
73 echo "Linking ${entry} to ${HOME}/${dirn}"
74 ln -rs ${entry} ${HOME}/
75 fi
76 fi
77 done
78
79 if [ -f "${CRONBASE}/${HOST}.${DOMAIN}" ]; then
80 if ! old=${${(z)"$(crontab -l | md5sum)"}[1]}; then
81 echo "crontab disabled for users"
82 return
83 fi
84 new=${${(z)$(md5sum .crontabs/gkar.ganneff.de )}[1]}
85 if [ "${new}" != "${old}" ]; then
86 echo "Crontab changed, installing repository copy"
87 crontab "${CRONBASE}/${HOST}.${DOMAIN}"
88 fi
89 fi
90