* updated kmailtransport (21.12.1 -> 21.12.2), untested
[t2-trunk.git] / package / archiver / bize / bize.sh
blobdcfc8cb02ab8b7820e1d379710f385bddd7c05f8
1 #!/bin/sh
2 # --- T2-COPYRIGHT-NOTE-BEGIN ---
3 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
4 #
5 # T2 SDE: package/.../bize/bize.sh
6 # Copyright (C) 2004 - 2005 The T2 SDE Project
7 #
8 # More information can be found in the files COPYING and README.
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; version 2 of the License. A copy of the
13 # GNU General Public License can be found in the file COPYING.
14 # --- T2-COPYRIGHT-NOTE-END ---
16 bize_usage()
18 echo "usage: bize -i [-t] [-v] [-f] [-R root] package1.tar.bz2 ..." 1>&2
19 echo " bize -r [-t] [-v] [-f] [-R root] package1 ..." 1>&2
22 bize_remove()
24 local line base tag md5s="$adm/md5sums/$pkg"
26 if [ "$keep" ] ; then
27 if [ ! -f "$md5s" ] ; then
28 echo "$0: $md5s: no such file, skipping remove" 1>&2
29 return
32 (cd "$root/" && md5sum -c "var/adm/md5sums/$pkg" 2> /dev/null) |
33 while read line ; do
34 base="${line%: *}"
35 stat="${line##*: }"
36 file="$root/$base"
37 if [ -z "$base" -o -z "$stat" ] ; then
38 echo "$0: invalid md5sum output '$line'" 1>&2
39 elif [ -f "$file" -a ! -L "$file" ] ; then
40 if [ "$stat" = OK ] ; then
41 $unlink "$file"
42 elif [ "$stat" != FAILED ] ; then
43 echo "$0: $file: $stat"
44 elif [ "$test" ] ; then
45 echo "$0: $file: modified, skipping"
48 done
51 sort -r "$list" | while read tag base ; do
52 file="$root/$base"
53 if [ "$tag" != "$pkg:" ] ; then
54 echo "$0: invalid tag '$tag' in $list" 1>&2
55 elif [ -z "$base" ] ; then
56 echo "$0: missing file name in $list" 1>&2
57 elif [ -L "$file" ] ; then
58 $unlink "$file"
59 elif [ -d "$file" ] ; then
60 $test rmdir $voption "$file"
61 elif [ "${base#var/adm/}" != "$base" -a -f "$file" ] ; then
62 $unlink "$file"
63 elif [ "$keep" -a -f "$file" ] ; then
64 [ "$test" ] || echo "$0: $file: modified, skipping"
65 else
66 $unlink "$file"
68 done
71 bize_install()
73 if [ ! -f "$arch" ] ; then
74 echo "$0: $arch: no such file, skipping install" 1>&2
75 return
78 pkg="${arch%.tar.bz2}"
79 if [ "$arch" = "$pkg" ] ; then
80 echo "$0: $arch: not a .tar.bz2 file" 1>&2
81 return
83 pkg="${pkg%-[0-9]*}"
84 pkg="${pkg##*/}"
86 if [ -z "$pkg" ] ; then
87 echo "$0: $arch: missing package name" 1>&2
88 return
90 [ "${arch#-}" = "$arch" ] || arch="./$arch"
92 list="$adm/flists/$pkg"
93 if [ -f "$list" ] ; then
94 [ "$verbose" ] && echo "updating $pkg ..."
95 bize_remove
96 else
97 [ "$verbose" ] && echo "installing $pkg ..."
100 $test mkdir -p$verbose "$root/"
101 if [ "$test" ] ; then
102 echo "bzip2 -c -d $arch | tar $taropt -C $root/"
103 else
104 bzip2 -c -d "$arch" | tar $taropt -C "$root/"
108 bize_uninstall()
110 [ "$verbose" ] && echo "removing $pkg"
111 list="$adm/flists/$pkg"
112 if [ -f "$list" ] ; then
113 bize_remove
114 else
115 echo "$0: $list: no such file, skipping remove" 1>&2
119 bize_main()
121 local which=which file arch list="sort rm rmdir mkdir tar bzip2"
122 local install remove test verbose voption keep=k root=/ taropt
124 while [ "$1" ] ; do
125 case "$1" in
126 -i) install=1 ;;
127 -r) remove=1 ;;
128 -t) test=echo ;;
129 -f) keep="" ;;
130 -v) verbose=v ; voption=-v ;;
131 -R) shift ; root="$1" ;;
132 -R*) root="${1#-R}" ;;
133 --) break ;;
134 -*) bize_usage ; return 1 ;;
135 *) break;;
136 esac
137 shift
138 done
140 if type sh > /dev/null 2>&1 ; then
141 which=type
142 elif ! which sh > /dev/null ; then
143 echo "$0: unable to find 'type' or 'which'" 1>&2
144 return 1
147 [ "$keep" ] && list="$list md5sum"
148 for file in $list ; do
149 if ! $which $file > /dev/null ; then
150 echo "$0: unable to find '$file'" 1>&2
151 return 1
153 done
155 if [ "$install" = "$remove" -o -z "$root" -o -z "$*" ] ; then
156 bize_usage
157 return 1
160 root="${root%/}"
161 [ "${root#-}" = "$root" ] || root="./$root"
163 local adm="$root/var/adm" unlink="$test rm -f$verbose" pkg
165 if [ "$install" ] ; then
166 taropt="xp${verbose}${keep}"
167 for arch do
168 bize_install
169 done
170 else
171 for pkg do
172 bize_uninstall
173 done
176 return 0
179 bize_main "$@"