spk rev 19

add: spk and some improvments
author Christophe Lincoln <pankso@slitaz.org>
date Tue May 15 14:20:23 2012 +0200 (2012-05-15)
parents e5d4c5d3ccf4
children 7d060800df61
files Makefile lib/libspk.sh spk spk-rm
line diff
     1.1 --- a/Makefile	Tue May 15 12:46:12 2012 +0200
     1.2 +++ b/Makefile	Tue May 15 14:20:23 2012 +0200
     1.3 @@ -38,9 +38,11 @@
     1.4  
     1.5  install: install-lib
     1.6  	install -m 0755 -d $(DESTDIR)$(PREFIX)/bin
     1.7 +	install -m 0755 -d $(DESTDIR)$(PREFIX)/sbin
     1.8  	install -m 0755 -d $(DESTDIR)$(PREFIX)/share/doc/spk
     1.9 +	install -m 0755 spk $(DESTDIR)$(PREFIX)/bin
    1.10  	install -m 0755 spk-ls $(DESTDIR)$(PREFIX)/bin
    1.11 -	install -m 0755 spk-rm $(DESTDIR)$(PREFIX)/bin
    1.12 +	install -m 0755 spk-rm $(DESTDIR)$(PREFIX)/sbin
    1.13  
    1.14  # Clean source
    1.15  
     2.1 --- a/lib/libspk.sh	Tue May 15 12:46:12 2012 +0200
     2.2 +++ b/lib/libspk.sh	Tue May 15 14:20:23 2012 +0200
     2.3 @@ -16,10 +16,19 @@
     2.4  pkgsdesc="${root}${PKGS_DB}/packages.desc"
     2.5  pkgsmd5="${root}${PKGS_DB}/packages.md5"
     2.6  # ????do we need packages.equiv????
     2.7 -blocked="${root}${PKGS_DB}/blocked-packages.list"
     2.8 +blocked="${root}${PKGS_DB}/blocked.list"
     2.9  activity="${root}${PKGS_DB}/activity"
    2.10  
    2.11  #
    2.12 +# Sanity checks
    2.13 +#
    2.14 +
    2.15 +if [ ! -d "${root}${PKGS_DB}" ]; then
    2.16 +	gettext "Can't find DB:"; echo " ${root}${PKGS_DB}"
    2.17 +	exit 1
    2.18 +fi
    2.19 +
    2.20 +#
    2.21  # Functions
    2.22  #
    2.23  
    2.24 @@ -45,13 +54,13 @@
    2.25  # Used by: list
    2.26  count_installed() {
    2.27  	local count=$(ls $installed | wc -l)
    2.28 -	gettext "Installed packages"; echo ": $count"
    2.29 +	gettext "Installed  :"; echo " $count"
    2.30  }
    2.31  
    2.32  # Used by: list
    2.33  count_mirrored() {
    2.34  	local count=$(cat $pkgsmd5 | wc -l)
    2.35 -	gettext "Mirrored packages"; echo ": $count"
    2.36 +	gettext "Mirrored   :"; echo " $count"
    2.37  }
    2.38  
    2.39  is_package_mirrored() {
    2.40 @@ -72,7 +81,7 @@
    2.41  	esac
    2.42  }
    2.43  
    2.44 -# Assume package_name is valid
    2.45 +# Assume package name is valid
    2.46  # There may be a more efficient way to do this...
    2.47  full_package() {
    2.48  	local name=$1
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/spk	Tue May 15 14:20:23 2012 +0200
     3.3 @@ -0,0 +1,126 @@
     3.4 +#!/bin/sh
     3.5 +#
     3.6 +# Spk - The SliTaz Packages toolset. Read the README before adding or
     3.7 +# modifing any code in spk!
     3.8 +#
     3.9 +# Copyright (C) SliTaz GNU/Linux - BSD License
    3.10 +# Author: See AUTHORS files
    3.11 +#
    3.12 +#. /usr/lib/slitaz/libspk.sh
    3.13 +. lib/libspk.sh
    3.14 +
    3.15 +#
    3.16 +# Functions
    3.17 +#
    3.18 +
    3.19 +# Help and usage
    3.20 +usage() {
    3.21 +	name=$(basename $0)
    3.22 +	cat << EOT
    3.23 +
    3.24 +$(boldify $(gettext "Usage:")) $name [packages|--options]
    3.25 +
    3.26 +$(gettext "SliTaz Packages toolset")
    3.27 +
    3.28 +$(boldify $(gettext "Commands:"))
    3.29 +  info     $(gettext "Display path, mirror and other stats")
    3.30 +  activity $(gettext "Display packages activities")
    3.31 +
    3.32 +$(boldify $(gettext "Options:"))
    3.33 +  --block     $(gettext "TODO")
    3.34 +  --root      $(gettext "Set the root file system path")
    3.35 +  --debug     $(gettext "Display some usefull debug information")
    3.36 +
    3.37 +$(boldify $(gettext "Examples:"))
    3.38 +  $name package1 package2 packageN
    3.39 +  $name package --block
    3.40 +
    3.41 +EOT
    3.42 +	exit 0
    3.43 +}
    3.44 +
    3.45 +#
    3.46 +# Commands and exit
    3.47 +#
    3.48 +
    3.49 +case "$1" in
    3.50 +	""|*usage|*help) usage ;;
    3.51 +	info)
    3.52 +		newline
    3.53 +		boldify "Spk Info"
    3.54 +		separator
    3.55 +		gettext "Database   :"; echo " $installed"
    3.56 +		gettext "Mirror URL :"; echo " $(cat $mirrorurl)"
    3.57 +		count_installed
    3.58 +		count_mirrored
    3.59 +		separator
    3.60 +		newline && exit 0 ;;
    3.61 +	activity)
    3.62 +		newline
    3.63 +		boldify "Spk Activity"
    3.64 +		separator
    3.65 +		cat $activity
    3.66 +		separator && newline
    3.67 +		exit 0 ;;
    3.68 +	ls|add)
    3.69 +		# Sort of helper on wrong commands or --option ? Or have better
    3.70 +		# usage/help: spk help [command] ?
    3.71 +		gettext "Did you mean ?"; echo " spk-$@"
    3.72 +		exit 0 ;;
    3.73 +esac
    3.74 +
    3.75 +#
    3.76 +# Handle packages: spk package1 ... packageN
    3.77 +#
    3.78 +
    3.79 +[ "$debug" ] && echo "DEBUG: cmdline: $0 $@"
    3.80 +count=0
    3.81 +
    3.82 +for pkg in $@
    3.83 +do
    3.84 +	# Handle: --options
    3.85 +	case " $@ " in
    3.86 +		*\ --rm\ *)
    3.87 +			spk-rm $pkg --count=$count
    3.88 +			count=$(($count + 1))
    3.89 +			continue ;;
    3.90 +	esac
    3.91 +	count=$(($count + 1))
    3.92 +	# Installed ?
    3.93 +	if [ -d "$installed/$pkg" ]; then
    3.94 +		[ "$count" == 1 ] && newline
    3.95 +		unset_receipt
    3.96 +		. $installed/$pkg/receipt
    3.97 +		boldify "$(gettext "Package") $pkg"
    3.98 +		separator
    3.99 +		gettext "Status     : installed"; newline
   3.100 +		receipt_info
   3.101 +		separator && newline
   3.102 +		continue
   3.103 +	fi
   3.104 +	# Mirrored ?
   3.105 +	mirrored=$(grep "^$pkg |" $pkgsdesc)
   3.106 +	if [ "$mirrored" ]; then
   3.107 +		# Handle: --add
   3.108 +		if [ "$add" ]; then
   3.109 +			echo "TODO: test 'spk-add $pkg'"
   3.110 +		else
   3.111 +			[ "$count" == 1 ] && newline
   3.112 +			boldify "$(gettext "Package") $pkg"
   3.113 +			separator
   3.114 +			gettext "Status     : not installed"; echo ""
   3.115 +			echo "$mirrored" | awk 'BEGIN { FS = "|" } ; { print \
   3.116 +				"Version    :" $2 "\n" \
   3.117 +				"Short desc :" $3 "\n" \
   3.118 +				"Category   :" $4 }'
   3.119 +			separator && newline
   3.120 +		fi
   3.121 +		continue
   3.122 +	fi
   3.123 +	# Skip options such as --confirm or unknow package
   3.124 +	case "$pkg" in
   3.125 +		--*) continue ;;
   3.126 +		*) gettext "Unknow package"; echo ": $pkg"
   3.127 +	esac
   3.128 +done
   3.129 +exit 0
     4.1 --- a/spk-rm	Tue May 15 12:46:12 2012 +0200
     4.2 +++ b/spk-rm	Tue May 15 14:20:23 2012 +0200
     4.3 @@ -6,8 +6,7 @@
     4.4  # Copyright (C) SliTaz GNU/Linux - BSD License
     4.5  # Author: See AUTHORS files
     4.6  #
     4.7 -#. /usr/lib/slitaz/libspk.sh
     4.8 -. lib/libspk.sh
     4.9 +. /usr/lib/slitaz/libspk.sh
    4.10  
    4.11  #
    4.12  # Functions
    4.13 @@ -168,7 +167,7 @@
    4.14  # Handle packages
    4.15  #
    4.16  
    4.17 -count=0
    4.18 +: ${count=0}
    4.19  check_root
    4.20  
    4.21  for pkg in $@