spk view spk-archive @ rev 65

Less verbose on extract but show package size, add comments to download() and enbale --quiet mode
author Christophe Lincoln <pankso@slitaz.org>
date Fri May 18 03:48:08 2012 +0200 (2012-05-18)
parents fb6acdd2617c
children 63fb720dc777
line source
1 #!/bin/sh
2 #
3 # Spk-Archive - SliTaz Package Archive Manager
4 #
5 # NOT COMPLETE: Still need to re-write (just what was grabbed from tazpkg)
6 #
7 # Authors : See the AUTHORS files
9 source /usr/lib/slitaz/libspk.sh
11 usage() {
12 name=$(basename $0)
13 cat << EOT
15 $(boldify $(gettext "Usage:")) $name [command] package
17 $(boldify $(gettext "Commands:"))
18 pack
19 repack [--config]
20 extract
21 recompress
23 $(boldify "$(gettext "Example:")")
24 $name extract package
26 EOT
27 exit 0
28 }
30 # Extract a package with cpio and gzip/lzma to the current directory.
31 # Parameters: package_file
32 extract_package() {
33 local package_file=$1
34 local package_name=$(package_name $package_file)
35 local size=$(du -sh $package_file | awk '{print $1}')
36 gettext "Extracting"; echo -n " $package_name: $size"
37 cpio -idm --quiet < ${package_file##*/} && rm -f ${package_file##*/}
38 unlzma -c fs.cpio.lzma | cpio -idm --quiet && rm fs.cpio.lzma
39 status
40 }
42 # Extract .tazpkg cpio archive into a directory.
43 # Parameters: package_file results_directory
44 extract() {
45 local package_file=$1
46 local target_dir=$2
48 # Validate the file
49 check_valid_tazpkg $package_file
51 # Find the package name
52 local package_name=$(package_name $package_file)
54 # Create destination directory
55 local dest_dir=$(pwd)/$package_name
56 [ -n "$target_dir" ] && dest_dir=$target_dir/$package_name
57 mkdir -p $dest_dir
59 newline
60 echo $(boldify $(gettext "Extracting:")) $package_name
61 separator
63 gettext "Copying original package..."
64 cp $package_file $dest_dir
65 status
66 cd $dest_dir
67 extract_package $package $package_file
68 cd - > /dev/null
69 separator
70 echo -n "$package_name"
71 gettext "is extracted to:"; echo " $dest_dir"
72 newline
73 }
75 # Recompress .tazpkg cpio archive with lzma.
76 # Parameters: package_file
77 recompress() {
78 local package_file=$1
79 valid_tazpkg $package_file
81 local package_name=$(package_name $package_file)
83 newline
84 echo $(boldify $(gettext "Recompressing:")) $package_name
85 separator
87 mkdir -p $TMP_DIR
89 gettext "Copying original package..."
90 cp $package_file $TMP_DIR
91 status
93 cd $TMP_DIR
94 extract_package $package_file
95 gettext "Recompressing the fs..."
96 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
97 rm -rf fs
98 status
99 cd - > /dev/null
101 gettext "Creating new package..."
102 find $TMP_DIR -print | cpio -o -H newc --quiet > \
103 $(basename $package_file).$$ && mv -f \
104 $(basename $package_file).$$ \
105 $(basename $package_file)
106 status
108 rm -rf $TMP_DIR
109 }
111 case $1 in
112 extract|-e)
113 extract_package $2 $3 ;;
114 recompress|-r)
115 recompress $2 ;;
116 *)
117 usage ;;
118 esac