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