ignore compiled files
[zsh.git] / .zsh / functions / udh
1 # -*- mode:sh -*-
2
3 local SPECBASE=${HOME}/.dotfiles
4 local CRONBASE=${HOME}/.crontabs
5
6 if [ "$ZDOTDIR" = "" ]; then
7 echo "Sorry, need to run within a configured zsh environment"
8 return
9 fi
10 cd ${HOME}
11 mr update
12
13 # Now we check if we have something specific for this host, that we need
14 # to link into the homedir
15
16 typeset -a specdirs
17 specdirs=(
18 # "${SPECBASE}/net:$DOMAIN"
19 # "${SPECBASE}/host:$HOST"
20 # "${SPECBASE}/sys:$OSNAME"
21 # "${SPECBASE}/distri:$DISTRI"
22 # "${SPECBASE}/user:$USER"
23 # "${SPECBASE}/user:$SUDO_USER"
24 "${SPECBASE}/net:$DOMAIN/host:$HOST"
25 "${SPECBASE}/net:$DOMAIN/sys:$OSNAME"
26 "${SPECBASE}/net:$DOMAIN/distri:$DISTRI"
27 "${SPECBASE}/net:$DOMAIN/user:$USER"
28 "${SPECBASE}/net:$DOMAIN/user:$SUDO_USER"
29 "${SPECBASE}/net:$DOMAIN/host:$HOST/sys:$OSNAME"
30 "${SPECBASE}/net:$DOMAIN/host:$HOST/distri:$DISTRI"
31 "${SPECBASE}/net:$DOMAIN/host:$HOST/user:$USER"
32 "${SPECBASE}/net:$DOMAIN/host:$HOST/user:$SUDO_USER"
33 "${SPECBASE}/net:$DOMAIN/host:$HOST/sys:$OSNAME"
34 "${SPECBASE}/net:$DOMAIN/host:$HOST/sys:$OSNAME/distri:$DISTRI"
35 "${SPECBASE}/net:$DOMAIN/host:$HOST/sys:$OSNAME/user:$USER"
36 "${SPECBASE}/net:$DOMAIN/host:$HOST/sys:$OSNAME/user:$SUDO_USER"
37 "${SPECBASE}/host:$HOST/sys:$OSNAME"
38 "${SPECBASE}/host:$HOST/distri:$DISTRI"
39 "${SPECBASE}/host:$HOST/user:$USER"
40 "${SPECBASE}/host:$HOST/user:$SUDO_USER"
41 "${SPECBASE}/host:$HOST/sys:$OSNAME/distri:$DISTRI"
42 "${SPECBASE}/host:$HOST/sys:$OSNAME/user:$USER"
43 "${SPECBASE}/host:$HOST/sys:$OSNAME/user:$SUDO_USER"
44 )
45
46 typeset -a workdirs
47 for entry in $specdirs[@]; do
48 for file in ${entry}/**/*(N.); do
49 workdirs+=$file
50 done
51 done
52 typeset -U workdirs
53
54 # Now link stuff
55 echo "Checking host files..."
56 for entry in $workdirs[@]; do
57 base=${entry:t}
58 dirn=${entry:h}
59 dirn=${dirn//$SPECBASE/}
60 dirn=${dirn//net:$DOMAIN/}
61 dirn=${dirn//host:$HOST/}
62 dirn=${dirn//sys:$OSNAME/}
63 dirn=${dirn//distri:$DISTRI/}
64 dirn=${dirn//user:$USER/}
65 dirn=${dirn//user:$SUDO_USER/}
66 # dirn=${${(j:/:)dirn}//\/\/##/}
67 # dirn=${${(j:/:)dirn}//\/##/}
68
69 echo "... ${HOME}/${dirn}/${base}"
70
71 if [ -f "${HOME}/${dirn}/${base}" ] || [ -L "${HOME}/${dirn}/${base}" ]; then
72 linktarget=$(readlink -f "${HOME}/${dirn}/${base}")
73 if ! [[ $linktarget =~ .dotfiles ]] || [ -z "${linktarget}" ]; then
74 answer=N
75 echo "File exists. ${HOME}/${dirn}/${base} (is ${linktarget})"
76 vared -p 'Overwrite with symlink to ${entry}?: [y/N] ' answer
77 case ${answer} in
78 y|Y)
79 rm -f "${HOME}/${dirn}/${base}"
80 ;;
81 *)
82 echo "Not overwriting ${linktarget}"
83 continue
84 ;;
85 esac
86 fi
87 fi
88
89 if ln --help 2>/dev/null | grep -- --relative >/dev/null; then
90 LNOPTS="-r"
91 fi
92
93 if [ -n "${dirn}" ]; then
94 mkdir -p "${HOME}/${dirn}"
95 if [ ! -L ${HOME}/${dirn}/${base} ]; then
96 echo "Linking ${entry} to ${HOME}/${dirn}/${base}"
97 /bin/ln -s $LNOPTS ${entry} ${HOME}/${dirn}
98 fi
99 else
100 if [ ! -L ${HOME}/${dirn}/${base} ]; then
101 echo "Linking ${entry} to ${HOME}/${dirn}"
102 /bin/ln -s $LNOPTS ${entry} ${HOME}/${base}
103 fi
104 fi
105 done
106
107 if [ -f "${CRONBASE}/${HOST}.${DOMAIN}" ]; then
108 if ! old=${${(z)"$(crontab -l | md5sum)"}[1]}; then
109 echo "crontab disabled for users"
110 return
111 fi
112 new=${${(z)$(md5sum "${CRONBASE}/${HOST}.${DOMAIN}" )}[1]}
113 if [ "${new}" != "${old}" ]; then
114 echo "Crontab changed, installing repository copy"
115 crontab "${CRONBASE}/${HOST}.${DOMAIN}"
116 fi
117 fi
118