blob: 44416192ef26974cea1b5085f37c88b5a2213a75 (
plain)
1 #!/bin/sh
2 # httpup-repgen - One way sync from an http server to a local directory
3 #
4 # Copyright 2003-2005 (c) Johannes Winkelmann, # jw@tks6.net
5 #
6 # - Filtering code adapted from Per Liden's pkgmk
7 # - optimized and made portable (sh-compliant) by Han Boetes
8
9
10 # The repo file is place on the server. httpup downloads it,
11 # makes the update and afterwards moves it to the REPOCURRENTFILE
12 # which keeps track of the files which have been checked out. The
13 # REPOCURRENTFILE contains only file names
14 REPOFILE=REPO
15 REPOCURRENTFILE=REPO.CURRENT
16
17 VERSION=0.8
18
19 info()
20 {
21 echo $*
22 }
23
24 debug()
25 {
26 return # echo $*
27 }
28
29 printUsage()
30 {
31 cat << EOF
32 httpup-repgen $VERSION
33 Copyright (c) 2003 Johannes Winkelmann
34
35 Usage:
36 httpup-repgen [directory]
37 EOF
38 exit -1
39 }
40
41 generateRepoFile()
42 {
43 dir=${1:-.}
44 if [ ! -d $dir ]; then
45 echo "Can't generate repository for '$dir': No such directory"
46 exit -2
47 fi
48 echo "Generating repository for directory '$dir'"
49
50 OLDPWD=$PWD
51 cd $dir
52 rm -f $REPOFILE || exit -3
53
54 IGNORE_FILE=.httpup-repgen-ignore
55 if [ -r $HOME/$IGNORE_FILE ]; then
56 FILTER="grep -E -v -f $HOME/$IGNORE_FILE"
57 else
58 FILTER="cat"
59 fi
60 if [ -r $IGNORE_FILE ]; then
61 FILTER_LOCAL="grep -E -v -f $IGNORE_FILE"
62 else
63 FILTER_LOCAL="cat"
64 fi
65 FILTER_OWN="egrep -v ($REPOFILE|$REPOCURRENTFILE|$IGNORE_FILE)"
66
67 find . -type d ! -name . -printf "%P\n"|$FILTER|$FILTER_LOCAL|$FILTER_OWN|\
68 awk '{print "d:"$1}' > $REPOFILE
69 files="$(find . -type f -printf "%P\n"|$FILTER|$FILTER_LOCAL|$FILTER_OWN)"
70 if [ -n "$files" ]; then
71 echo $files|xargs md5sum|awk '{print "f:"$1":"$2}' >> $REPOFILE
72 fi
73
74 cd $OLDPWD
75 }
76
77 case $1 in
78 -*)
79 printUsage
80 ;;
81 *)
82 generateRepoFile $1
83 ;;
84 esac
|