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