spk view spk-archive @ rev 40
Better modifiers and rdeps handler in spk-rm and fixes
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Wed May 16 02:32:22 2012 +0200 (2012-05-16) |
parents | bb5a37f13ad6 |
children | 07f5864f07a2 |
line source
1 #!/bin/bash
2 #
3 # Spk-Archive - SliTaz Package Archive Manager
4 #
5 # NOT COMPLETE: Still need to re-write (just what was grabbed from tazpkg)
6 # UNSURE: Should Pack and Repack be here?
7 #
8 # Authors : See the AUTHORS files
10 source /usr/lib/slitaz/libspk.sh
12 usage() {
13 name=$(basename $0)
14 cat << EOT
16 $(boldify $(gettext "Usage:")) $name [command] package
18 $(boldify $(gettext "Commands:"))
19 pack
20 repack [--config]
21 extract
22 recompress
24 $(boldify "$(gettext "Example:")")
25 $name extract clex
27 EOT
28 exit 0
29 }
31 # Extract a package with cpio and gzip/lzma to the current directory.
32 # Parameters: package_file
33 extract_package() {
34 local package_file=$1
35 local package_name=$(package_name $package_file)
37 eval_gettext "Extracting \$package_name... "
38 cpio -idm --quiet < ${package_file##*/} && rm -f ${package_file##*/}
39 status
41 gettext "Extracting the pseudo fs... "
42 unlzma -c fs.cpio.lzma | cpio -idm --quiet && rm fs.cpio.lzma
43 status
44 }
46 # Extract .tazpkg cpio archive into a directory.
47 # Parameters: package_file results_directory
48 extract() {
49 local package_file=$1
50 local target_dir=$2
52 # validate the file
53 check_valid_tazpkg $package_file
55 # find the package name
56 local package_name=$(package_name $package_file)
58 # Create destination directory
59 local dest_dir=$(pwd)/$package_name
60 [ -n "$target_dir" ] && dest_dir=$target_dir/$package_name
61 mkdir -p $dest_dir
63 newline
64 echo $(boldify $(gettext "Extracting:")) $package_name
65 separator
67 gettext "Copying original package..."
68 cp $package_file $dest_dir
69 status
70 pushd $dest_dir > /dev/null
71 extract_package $package $package_file
72 popd > /dev/null
73 separator
74 eval_gettext "\$package_name is extracted to: \$dest_dir"; newline
75 newline
76 }
78 # Recompress .tazpkg cpio archive with lzma.
79 # Parameters: package_file
80 recompress() {
81 local package_file=$1
82 valid_tazpkg $package_file
84 local package_name=$(package_name $package_file)
86 newline
87 echo $(boldify $(gettext "Recompressing:")) $package_name
88 separator
90 mkdir -p $TMP_DIR
92 gettext "Copying original package..."
93 cp $package_file $TMP_DIR
94 status
96 pushd $TMP_DIR > /dev/null
97 extract_package $package_file
99 gettext "Recompressing the fs... "
100 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
101 rm -rf fs
102 status
103 popd > /dev/null
105 gettext "Creating new package... "
106 find $TMP_DIR -print | cpio -o -H newc --quiet > \
107 $(basename $package_file).$$ && mv -f \
108 $(basename $package_file).$$ \
109 $(basename $package_file)
110 status
112 rm -rf $TMP_DIR
113 }
115 # Create SliTaz package archive from an installed package.
116 # Parameters: package
117 repack() {
118 local package=$1
119 unset EXTRAVERSION
120 source $INSTALLED/$package/receipt
121 newline
122 echo -e "$(bold Repacking :) $PACKAGE-$VERSION$EXTRAVERSION.tazpkg"
123 separator
124 if grep -qs ^NO_REPACK= $INSTALLED/$PACKAGE/receipt; then
125 eval_gettext "Can't repack \$PACKAGE"; newline
126 exit 1
127 fi
128 if [ -s $INSTALLED/$PACKAGE/modifiers ]; then
129 eval_gettext "Can't repack, \$PACKAGE files have been modified by:"; newline
130 for i in $(cat $INSTALLED/$PACKAGE/modifiers); do
131 echo " $i"
132 done
133 exit 1
134 fi
135 unset MISSING
136 while read i; do
137 [ -e "$i" ] && continue
138 [ -L "$i" ] || MISSING="$MISSING\n $i"
139 done < $INSTALLED/$PACKAGE/files.list
140 if [ -n "$MISSING" ]; then
141 gettext "Can't repack, the following files are lost:"
142 echo -e "$MISSING"
143 exit 1
144 fi
145 mkdir -p $TMP_DIR
146 pushd $TMP_DIR > /dev/null
147 FILES="fs.cpio.lzma\n"
148 for i in $(ls $INSTALLED/$PACKAGE) ; do
149 [ "$i" = "volatile.cpio.gz" ] && continue
150 [ "$i" = "modifiers" ] && continue
151 cp $INSTALLED/$PACKAGE/$i . && FILES="$FILES$i\n"
152 done
153 ln -s / rootfs
154 mkdir tmp
155 sed 's/^/rootfs/' < files.list | cpio -o -H newc --quiet |\
156 { cd tmp ; cpio -idm --quiet >/dev/null; cd ..; }
157 mv tmp/rootfs fs
158 if [ -f $INSTALLED/$PACKAGE/volatile.cpio.gz ]; then
159 zcat $INSTALLED/$PACKAGE/volatile.cpio.gz | \
160 { cd fs; cpio -idm --quiet; cd ..; }
161 fi
162 if fgrep -q repack_cleanup $INSTALLED/$PACKAGE/receipt; then
163 . $INSTALLED/$PACKAGE/receipt
164 repack_cleanup fs
165 fi
166 if [ -f $INSTALLED/$PACKAGE/$CHECKSUM ]; then
167 sed 's, , fs,' < $INSTALLED/$PACKAGE/$CHECKSUM | \
168 $CHECKSUM -s -c || {
169 gettext "Can't repack, $CHECKSUM error."; newline
170 popd
171 rm -rf $TMP_DIR
172 exit 1
173 }
174 fi
175 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
176 echo -e "$FILES" | cpio -o -H newc --quiet > $PACKAGE-$VERSION$EXTRAVERSION.tazpkg
177 popd > /dev/null
178 mv $TMP_DIR/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg .
179 rm -R $TMP_DIR
180 eval_gettext "Package \$PACKAGE repacked successfully."; newline
181 echo $(gettext "Size") : $(du -sh $PACKAGE-$VERSION$EXTRAVERSION.tazpkg)
182 newline
183 }
185 # Create SliTaz package archive from configuration files.
186 repack_config() {
187 mkdir -p $TMP_DIR
188 pushd $TMP_DIR > /dev/null
189 CONFIG_VERSION=1.0
190 mkdir config-$CONFIG_VERSION
191 pushd config-$CONFIG_VERSION
192 for i in $INSTALLED/*/volatile.cpio.gz; do
193 zcat $i | cpio -t --quiet
194 done > files.list
195 mkdir fs
196 pushd fs
197 ( cd / ; cpio -o -H newc --quiet ) < ../files.list | cpio -idm --quiet > /dev/null
198 mkdir -p etc/tazlito
199 for i in $INSTALLED/*/receipt; do
200 unset EXTRAVERSION
201 source $i
202 echo "$PACKAGE-$VERSION$EXTRAVERSION"
203 done > etc/tazlito/config-packages.list
204 popd > /dev/null
205 echo "etc/tazlito/config-packages.list" >> files.list
206 cat > receipt <<EOT
207 # SliTaz package receipt.
209 PACKAGE="config"
210 VERSION="$CONFIG_VERSION"
211 CATEGORY="base-system"
212 SHORT_DESC="$(gettext "User configuration backup on ")$(date)"
213 DEPENDS="$(ls $INSTALLED)"
214 EOT
215 popd
216 tazpkg pack config-$CONFIG_VERSION
217 popd
218 cp $TMP_DIR/config-$CONFIG_VERSION.tazpkg .
219 rm -rf $TMP_DIR
220 }
222 # Create SliTaz package archive using cpio and gzip.
223 # Parameters: package
224 pack() {
225 local package="$1"
226 cd $PACKAGE
227 if [ ! -f "receipt" ]; then
228 gettext "Receipt is missing. Please read the documentation."; newline
229 exit 0
230 else
231 newline
232 echo "$(bold Packing :) $PACKAGE"
233 separator
234 # Create files.list with redirecting find outpout.
235 gettext "Creating the list of files..."
236 pushd fs
237 find . -type f -print > ../files.list
238 find . -type l -print >> ../files.list
239 popd
240 sed -i s/'^.'/''/ files.list
241 status
242 gettext "Creating $CHECKSUM of files..."
243 while read file; do
244 [ -L "fs$file" ] && continue
245 [ -f "fs$file" ] || continue
246 case "$file" in
247 /lib/modules/*/modules.*|*.pyc) continue;;
248 esac
249 $CHECKSUM "fs$file" | sed 's/ fs/ /'
250 done < files.list > $CHECKSUM
251 status
252 UNPACKED_SIZE=$(du -chs fs receipt files.list $CHECKSUM \
253 description.txt 2> /dev/null | busybox awk \
254 '{ sz=$1 } END { print sz }')
255 # Build cpio archives.
256 gettext "Compressing the fs... "
257 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
258 rm -rf fs
259 status
260 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
261 $CHECKSUM description.txt 2> /dev/null | busybox awk \
262 '{ sz=$1 } END { print sz }')
263 gettext "Updating receipt sizes..."
264 sed -i s/^PACKED_SIZE.*$// receipt
265 sed -i s/^UNPACKED_SIZE.*$// receipt
266 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
267 status
268 gettext "Creating full cpio archive... "
269 find . -print | cpio -o -H newc --quiet > ../$PACKAGE.tazpkg
270 status
271 gettext "Restoring original package tree... "
272 unlzma -c fs.cpio.lzma | cpio -idm --quiet
273 status
274 rm fs.cpio.lzma && cd ..
275 separator
276 eval_gettext "Package \$PACKAGE compressed successfully."; newline
277 echo $(gettext "Size") : $(du -sh $PACKAGE.tazpkg)
278 newline
279 fi
280 }
282 case $1 in
283 pack|-p)
284 pack $2 ;;
285 extract|-e)
286 extract_package $2 $3 ;;
287 recompress|-r)
288 recompress $2 ;;
289 *)
290 usage ;;
291 esac