wok-next view tramys-server/stuff/tramys.cgi @ rev 17082
Up: tramys-server and tramys-client (140824).
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Sun Aug 24 22:46:59 2014 +0300 (2014-08-24) |
parents | 096a77a2021d |
children |
line source
1 #!/bin/sh
2 # tramys - TRAnslate MY Slitaz. Server solution
3 # Tool for managing translation files for SliTaz GNU/Linux
4 # Aleksej Bobylev <al.bobylev@gmail.com>, 2014
6 # How to use:
7 # 1. tramys2.cgi?lang=$LANG&rel=$RELEASE to generate archive
8 # Pass packages list in HTTP_USER_AGENT header
9 # (seems it have no restrictions for length and no encoded symbols ' ' and '+')
10 # 2. tramys2.cgi?dl=$DL_KEY to download archive (user can cancel downloading)
12 . /usr/bin/httpd_helper.sh
14 WORKING=$(mktemp -d)
15 DATADIR=/home/lexeii/Public/tramys
17 # hide script
18 if [ "x$(GET lang)$(GET rel)$(GET dl)" == "x" ]; then
19 echo -e "HTTP/1.1 404 Not Found\nContent-Type: text/html\n\n<!DOCTYPE html><html><head><title>404 - Not Found</title></head><body><h1>404 - Not Found</h1></body></html>"
20 exit
21 fi
23 # begin: compress and give to client
24 if [ "x$(GET dl)" != "x" ]; then
25 WORKING="/tmp/tmp.$(echo $(GET dl) | tr -cd 'A-Za-z0-9')" # avoid relative paths
26 cat <<EOT
27 Content-Type: application/x-compressed-tar
28 Content-Length: $(stat -c %s $WORKING.tgz)
29 Content-Disposition: attachment; filename=tramys.tgz
31 EOT
32 cat $WORKING.tgz
33 rm -f $WORKING.tgz
34 exit 0
35 fi
36 # end: compress and give to client
39 # prepare list for search
40 # original GNU gettext searches precisely in this order
41 locales_list() {
42 LL=$(echo $1 | sed 's|^\([^_.@]*\).*$|\1|')
43 CC=$(echo $1 | sed -n '/_/s|^[^_]*\(_[^.@]*\).*$|\1|p')
44 EE=$(echo $1 | sed -n '/./s|^[^\.]*\(\.[^@]*\).*$|\1|p')
45 VV=$(echo $1 | sed -n '/@/s|^[^@]*\(@.*\)$|\1|p')
46 ee=$(echo $EE | tr A-Z a-z | tr -cd a-z0-9); [ "$ee" ] && ee=.$ee
47 [ "x$EE" == "x$ee" ] && ee=''
49 [ "$CC" -a "$EE" -a "$VV" ] && echo -n "$LL$CC$EE$VV "
50 [ "$CC" -a "$ee" -a "$VV" ] && echo -n "$LL$CC$ee$VV "
51 [ "$CC" -a "$VV" ] && echo -n "$LL$CC$VV "
52 [ "$EE" -a "$VV" ] && echo -n "$LL$EE$VV "
53 [ "$ee" -a "$VV" ] && echo -n "$LL$ee$VV "
54 [ "$VV" ] && echo -n "$LL$VV "
55 [ "$CC" -a "$EE" ] && echo -n "$LL$CC$EE "
56 [ "$CC" -a "$ee" ] && echo -n "$LL$CC$ee "
57 [ "$CC" ] && echo -n "$LL$CC "
58 [ "$EE" ] && echo -n "$LL$EE "
59 [ "$ee" ] && echo -n "$LL$ee "
60 echo "$LL"
61 }
62 MY_LOCALES=$(locales_list $(GET lang))
64 # constants to use in lists
65 US="/usr/share"
66 LC="LC_MESSAGES"
67 PY="/usr/lib/python2.7/site-packages"
68 R="/usr/lib/R/library"
69 RT="$R/translations/%/$LC"
71 # supported 4.0 (as stable now) an cooking (rolling, 5.0)
72 # don't know what to do with "arm" and "x86_64" woks
73 case $(GET rel) in
74 4*) PREFIX="stable"; WOK="stable" ;;
75 *) PREFIX=""; WOK="cooking" ;;
76 esac
77 WOK="/home/slitaz/$WOK/chroot/home/slitaz/wok"
79 PKGNUM=$(echo $HTTP_USER_AGENT | wc -w)
80 NUM=1
82 echo -e "Content-Type: text/plain\n\n" # to Yad client
83 echo "#Number of packages: $PKGNUM"
84 echo "#Searching in progress..."
86 for P in $HTTP_USER_AGENT; do
88 echo "$((100*$NUM/$PKGNUM))" # percentage to Yad client
89 NUM=$(($NUM+1))
91 for list_type in mo qm; do
92 IFS=$'\n'
93 for line in $(grep -e "^$P " $DATADIR/$PREFIX$list_type.list); do
94 locales=$(echo $line | cut -d' ' -f2)
95 names=$(echo $line | cut -d' ' -f3)
96 [ "x$names" == "x" ] && names=$P
97 pathes=$(echo $line | cut -d' ' -f4)
98 [ "x$pathes" == "x" ] && pathes="$US/locale/%/$LC"
100 IFS=' '
101 for locale in $MY_LOCALES; do
102 if $(echo " $locales " | grep -q " $locale "); then
104 for name in $names; do
105 for path in $pathes; do
106 eval "fullname=${path//%/$locale}/${name//%/$locale}.$list_type"
107 mkdir -p $WORKING$(dirname $fullname)
108 cp -pf $WOK/$P/install$fullname $WORKING$fullname
109 done
110 done
111 break
112 fi
113 done
114 done
115 done
116 done
118 echo "#" # to Yad client log
119 echo "#Preparing archive. Please wait"
121 busybox tar -czf $WORKING.tgz -C $WORKING .
122 rm -rf $WORKING
124 echo "#" # to Yad client log
125 echo "#Done!"
126 echo "#Now you can proceed to downloading"
127 echo "#and installing your translations."
128 echo "#File size: $(stat -c %s $WORKING.tgz)"
130 echo "${WORKING#*.}" # give download key to Yad client
131 exit 0