slitaz-tools rev 143
Add: tazfile
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Wed Apr 16 20:33:25 2008 +0000 (2008-04-16) |
parents | e07f37112a41 |
children | e36407c1b1dd |
files | tinyutils/tazfile |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/tinyutils/tazfile Wed Apr 16 20:33:25 2008 +0000 1.3 @@ -0,0 +1,141 @@ 1.4 +#!/bin/sh 1.5 +# Tazfile - Tiny autonomus zone files locator. 1.6 +# 1.7 +# This is a lightwight files locator for *.tazpkg files, all written in 1.8 +# SHell script. It works well with Busybox ash shell and bash. Tazfile let you 1.9 +# create and explore a files list database. 1.10 +# 1.11 +# (C) 2008 SliTaz - GNU General Public License v3. 1.12 +# 1.13 +# Author : Pascal Bellard <pascal.bellard@slitaz.org> 1.14 +# 1.15 +VERSION=1.0 1.16 + 1.17 +#################### 1.18 +# Script variables # 1.19 +#################### 1.20 + 1.21 +# Initialize some variables to use words 1.22 +# rater than numbers for functions and actions. 1.23 +COMMAND=$1 1.24 +TOP_DIR=`pwd` 1.25 +TMP_DIR=/tmp/tazfile-$$-$RANDOM 1.26 + 1.27 +# Path to tazpkg used dir and configuration files 1.28 +LOCALSTATE=/var/lib/tazpkg 1.29 +INSTALLED=$LOCALSTATE/installed 1.30 +MIRROR=$LOCALSTATE/mirror 1.31 +FILES_LIST=$LOCALSTATE/files.list.lzma 1.32 +DEFAULT_MIRROR="http://download.tuxfamily.org/slitaz/packages/`cat /etc/slitaz-release`/" 1.33 + 1.34 +# Check if the directories and files used by Tazfile 1.35 +# exists. If not and user is root we creat them. 1.36 +if test $(id -u) = 0 ; then 1.37 + if [ ! -d "$INSTALLED" ]; then 1.38 + mkdir -p $INSTALLED 1.39 + fi 1.40 + if [ ! -f "$LOCALSTATE/mirror" ]; then 1.41 + echo "$DEFAULT_MIRROR" > $LOCALSTATE/mirror 1.42 + fi 1.43 +fi 1.44 + 1.45 +#################### 1.46 +# Script functions # 1.47 +#################### 1.48 + 1.49 +# Print the usage. 1.50 +usage () 1.51 +{ 1.52 + echo -e "SliTaz files locator - Version: $VERSION\n 1.53 +\033[1mUsage:\033[0m tazfile [command] [file...]\n 1.54 +\033[1mCommands: \033[0m 1.55 + usage Print this short usage. 1.56 + build Build a files list to stdout from a list of packages. 1.57 + recharge Recharge your $(basename $FILES_LIST) from the mirror. 1.58 + search Search for file(s) in all (installed or not) packages. 1.59 + 1.60 +\033[1mExample: \033[0m 1.61 + $ find . -name '*.tazpkg' | tazfile build > $(basename $FILES_LIST) 1.62 + $ find . -name '*.tazpkg' -newer $(basename $FILES_LIST) | tazfile $(basename $FILES_LIST) 1.63 + $ tazfile recharge 1.64 + $ tazfile search awk cpio " 1.65 +} 1.66 + 1.67 +# Check for packages.list to download and install packages. 1.68 +check_for_files_list_lzma() 1.69 +{ 1.70 + if [ ! -f "$FILES_LIST" ]; then 1.71 + echo -e " 1.72 +Unable to find the list : $FILES_LIST\n 1.73 +You must probably run 'tazfile recharge' as root to get the last list of 1.74 +files avalaible on the mirror.\n" 1.75 + exit 0 1.76 + fi 1.77 +} 1.78 + 1.79 +# Download a file trying all mirrors 1.80 +download() 1.81 +{ 1.82 + for i in $(cat $MIRROR); do 1.83 + wget $i$@ && break 1.84 + done 1.85 +} 1.86 + 1.87 +build_database() 1.88 +{ 1.89 + while read pkg; do 1.90 + cat $pkg | ( cd $TMP_DIR 1.91 + cpio -iu > /dev/null 2>&1 1.92 + . ./receipt 1.93 + echo "$PACKAGE" 1.94 + cat ./files.list ) | awk ' 1.95 + BEGIN { name="" } 1.96 + { 1.97 + if (name == "") name=$0; 1.98 + else printf("%s: %s\n",name,$0); 1.99 + }' 1.100 + done 1.101 +} 1.102 + 1.103 +################### 1.104 +# Tazpkg commands # 1.105 +################### 1.106 + 1.107 +case "$COMMAND" in 1.108 + build) 1.109 + # Create files.list.lzma to stdout. 1.110 + # 1.111 + mkdir $TMP_DIR 1.112 + build_database | lzma e -si -so 1.113 + rm -rf $TMP_DIR 1.114 + ;; 1.115 + recharge) 1.116 + # Recharge files.list.lzma from a mirror. 1.117 + # 1.118 + cd $LOCALSTATE 1.119 + echo "" 1.120 + mv -f $FILES_LIST $FILES_LIST.old 2> /dev/null 1.121 + download $(basename $FILES_LIST) 1.122 + ;; 1.123 + search) 1.124 + # Search for a file by pattern or name in files.list.lzma. 1.125 + # 1.126 + check_for_files_list_lzma 1.127 + while [ -n "$2" ]; do 1.128 + unlzma -c $FILES_LIST | \ 1.129 + grep -i -- "$2$" | while read line; do 1.130 + pkg=${line%:*} 1.131 + if [ -d $INSTALLED/$pkg ]; then 1.132 + echo -n "[already installed] " 1.133 + fi 1.134 + echo "$line" 1.135 + done 1.136 + shift 1.137 + done 1.138 + ;; 1.139 + usage|*) 1.140 + # Print a short help or give usage for an unknow or empty command. 1.141 + # 1.142 + usage 1.143 + ;; 1.144 +esac