Subversion Repositories DevTools

Rev

Rev 1042 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1050 dpurdie 1
 
1038 dpurdie 2
#
3
#   Receive a file and save is locally
4
#   Script run by ssh to receive a compressed file and to save it
1050 dpurdie 5
#   Works in bash and dash
1038 dpurdie 6
#
7
#   Assumes that gzip output as stdin
8
#
9
#set -x
10
set -e
11
 
1050 dpurdie 12
error() {
1038 dpurdie 13
    echo ERROR: $*
14
    exit 1;
15
}
16
 
17
# User options
18
while getopts D arg ; do
19
    case $arg in
20
        D) set -x ;;
21
        *) error Unknown option: $arg ;;
22
    esac
23
done
24
shift $(($OPTIND - 1))
25
 
26
# User arguments
27
fname=${1:?Need file name}
28
 
29
dpkg="dpkg_archive"
30
[ -d $dpkg ] || error dpkg_archive not found
31
 
32
#
33
#   Names of working directories
34
#
35
metadir="$dpkg/.dpkg_archive"
36
tmpfile="$metadir/${fname}.NEWTMP"
37
newfile="$metadir/${fname}"
38
 
39
#
40
#   Create package metadata directory
41
#   Ensure its writable
42
mkdir -p "$metadir"
43
chmod u+w "$metadir"
44
 
45
#
46
#   unzip the file into a temp name
47
gunzip -c -d -- > "$tmpfile"
48
 
49
#
50
#   Now that the new file has arrived error free
51
#   Rename the temp file to the new file
52
#
53
 
54
chmod a+w "$newfile" || true
55
rm -f "$newfile"
56
mv "$tmpfile" "$newfile"
57
 
58
# Fix up permissions on the file and directory
59
chmod a-w "$newfile"
1042 dpurdie 60
chmod go-w "$metadir"
61
chmod a+rx "$metadir"
1038 dpurdie 62