2 # No way I try to deal with a crippled sh just for POSIX foo.
4 # Copyright (C) 2011 Joerg Jaspert <joerg@debian.org>
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation; version 2.
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 # Homer: Are you saying you're never going to eat any animal again? What
25 # Lisa: Dad, those all come from the same animal.
26 # Homer: Heh heh heh. Ooh, yeah, right, Lisa. A wonderful, magical animal.
28 # Let files inside morgue be symlinks to the snapshot farm
32 # make sure to only use defined variables
34 # ERR traps should be inherited from functions too. (And command
35 # substitutions and subshells and whatnot, but for us the functions is
36 # the important part here)
39 # Make sure we start out with a sane umask setting
42 # And use one locale, no matter what the caller has set
46 # log something (basically echo it together with a timestamp)
47 # Set $PROGRAM to a string to have it added to the output.
49 local prefix=${PROGRAM:-$0}
50 echo "$(date +"%b %d %H:%M:%S") $(hostname -s) ${prefix}[$$]: $@"
53 PROCESSDIR="/srv/morgue.debian.org"
54 FARMBASE="/srv/snapshot.debian.org/farm"
57 log "Processing ${PROCESSDIR}"
58 find ${PROCESSDIR} -type f |
60 # Get the files sha1sum
61 mshasum=$(sha1sum ${mfile})
62 mshasum=${mshasum%% *}
63 # And now get the "levels" of the farm
64 if [[ ${mshasum} =~ ([0-9a-z][0-9a-z])([0-9a-z][0-9a-z]).* ]]; then
65 LVL1=${BASH_REMATCH[1]}
66 LVL2=${BASH_REMATCH[2]}
68 log "Ups, unknown error in regex for ${mfile} (${mshasum})"
72 # See if we have a target
73 if [ -f "${FARMBASE}/${LVL1}/${LVL2}/${mshasum}" ]; then
74 # Yes, lets symlink it
75 log "Symlinking ${mfile} to ${FARMBASE}/${LVL1}/${LVL2}/${mshasum}"
76 ln -sf "${FARMBASE}/${LVL1}/${LVL2}/${mshasum}" "${mfile}"
79 log "No symlink target for ${mfile}"
81 done # mfile read mfile