spk view spk-archive @ rev 64

spk-archive: be busybox ash compatible
author Christophe Lincoln <pankso@slitaz.org>
date Fri May 18 03:19:51 2012 +0200 (2012-05-18)
parents 07f5864f07a2
children de880358af6d
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)
36 gettext "Extracting:"; echo " $package_name... "
37 cpio -idm --quiet < ${package_file##*/} && rm -f ${package_file##*/}
38 status
40 [ "$verbose" ] && gettext "Extracting the pseudo fs... "
41 unlzma -c fs.cpio.lzma | cpio -idm --quiet && rm fs.cpio.lzma
42 [ "$verbose" ] && status
43 }
45 # Extract .tazpkg cpio archive into a directory.
46 # Parameters: package_file results_directory
47 extract() {
48 local package_file=$1
49 local target_dir=$2
51 # Validate the file
52 check_valid_tazpkg $package_file
54 # Find the package name
55 local package_name=$(package_name $package_file)
57 # Create destination directory
58 local dest_dir=$(pwd)/$package_name
59 [ -n "$target_dir" ] && dest_dir=$target_dir/$package_name
60 mkdir -p $dest_dir
62 newline
63 echo $(boldify $(gettext "Extracting:")) $package_name
64 separator
66 gettext "Copying original package..."
67 cp $package_file $dest_dir
68 status
69 cd $dest_dir
70 extract_package $package $package_file
71 cd - > /dev/null
72 separator
73 echo -n "$package_name"
74 gettext "is extracted to:"; echo " $dest_dir"
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 cd $TMP_DIR
97 extract_package $package_file
98 gettext "Recompressing the fs..."
99 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
100 rm -rf fs
101 status
102 cd - > /dev/null
104 gettext "Creating new package..."
105 find $TMP_DIR -print | cpio -o -H newc --quiet > \
106 $(basename $package_file).$$ && mv -f \
107 $(basename $package_file).$$ \
108 $(basename $package_file)
109 status
111 rm -rf $TMP_DIR
112 }
114 case $1 in
115 extract|-e)
116 extract_package $2 $3 ;;
117 recompress|-r)
118 recompress $2 ;;
119 *)
120 usage ;;
121 esac