slitaz-tools view oldstuff/tazfile @ rev 625

Gettextize setmixer and make pot
author Christophe Lincoln <pankso@slitaz.org>
date Tue Jun 14 22:47:24 2011 +0200 (2011-06-14)
parents 7e8f98aac2f9
children
line source
1 #!/bin/sh
2 # Tazfile - Tiny autonomus zone files locator.
3 #
4 # This is a lightweight files locator for *.tazpkg files written in
5 # SHell script. It works well with Busybox ash shell and bash. Tazfile lets you
6 # create and explore a files list database.
7 #
8 # (C) 2008 SliTaz - GNU General Public License v3.
9 #
10 # Author : Pascal Bellard <pascal.bellard@slitaz.org>
11 #
12 VERSION=1.0
14 ####################
15 # Script variables #
16 ####################
18 # Initialize some variables to use words
19 # rather than numbers for functions and actions.
20 COMMAND=$1
21 TOP_DIR=`pwd`
22 TMP_DIR=/tmp/tazfile-$$-$RANDOM
24 # Path to tazpkg used dir and configuration files
25 LOCALSTATE=/var/lib/tazpkg
26 INSTALLED=$LOCALSTATE/installed
27 MIRROR=$LOCALSTATE/mirror
28 FILES_LIST=$LOCALSTATE/files.list.lzma
29 DEFAULT_MIRROR="http://download.tuxfamily.org/slitaz/packages/`cat /etc/slitaz-release`/"
31 # Check if the directories and files used by Tazfile
32 # exist. If not and user is root we create them.
33 if test $(id -u) = 0 ; then
34 if [ ! -d "$INSTALLED" ]; then
35 mkdir -p $INSTALLED
36 fi
37 if [ ! -f "$LOCALSTATE/mirror" ]; then
38 echo "$DEFAULT_MIRROR" > $LOCALSTATE/mirror
39 fi
40 fi
42 ####################
43 # Script functions #
44 ####################
46 # Print the usage.
47 usage ()
48 {
49 echo -e "SliTaz files locator - Version: $VERSION\n
50 \033[1mUsage:\033[0m tazfile [command] [file...]\n
51 \033[1mCommands: \033[0m
52 usage Print this short usage.
53 build Build a files list to stdout from a list of packages.
54 recharge Recharge your $(basename $FILES_LIST) from the mirror.
55 search Search for file(s) in all (installed or not) packages.
57 \033[1mExample: \033[0m
58 $ find . -name '*.tazpkg' | tazfile build > $(basename $FILES_LIST)
59 $ tazfile recharge
60 $ tazfile search awk cpio "
61 }
63 # Check for packages.list to download and install packages.
64 check_for_files_list_lzma()
65 {
66 if [ ! -f "$FILES_LIST" ]; then
67 echo -e "
68 Unable to find the list : $FILES_LIST\n
69 You must probably run 'tazfile recharge' as root to get the latest list of
70 files available on the mirror.\n"
71 exit 0
72 fi
73 }
75 # Download a file trying all mirrors
76 download()
77 {
78 for i in $(cat $MIRROR); do
79 wget $i$@ && break
80 done
81 }
83 build_database()
84 {
85 while read pkg; do
86 cat $pkg | ( cd $TMP_DIR
87 cpio -iu > /dev/null 2>&1
88 . ./receipt
89 echo "$PACKAGE"
90 cat ./files.list ) | awk '
91 BEGIN { name="" }
92 {
93 if (name == "") name=$0;
94 else printf("%s: %s\n",name,$0);
95 }'
96 done
97 }
99 ###################
100 # Tazpkg commands #
101 ###################
103 case "$COMMAND" in
104 build)
105 # Create files.list.lzma to stdout.
106 #
107 mkdir $TMP_DIR
108 build_database | lzma e -si -so
109 rm -rf $TMP_DIR
110 ;;
111 recharge)
112 # Recharge files.list.lzma from a mirror.
113 #
114 cd $LOCALSTATE
115 echo ""
116 mv -f $FILES_LIST $FILES_LIST.old 2> /dev/null
117 download $(basename $FILES_LIST)
118 ;;
119 search)
120 # Search for a file by pattern or name in files.list.lzma.
121 #
122 check_for_files_list_lzma
123 while [ -n "$2" ]; do
124 unlzma -c $FILES_LIST | \
125 grep -i -- "$2$" | while read line; do
126 pkg=${line%:*}
127 if [ -d $INSTALLED/$pkg ]; then
128 echo -n "[already installed] "
129 fi
130 echo "$line"
131 done
132 shift
133 done
134 ;;
135 usage|*)
136 # Print a short help or give usage for an unknown or empty command.
137 #
138 usage
139 ;;
140 esac