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