wok view tramys-server/stuff/tramys2.cgi @ rev 22927

updated hdf5 and hdf5-dev (1.10.4 -> 1.10.6)
author Hans-G?nter Theisgen
date Wed Feb 26 15:03:15 2020 +0100 (2020-02-26)
parents 02c70d036ea0
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. Request for archive:
8 # HTTP_ACCEPT_LANGUAGE -> users locale
9 # HTTP_ACCEPT -> SliTaz release
10 # HTTP_COOKIE (list=...) -> space-separated list of packages to process
11 #
12 # 2. Remove archive that the user has refused to download:
13 # HTTP_COOKIE (rm=DLKEY) -> remove /tmp/tmp.DLKEY.tgz file
14 #
15 # 3. Send archive to user:
16 # HTTP_COOKIE (dl=DLKEY) -> send /tmp/tmp.DLKEY.tgz file
18 . /usr/bin/httpd_helper.sh
19 . /home/slitaz/www/cook/tramys2.msg # translations
21 WORKING=$(busybox mktemp -d) # make temp working dir /tmp/tmp.??????
22 DATADIR=/usr/share/tramys # this folder contains lists
24 # Get user settings from HTTP headers.
25 lang="$HTTP_ACCEPT_LANGUAGE"
26 rel="$HTTP_ACCEPT"
27 cmd="${HTTP_COOKIE%%=*}"
28 arg="${HTTP_COOKIE#*=}"
30 #-----------#
31 # Functions #
32 #-----------#
34 # Prepare list for search.
35 # Original GNU gettext searches precisely in this order.
36 locales_list() {
37 LL=$(echo $1 | sed 's|^\([^_.@]*\).*$|\1|')
38 CC=$(echo $1 | sed -n '/_/s|^[^_]*\(_[^.@]*\).*$|\1|p')
39 EE=$(echo $1 | sed -n '/./s|^[^\.]*\(\.[^@]*\).*$|\1|p')
40 VV=$(echo $1 | sed -n '/@/s|^[^@]*\(@.*\)$|\1|p')
41 ee=$(echo $EE | tr A-Z a-z | tr -cd a-z0-9); [ "$ee" ] && ee=.$ee
42 [ "x$EE" = "x$ee" ] && ee=''
44 [ "$CC" -a "$EE" -a "$VV" ] && echo -n "$LL$CC$EE$VV "
45 [ "$CC" -a "$ee" -a "$VV" ] && echo -n "$LL$CC$ee$VV "
46 [ "$CC" -a "$VV" ] && echo -n "$LL$CC$VV "
47 [ "$EE" -a "$VV" ] && echo -n "$LL$EE$VV "
48 [ "$ee" -a "$VV" ] && echo -n "$LL$ee$VV "
49 [ "$VV" ] && echo -n "$LL$VV "
50 [ "$CC" -a "$EE" ] && echo -n "$LL$CC$EE "
51 [ "$CC" -a "$ee" ] && echo -n "$LL$CC$ee "
52 [ "$CC" ] && echo -n "$LL$CC "
53 [ "$EE" ] && echo -n "$LL$EE "
54 [ "$ee" ] && echo -n "$LL$ee "
55 echo "$LL"
56 }
57 MY_LOCALES=$(locales_list $lang)
59 # Search and copy translation files
60 copy_translations() {
61 # for all packages in list
62 for P in $arg; do
64 echo "$((100*$NUM/$PKGNUM))" # send percentage to Yad client
65 NUM=$(($NUM+1)) # next package
67 # for all list types
68 for list_type in mo qm; do
69 IFS=$'\n'
70 for line in $(grep -e "^$P " $DATADIR/$PREFIX$list_type.list); do
71 locales=$(echo $line | cut -d' ' -f2)
72 names=$(echo $line | cut -d' ' -f3)
73 [ -z "$names" ] && names=$P
74 paths=$(echo $line | cut -d' ' -f4)
75 [ -z "$paths" ] && paths="$US/locale/%/$LC"
77 IFS=' '
78 # for all valid locale variants
79 for locale in $MY_LOCALES; do
80 if $(echo " $locales " | grep -q " $locale "); then
82 # for all file names
83 for name in $names; do
84 # for all paths
85 for path in $paths; do
86 # substitute variables and "%"
87 eval "fullname=${path//%/$locale}/${name//%/$locale}.$list_type"
89 # copy translation file to working dir
90 mkdir -p $WORKING$(dirname $fullname)
91 cp -pf $WOK/$P/install$fullname $WORKING$fullname
92 done
93 done
94 break
95 fi
96 done
97 done
98 done
99 done
100 }
102 #----------#
103 # Main #
104 #----------#
106 # Branch commands: list, rm, dl.
107 case "x$cmd" in
108 xlist) # Main actions: get list, search translations, make an archive.
109 # constants to use in lists
110 US="/usr/share"
111 LC="LC_MESSAGES"
112 PY="/usr/lib/python2.7/site-packages"
113 R="/usr/lib/R/library"
114 RT="$R/translations/%/$LC"
116 # Supported 4.0 (as stable now) and cooking (rolling, 5.0)
117 # Don't know what to do with "arm" and "x86_64" woks ???
118 case "x$rel" in
119 x4*|xstable) PREFIX="stable_"; WOK="stable" ;;
120 *) PREFIX=""; WOK="cooking" ;;
121 esac
122 # Path to the specified WOK in the SliTaz server.
123 WOK="/home/slitaz/$WOK/chroot/home/slitaz/wok"
125 PKGNUM=$(echo $arg | wc -w) # number of packages in the list
126 NUM=1 # initial value
128 echo -e "Content-Type: text/plain\n\n" # to Yad client
129 msg 1 # Message to Yad log
131 copy_translations
133 msg 2 # Message to Yad log
135 # Make the archive from working dir and remove temp working dir.
136 busybox tar -czf $WORKING.tgz -C $WORKING .
137 rm -rf $WORKING
139 SIZE=$(ls -lh $WORKING.tgz | awk '{print $5}')
140 msg 3 # Message to Yad log
142 echo "${WORKING#*.}" # give download token to Yad client
143 exit 0 ;;
145 xrm) # Remove archive.
146 # Avoid relative path to avoid removing of any system file.
147 archive="/tmp/tmp.$(echo $arg | tr -cd 'A-Za-z0-9').tgz"
148 rm -f $archive
149 cat <<EOT
150 Content-Type: text/plain; charset=UTF-8
151 Content-Length: 0
153 EOT
154 exit 0 ;;
156 xdl) # Send archive to client.
157 # Avoid relative path to avoid hijacking of any system file.
158 archive="/tmp/tmp.$(echo $arg | tr -cd 'A-Za-z0-9').tgz"
159 cat <<EOT
160 Content-Type: application/x-compressed-tar
161 Content-Length: $(stat -c %s $archive)
162 Content-Disposition: attachment; filename=tramys.tgz
164 EOT
165 cat $archive
166 # Remove archive after sending.
167 rm -f $archive
168 exit 0 ;;
170 *) # Hide the script from the web bots and browsers.
171 echo -e "HTTP/1.0 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>"
172 exit ;;
173 esac
175 exit 0