wok annotate tramys-client/stuff/tramys2 @ rev 17090

tramys-client: make virtual package tramys-data (you can: tazpkg info tramys-data, tazpkg list-files tramys-data, or tazpkg remove tramys-data); better locale change.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Wed Aug 27 22:27:18 2014 +0300 (2014-08-27)
parents e96aa956e72e
children bf52d3ac4b95
rev   line source
al@17081 1 #!/bin/sh
al@17081 2 # tramys - TRAnslate MY Slitaz. Client solution
al@17081 3 # Tool for managing translation files for SliTaz GNU/Linux
al@17081 4 # Aleksej Bobylev <al.bobylev@gmail.com>, 2014
al@17081 5
al@17081 6 . /etc/slitaz/slitaz.conf
al@17081 7 . /lib/libtaz.sh
al@17090 8 . /etc/locale.conf
al@17082 9
al@17086 10 # Ask for root access in order to install the files in the system.
al@17082 11 if [ $(id -u) != 0 ]; then
al@17082 12 exec tazbox su $0 $@; exit 0
al@17082 13 fi
al@17082 14
al@17082 15 export TEXTDOMAIN='tramys' # i18n
al@17081 16 WORKING=$(mktemp -d)
al@17082 17 LOG="/tmp/tramys.log"
al@17082 18 TGZ="/tmp/tramys.tgz"
al@17086 19 URL="http://cook.slitaz.org/tramys2.cgi"
al@17086 20
al@17086 21 # Common Yad options.
al@17082 22 YADCONF="--center --window-icon=config-language --image=config-language --image-on-top"
al@17082 23
al@17086 24 # First step. Describes the functions of the program.
al@17086 25 # It is possible to set the language.
al@17086 26 # Also here the user has the ability to stop the program.
al@17082 27 yad $YADCONF --title="tramys (1/3)" --text="$(_ \
al@17082 28 'Now translations for all installed programs will be found and downloaded.
al@17082 29 You can change locale if you want, or proceed.
al@17082 30
al@17082 31 Your current locale: <b>$LANG</b>')" \
al@17082 32 --button "gtk-edit:2" --button "gtk-cancel:1" --button "gtk-go-forward:0"
al@17082 33 case $? in
al@17090 34 2) tazbox locale; tramys2; exit 0 ;;
al@17082 35 1) exit 0 ;;
al@17082 36 esac
al@17082 37
al@17086 38 # your locale -> HTTP_ACCEPT_LANGUAGE
al@17086 39 # your SliTaz release -> HTTP_ACCEPT (different releases have different translations)
al@17086 40 # your installed packages list -> HTTP_COOKIE (list=...)
al@17086 41 # Note clean address "tramys2.cgi" in the server access logs.
al@17086 42 #
al@17086 43 # Server sending and Yad shows user useful info using log widget.
al@17086 44 # We are temporarily stored this log in the $LOG file in order to get
al@17086 45 # a download token (see below).
al@17086 46 # Here the user can refuse to download the file.
al@17086 47 busybox wget --header "Accept-Language: $LANG" \
al@17086 48 --header "Accept: $(cat /etc/slitaz-release)" \
al@17086 49 --header "Cookie: list=$(cd $INSTALLED; ls -1 | tr '\n' ' ')" \
al@17086 50 $URL -O - | tee $LOG | \
al@17082 51 yad $YADCONF --title="tramys (2/3)" --progress --width=320 --text="$(_ \
al@17082 52 'The server processes the request.
al@17082 53 Please wait.')" \
al@17082 54 --enable-log --log-expanded \
al@17082 55 --button "gtk-cancel:1" --button "gtk-go-forward:0"
al@17086 56 ANSWER=$?
al@17086 57
al@17086 58 # In the last line of log server gives us a download token.
al@17086 59 # We can download archive which the server has prepared for us.
al@17086 60 # Get download token and remove log.
al@17086 61 DLKEY=$(tail -n1 $LOG); rm -f $LOG
al@17086 62
al@17086 63 case $ANSWER in
al@17086 64 1)
al@17086 65 # We need to remove archive that the user has refused to download.
al@17086 66 # This command passed in HTTP_COOKIE (rm=...)
al@17086 67 busybox wget --header "Cookie: rm=$DLKEY" $URL -O /dev/null; exit 0 ;;
al@17082 68 esac
al@17082 69
al@17086 70 # We want to download the file. Show pulsate progress bar.
al@17086 71 # This command passed in HTTP_COOKIE (dl=...)
al@17086 72 # Also here the user can terminate file downloading.
al@17086 73 busybox wget --header "Cookie: dl=$DLKEY" $URL -O $TGZ 2>&1 | \
al@17086 74 yad $YADCONF --title="tramys (3/3)" --progress --pulsate --width=320 \
al@17086 75 --text="$(_ \
al@17082 76 'Downloading in progress.
al@17082 77 Please wait.')" \
al@17082 78 --button "gtk-cancel:1" --button "gtk-ok:0"
al@17082 79 case $? in
al@17082 80 1) exit 0 ;;
al@17082 81 esac | \
al@17082 82
al@17086 83 # Unpack archive content to a temporary folder.
al@17082 84 busybox tar -xz -C $WORKING -f $TGZ
al@17086 85 # All folders and files in the archive are owned by user www and group www.
al@17086 86 # This is because the CGI script on the server is executed by the user www.
al@17086 87 # If we had just unpacked the archive content into our file system, then there
al@17086 88 # would be a big trouble. For example, all folders: /, /usr, /usr/share,
al@17086 89 # /usr/share/locale, etc. would be owned by user www and become unavailable
al@17086 90 # for a regular user. So force all folders and files to root own.
al@17081 91 chown -R root:root $WORKING
al@17090 92
al@17090 93 # Create or recreate virtual package "tramys-data".
al@17090 94 # It contains all translations.
al@17090 95 # And you can remove it if you no longer need translations.
al@17090 96 TD=$INSTALLED/tramys-data
al@17090 97 mkdir -p $TD
al@17090 98 cat <<EOT > $TD/receipt
al@17090 99 # SliTaz package receipt.
al@17090 100
al@17090 101 PACKAGE="tramys-data"
al@17090 102 VERSION="$(date +%y%m%d)"
al@17090 103 CATEGORY="system-tools"
al@17090 104 SHORT_DESC="This package contains translation files installed by tramys-client"
al@17090 105 MAINTAINER="you@slitaz.org"
al@17090 106 LICENSE="GPL"
al@17090 107 WEB_SITE="http://www.slitaz.org/"
al@17090 108 DEPENDS="tramys-client"
al@17090 109 EOT
al@17090 110 # Update files list.
al@17090 111 cd $WORKING; find . -type f | sed 's|^./|/|g' >> $TD/files.list
al@17090 112 sort -u $TD/files.list -o $TD/files.list
al@17090 113
al@17086 114 # copy all translation files to root file system.
al@17081 115 cp -fpr $WORKING/* /
al@17090 116
al@17090 117 # Recreate md5sums.
al@17090 118 md5sum $(cat $TD/files.list) > $TD/md5sum
al@17090 119
al@17086 120 # remove temporary folder and file, they are no longer needed.
al@17082 121 rm -f $TGZ
al@17081 122 rm -rf $WORKING
al@17082 123
al@17086 124 # Final message.
al@17082 125 yad $YADCONF --title="tramys" --text="$(_ \
al@17082 126 'Translation files have been installed in your system.')"