slitaz-base-files rev 125

Add /lib/libtaz.sh
author Christophe Lincoln <pankso@slitaz.org>
date Thu Apr 12 21:53:58 2012 +0200 (2012-04-12)
parents cd043522cb43
children 32c560235098
files Makefile po/fr.po po/slitaz-base.pot rootfs/lib/libtaz.sh testsuite.sh
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Makefile	Thu Apr 12 21:53:58 2012 +0200
     1.3 @@ -0,0 +1,49 @@
     1.4 +# Makefile for SliTaz Bugs.
     1.5 +#
     1.6 +
     1.7 +PACKAGE="slitaz-base"
     1.8 +PREFIX?=/usr
     1.9 +LINGUAS?=fr
    1.10 +
    1.11 +all: help
    1.12 +
    1.13 +help:
    1.14 +	@echo "make [pot|msgmerge|msgfmt|install-libtaz|install-msg|install|clean]"
    1.15 +
    1.16 +# i18n
    1.17 +
    1.18 +pot:
    1.19 +	xgettext -o po/$(PACKAGE).pot -L Shell --package-name="SliTaz Base" \
    1.20 +		./rootfs/lib/libtaz.sh
    1.21 +
    1.22 +msgmerge:
    1.23 +	@for l in $(LINGUAS); do \
    1.24 +		echo -n "Updating $$l po file."; \
    1.25 +		msgmerge -U po/$$l.po po/$(PACKAGE).pot; \
    1.26 +	done;
    1.27 +
    1.28 +msgfmt:
    1.29 +	@for l in $(LINGUAS); do \
    1.30 +		echo "Compiling $$l mo file..."; \
    1.31 +		mkdir -p po/mo/$$l/LC_MESSAGES; \
    1.32 +		msgfmt -o po/mo/$$l/LC_MESSAGES/$(PACKAGE).mo po/$$l.po; \
    1.33 +	done;
    1.34 +
    1.35 +# Install
    1.36 +
    1.37 +install-libtaz:
    1.38 +	install -m 0744 rootfs/lib/libtaz.sh $(DESTDIR)/lib
    1.39 +	
    1.40 +install-msg: msgfmt
    1.41 +	install -m 0755 -d $(DESTDIR)$(PREFIX)/share/locale
    1.42 +	cp -a po/mo/* $(DESTDIR)$(PREFIX)/share/locale
    1.43 +	
    1.44 +install: install-msg
    1.45 +	cp -a rootfs/* $(DESTDIR)
    1.46 +	chown -R root.root $(DESTDIR)
    1.47 +
    1.48 +# Clean source
    1.49 +
    1.50 +clean:
    1.51 +	rm -rf po/mo
    1.52 +	
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/po/fr.po	Thu Apr 12 21:53:58 2012 +0200
     2.3 @@ -0,0 +1,31 @@
     2.4 +# French translations for SliTaz package.
     2.5 +# Copyright (C) 2012 THE SliTaz'S COPYRIGHT HOLDER
     2.6 +# This file is distributed under the same license as the SliTaz package.
     2.7 +# Christophe Lincoln <pankso@slitaz.org>, 2012.
     2.8 +#
     2.9 +msgid ""
    2.10 +msgstr ""
    2.11 +"Project-Id-Version: SliTaz Base\n"
    2.12 +"Report-Msgid-Bugs-To: \n"
    2.13 +"POT-Creation-Date: 2012-04-12 02:06+0200\n"
    2.14 +"PO-Revision-Date: 2012-04-12 02:14+0100\n"
    2.15 +"Last-Translator: Christophe Lincoln <pankso@slitaz.org>\n"
    2.16 +"Language-Team: French\n"
    2.17 +"Language: fr\n"
    2.18 +"MIME-Version: 1.0\n"
    2.19 +"Content-Type: text/plain; charset=UTF-8\n"
    2.20 +"Content-Transfer-Encoding: 8bit\n"
    2.21 +"Plural-Forms: nplurals=2; plural=(n > 1);\n"
    2.22 +
    2.23 +#: rootfs/usr/lib/slitaz/libtaz.sh:18
    2.24 +msgid "Done"
    2.25 +msgstr "Fait"
    2.26 +
    2.27 +#: rootfs/usr/lib/slitaz/libtaz.sh:19
    2.28 +msgid "Failed"
    2.29 +msgstr "Echec"
    2.30 +
    2.31 +#: rootfs/usr/lib/slitaz/libtaz.sh:100
    2.32 +msgid "You must be root to execute:"
    2.33 +msgstr "Vous devez ĂȘtre root pour exĂ©cuter:"
    2.34 +
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/po/slitaz-base.pot	Thu Apr 12 21:53:58 2012 +0200
     3.3 @@ -0,0 +1,30 @@
     3.4 +# SOME DESCRIPTIVE TITLE.
     3.5 +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
     3.6 +# This file is distributed under the same license as the PACKAGE package.
     3.7 +# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
     3.8 +#
     3.9 +#, fuzzy
    3.10 +msgid ""
    3.11 +msgstr ""
    3.12 +"Project-Id-Version: SliTaz Base\n"
    3.13 +"Report-Msgid-Bugs-To: \n"
    3.14 +"POT-Creation-Date: 2012-04-12 16:38+0200\n"
    3.15 +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    3.16 +"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
    3.17 +"Language-Team: LANGUAGE <LL@li.org>\n"
    3.18 +"Language: \n"
    3.19 +"MIME-Version: 1.0\n"
    3.20 +"Content-Type: text/plain; charset=CHARSET\n"
    3.21 +"Content-Transfer-Encoding: 8bit\n"
    3.22 +
    3.23 +#: rootfs/lib/libtaz.sh:18
    3.24 +msgid "Done"
    3.25 +msgstr ""
    3.26 +
    3.27 +#: rootfs/lib/libtaz.sh:19
    3.28 +msgid "Failed"
    3.29 +msgstr ""
    3.30 +
    3.31 +#: rootfs/lib/libtaz.sh:100
    3.32 +msgid "You must be root to execute:"
    3.33 +msgstr ""
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/rootfs/lib/libtaz.sh	Thu Apr 12 21:53:58 2012 +0200
     4.3 @@ -0,0 +1,106 @@
     4.4 +#!/bin/sh
     4.5 +#
     4.6 +# SliTaz Base functions used from boot scripts to end user tools. Use
     4.7 +# gettext and not echo for messages. Keep output suitable for GTK boxes
     4.8 +# and Ncurses dialog. LibTaz should not depend on any configuration file.
     4.9 +# No bloated code here, function must be used by at least 3-4 tools. See
    4.10 +# libtaz() for a list of functions and options or run: tazdev libtaz.sh
    4.11 +# Libtaz is located in /lib/libtaz.sh since it is used when /usr may not
    4.12 +# be mounted.
    4.13 +#
    4.14 +# Copyright (C) 2012 SliTaz GNU/Linux - BSD License
    4.15 +#
    4.16 +
    4.17 +# Internationalization.
    4.18 +. /usr/bin/gettext.sh
    4.19 +TEXTDOMAIN='slitaz-base'
    4.20 +export TEXTDOMAIN
    4.21 +
    4.22 +# Internal variables.
    4.23 +okmsg="$(gettext "Done")"
    4.24 +ermsg="$(gettext "Failed")"
    4.25 +okcolor=32
    4.26 +ercolor=31
    4.27 +
    4.28 +# Parse cmdline options.
    4.29 +for opt in "$@"
    4.30 +do
    4.31 +	case "$opt" in
    4.32 +		--raw-out)
    4.33 +			output="raw"
    4.34 +			done=" $okmsg" 
    4.35 +			error=" $ermsg" ;;
    4.36 +		--gtk-out)
    4.37 +			# Yad/GTK TextView bold or colored text ?
    4.38 +			output="gtk" 
    4.39 +			done=" $okmsg" 
    4.40 +			error=" $ermsg" ;;
    4.41 +		--html-out)
    4.42 +			output="html" 
    4.43 +			done=" <span class='done'>$okmsg</span>" 
    4.44 +			error=" <span class='error'>$ermsg</span>" ;;
    4.45 +	esac
    4.46 +done
    4.47 +
    4.48 +# Help and usage.
    4.49 +libtaz() {
    4.50 +	cat << EOT
    4.51 +
    4.52 +Include this library in a script:
    4.53 +  . /usr/lib/slitaz/libtaz.sh
    4.54 +
    4.55 +Functions:
    4.56 +  status
    4.57 +  separator
    4.58 +  boldify string
    4.59 +  check_root
    4.60 +
    4.61 +Options:
    4.62 +  --raw-out
    4.63 +  --gtk-out
    4.64 +  --html-out
    4.65 + 
    4.66 +EOT
    4.67 +}
    4.68 +
    4.69 +# Return command status. Default to colored console output.
    4.70 +status() {
    4.71 +	local check=$?
    4.72 +	if [ ! "$output" ]; then
    4.73 +		local cols=$(stty -a | head -n 1 | cut -d ";" -f 3 | awk '{print $2}')
    4.74 +		local scol=$(($cols - 10))
    4.75 +		done="\\033[${scol}G[ \\033[1;${okcolor}m${okmsg}\\033[0;39m ]"
    4.76 +		error="\\033[${scol}G[ \\033[1;${ercolor}m${ermsg}\\033[0;39m ]"
    4.77 +	fi
    4.78 +	if [ $check = 0 ]; then
    4.79 +		echo -e "$done"
    4.80 +	else
    4.81 +		echo -e "$error"
    4.82 +	fi
    4.83 +}
    4.84 +
    4.85 +# Line separator.
    4.86 +separator() {
    4.87 +	local cols=$(stty -a | head -n 1 | cut -d ";" -f 3 | awk '{print $2}')
    4.88 +	for c in $(seq 1 $cols); do
    4.89 +		echo -n "="
    4.90 +	done && echo ""
    4.91 +}
    4.92 +
    4.93 +# Display a bold message. GTK Yad: Works only in --text=""
    4.94 +boldify() {
    4.95 +	case $output in
    4.96 +		raw) echo "$1" ;;
    4.97 +		gtk) echo "<b>$1</b>" ;;
    4.98 +		html) echo "<strong>$1</strong>" ;;
    4.99 +		*) echo -e "\\033[1m${1}\\033[0m" ;;
   4.100 +	esac
   4.101 +}
   4.102 +
   4.103 +# Check if user is logged as root.
   4.104 +check_root() {
   4.105 +	if [ $(id -u) != 0 ]; then
   4.106 +		gettext "You must be root to execute:" && echo " $(basename $0) $@"
   4.107 +		exit 1
   4.108 +	fi
   4.109 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/testsuite.sh	Thu Apr 12 21:53:58 2012 +0200
     5.3 @@ -0,0 +1,20 @@
     5.4 +#!/bin/sh
     5.5 +#
     5.6 +. rootfs/lib/libtaz.sh
     5.7 +
     5.8 +echo -n "Checking libtaz.sh: status() 0"
     5.9 +status
    5.10 +
    5.11 +echo -n "Checking libtaz.sh: status() 1"
    5.12 +touch /tmp/1/2/2/4 2>/dev/null
    5.13 +status
    5.14 +
    5.15 +echo -n "Checking libtaz.sh: boldify() "
    5.16 +boldify "Message"
    5.17 +
    5.18 +echo "Checking libtaz.sh: separator"
    5.19 +separator
    5.20 +#check_root $@
    5.21 +
    5.22 +echo ""
    5.23 +exit 0