wok diff 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 diff
1.1 --- a/tramys-server/stuff/tramys.cgi Sun Aug 24 22:43:01 2014 +0300 1.2 +++ b/tramys-server/stuff/tramys.cgi Sun Aug 24 22:46:59 2014 +0300 1.3 @@ -3,15 +3,39 @@ 1.4 # Tool for managing translation files for SliTaz GNU/Linux 1.5 # Aleksej Bobylev <al.bobylev@gmail.com>, 2014 1.6 1.7 -# How to use: tramys.cgi?lang=$LANG 1.8 +# How to use: 1.9 +# 1. tramys2.cgi?lang=$LANG&rel=$RELEASE to generate archive 1.10 # Pass packages list in HTTP_USER_AGENT header 1.11 # (seems it have no restrictions for length and no encoded symbols ' ' and '+') 1.12 +# 2. tramys2.cgi?dl=$DL_KEY to download archive (user can cancel downloading) 1.13 1.14 . /usr/bin/httpd_helper.sh 1.15 1.16 WORKING=$(mktemp -d) 1.17 DATADIR=/home/lexeii/Public/tramys 1.18 1.19 +# hide script 1.20 +if [ "x$(GET lang)$(GET rel)$(GET dl)" == "x" ]; then 1.21 + 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>" 1.22 + exit 1.23 +fi 1.24 + 1.25 +# begin: compress and give to client 1.26 +if [ "x$(GET dl)" != "x" ]; then 1.27 + WORKING="/tmp/tmp.$(echo $(GET dl) | tr -cd 'A-Za-z0-9')" # avoid relative paths 1.28 + cat <<EOT 1.29 +Content-Type: application/x-compressed-tar 1.30 +Content-Length: $(stat -c %s $WORKING.tgz) 1.31 +Content-Disposition: attachment; filename=tramys.tgz 1.32 + 1.33 +EOT 1.34 + cat $WORKING.tgz 1.35 + rm -f $WORKING.tgz 1.36 + exit 0 1.37 +fi 1.38 +# end: compress and give to client 1.39 + 1.40 + 1.41 # prepare list for search 1.42 # original GNU gettext searches precisely in this order 1.43 locales_list() { 1.44 @@ -44,11 +68,29 @@ 1.45 R="/usr/lib/R/library" 1.46 RT="$R/translations/%/$LC" 1.47 1.48 +# supported 4.0 (as stable now) an cooking (rolling, 5.0) 1.49 +# don't know what to do with "arm" and "x86_64" woks 1.50 +case $(GET rel) in 1.51 + 4*) PREFIX="stable"; WOK="stable" ;; 1.52 + *) PREFIX=""; WOK="cooking" ;; 1.53 +esac 1.54 +WOK="/home/slitaz/$WOK/chroot/home/slitaz/wok" 1.55 + 1.56 +PKGNUM=$(echo $HTTP_USER_AGENT | wc -w) 1.57 +NUM=1 1.58 + 1.59 +echo -e "Content-Type: text/plain\n\n" # to Yad client 1.60 +echo "#Number of packages: $PKGNUM" 1.61 +echo "#Searching in progress..." 1.62 + 1.63 for P in $HTTP_USER_AGENT; do 1.64 1.65 + echo "$((100*$NUM/$PKGNUM))" # percentage to Yad client 1.66 + NUM=$(($NUM+1)) 1.67 + 1.68 for list_type in mo qm; do 1.69 IFS=$'\n' 1.70 - for line in $(grep -e "^$P " $DATADIR/$list_type.list); do 1.71 + for line in $(grep -e "^$P " $DATADIR/$PREFIX$list_type.list); do 1.72 locales=$(echo $line | cut -d' ' -f2) 1.73 names=$(echo $line | cut -d' ' -f3) 1.74 [ "x$names" == "x" ] && names=$P 1.75 @@ -63,8 +105,7 @@ 1.76 for path in $pathes; do 1.77 eval "fullname=${path//%/$locale}/${name//%/$locale}.$list_type" 1.78 mkdir -p $WORKING$(dirname $fullname) 1.79 - cp -pf /home/slitaz/cooking/chroot/home/slitaz/wok/$P/install$fullname \ 1.80 - $WORKING$fullname 1.81 + cp -pf $WOK/$P/install$fullname $WORKING$fullname 1.82 done 1.83 done 1.84 break 1.85 @@ -74,14 +115,17 @@ 1.86 done 1.87 done 1.88 1.89 +echo "#" # to Yad client log 1.90 +echo "#Preparing archive. Please wait" 1.91 + 1.92 busybox tar -czf $WORKING.tgz -C $WORKING . 1.93 -cat <<EOT 1.94 -Content-Type: application/x-compressed-tar 1.95 -Content-Length: $(stat -c %s $WORKING.tgz) 1.96 -Content-Disposition: attachment; filename=tramys.tgz 1.97 +rm -rf $WORKING 1.98 1.99 -EOT 1.100 -cat $WORKING.tgz 1.101 +echo "#" # to Yad client log 1.102 +echo "#Done!" 1.103 +echo "#Now you can proceed to downloading" 1.104 +echo "#and installing your translations." 1.105 +echo "#File size: $(stat -c %s $WORKING.tgz)" 1.106 1.107 -rm -rf $WORKING 1.108 -rm -f $WORKING.tgz 1.109 +echo "${WORKING#*.}" # give download key to Yad client 1.110 +exit 0