sup rev 23
Small fix to sup cmdline tool and huge imprivments to the online Hub (upload packages)
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Mon Feb 27 12:16:46 2017 +0100 (2017-02-27) |
parents | 361b8459a302 |
children | 690b94e42aa8 |
files | libsup.sh server/sup/sup.cgi server/sup/sup.conf sup |
line diff
1.1 --- a/libsup.sh Sun Feb 26 22:38:12 2017 +0100 1.2 +++ b/libsup.sh Mon Feb 27 12:16:46 2017 +0100 1.3 @@ -16,7 +16,6 @@ 1.4 activity="$cache/activity.log" 1.5 1.6 mirror="http://scn.slitaz.org/content/sup/packages" 1.7 -md5list="$supdb/packages.md5" 1.8 pkgsdb="$supdb/packages.db" 1.9 1.10 wok="$supdb/wok"
2.1 --- a/server/sup/sup.cgi Sun Feb 26 22:38:12 2017 +0100 2.2 +++ b/server/sup/sup.cgi Mon Feb 27 12:16:46 2017 +0100 2.3 @@ -4,57 +4,229 @@ 2.4 # 2.5 # This plugin is part of the SPI tools and services. More information 2.6 # at http://hg.slitaz.org/sup/file/ && http://scn.slitaz.org/?d=en/sup 2.7 +# packages.db is a SQLite table with all mirrored packages info, just 2.8 +# for the fun of playing witg SQLite :-) 2.9 # 2.10 # Copyright (C) 2017 SliTaz GNU/Linux - BSD License 2.11 # Author: Christophe Lincoln <pankso@slitaz.org> 2.12 # 2.13 2.14 +# This script is called directly on upload: get httphelper.sh functions 2.15 +# and set full path to move files 2.16 +if [ "$(basename $0)" == "sup.cgi" ]; then 2.17 + . /lib/libtaz.sh 2.18 + . /usr/lib/slitaz/httphelper.sh 2.19 +fi 2.20 + 2.21 +#host="http://scn.slitaz.org/" 2.22 +#scn="/home/slitaz/www/scn" 2.23 +host="http://localhost/~pankso/cgi-bin/scn/" 2.24 +scn="/home/pankso/Public/cgi-bin/scn" 2.25 + 2.26 +supdb="$content/sup" 2.27 +wok="$supdb/wok" 2.28 +packages="$supdb/packages" 2.29 +suplog="$cache/log/sup.log" 2.30 + 2.31 +# Keep the highlighter minimal :-) 2.32 +receip_highlighter() { 2.33 + sed -e s'|&|\&|g' -e 's|<|\<|g' -e 's|>|\>|'g \ 2.34 + -e s"#^\#\([^']*\)#<span class='comment'>\0</span>#"g \ 2.35 + -e s"#\"\([^']*\)\"#<span class='value'>\0</span>#"g 2.36 +} 2.37 + 2.38 case " $(GET sup) " in 2.39 2.40 *\ pkg\ *) 2.41 pkg="$(GET name)" 2.42 - supdb="$content/sup" 2.43 - wok="$supdb/wok" 2.44 - d="Sup package: $pkg" 2.45 + d="SUP: $pkg" 2.46 header 2.47 html_header 2.48 user_box 2.49 + if ! . ${wok}/${pkg}/receip; then 2.50 + echo "Missing or corrupted receip" && exit 1 2.51 + fi 2.52 + cat << EOT 2.53 +<h2>$(gettext "Package:") $PACKAGE $VERSION</h2> 2.54 +<div id="tools"> 2.55 + <a title="Right click to download link: $PACKAGE-$VERSION.sup" 2.56 + href='$packages/$PACKAGE-$VERSION.sup'>Download</a> 2.57 + <a href='?sup'>SUP Hub</a> 2.58 +EOT 2.59 + # Tools for logged users 2.60 + if check_auth; then 2.61 + cat << EOT 2.62 + <a href="?sup=upload">$(gettext "Update package")</a> 2.63 +EOT 2.64 + fi 2.65 + cat << EOT 2.66 +</div> 2.67 + 2.68 +<h3>$(gettext "Receip")</h3> 2.69 +<pre> 2.70 +$(cat ${wok}/${pkg}/receip | receip_highlighter) 2.71 +</pre> 2.72 +EOT 2.73 + html_footer && exit 0 ;; 2.74 + 2.75 + *\ upload\ *) 2.76 + # HTML Form: use cloud plugin CSS style 2.77 + header 2.78 + html_header 2.79 + user_box 2.80 + if ! check_auth; then 2.81 + header "Location: $HTTP_REFERER" 2.82 + fi 2.83 + d="SUP Upload" 2.84 + cat << EOT 2.85 +<h2>${d}</h2> 2.86 +<p> 2.87 + $(gettext "User:") <a href="?user=$user">$user</a> - Mail: $MAIL 2.88 +</p> 2.89 + 2.90 +<div id="cloud-upload"> 2.91 + 2.92 + <form method="post" 2.93 + action="plugins/sup/sup.cgi?sup=supQA&user=$user&mail=$MAIL" 2.94 + enctype="multipart/form-data"> 2.95 + <input type="file" name="supfile" size="150" /> 2.96 + <input type="submit" value="Upload" /> 2.97 + </form> 2.98 + 2.99 +</div> 2.100 +EOT 2.101 + html_footer && exit 0 ;; 2.102 + 2.103 + *\ supQA\ *) 2.104 + # SUP Upload Quality assurance. Check package in cache before 2.105 + # publishing. We need full path for upload to work ../../ 2.106 + # 2.107 + # This is the geeky part for users, QA output in cmdline style 2.108 + # and to be transparent on what is going on :-) 2.109 + # 2.110 + header 2.111 + d="SUP Upload QA" 2.112 + supfile=$(FILE supfile name) 2.113 + tmpfile=$(FILE supfile tmpname) 2.114 + wok="$scn/content/sup/wok" 2.115 + packages="$scn/content/sup/packages" 2.116 + cache="$scn/cache/sup/${supfile%.sup}" 2.117 + pkgsdb="$scn/content/sup/packages/packages.db" 2.118 + suplog="$scn/cache/log/sup.log" 2.119 + error=0 2.120 2.121 + # Use COOKIE to make sure user is logged in SCN/SUP Hub 2.122 + user="$(echo $(COOKIE auth) | cut -d ':' -f 1)" 2.123 + if [ "$(COOKIE auth)" ] && [ "$user" != "$(GET user)" ]; then 2.124 + echo "<pre>ERROR: user auth cookie</pre>" && exit 1 2.125 + fi 2.126 + 2.127 + #if [ ! -f "$pkgsdb" ]; then 2.128 + #echo "<pre>ERROR: missing $pkgsdb</pre>" && exit 1 2.129 + #fi 2.130 + 2.131 + cat << EOT 2.132 +<!DOCTYPE html> 2.133 +<html lang="en"> 2.134 +<head> 2.135 + <meta charset="utf-8" /> 2.136 + <title>$d</title> 2.137 + <link rel="stylesheet" type="text/css" href="${host}style.css" /> 2.138 + <style type="text/css">body { margin: 40px 80px; }</style> 2.139 +</head> 2.140 +<body> 2.141 +<h2>$d</h2> 2.142 +<pre> 2.143 +SUP Hub user : <a href="${host}?user=$user">$user</a> 2.144 +Package file : ${supfile} 2.145 +EOT 2.146 + mkdir -p ${cache} 2.147 + if ! mv -f ${tmpfile} ${cache}/${supfile}; then 2.148 + echo "<span class='error'>ERROR moving: ${tmpfile} to ${supfile}</span></pre>" 2.149 + rm -rf ${cache} $(dirname $tmpfile) && exit 1 2.150 + fi 2.151 + 2.152 + # Show MD5sum 2.153 + echo -e "MD5sum : $(md5sum $cache/$supfile | cut -d ' ' -f 1)\n" 2.154 + 2.155 + # Extract receip: sup cook already check vor empty var. Make 2.156 + # sure SCN user name match package MAINTAINER. 2.157 + gettext "Extracting receip..." 2.158 + cd ${cache} 2.159 + cpio -i receip --quiet < ${supfile} 2.160 + status 2.161 + 2.162 + if ! . receip; then 2.163 + echo "<span class='error'>ERROR: Can't source receip</span></pre>" 2.164 + rm -rf ${cache} $(dirname $tmpfile) && exit 1 2.165 + fi 2.166 + echo "build_date: $build_date" 2.167 + 2.168 + # README 2.169 + gettext "Checking for a README file..." 2.170 + cpio -i README --quiet < ${supfile} 2.171 + if [ -f "README" ]; then 2.172 + echo " <span class='color32'>$(gettext 'yes')</span>" 2.173 + else 2.174 + echo " <span class='value'>$(gettext 'no')</span>" 2.175 + fi 2.176 + 2.177 + # Logged user is maintainaer ? 2.178 + if [ "$MAINTAINER" != "$(GET mail)" ]; then 2.179 + error=1 2.180 + echo -e "\n<span class='error'>WARNING: user mail not matching</span>" 2.181 + gettext "User mail :"; echo " $(GET mail)" 2.182 + gettext "MAINTAINER :"; echo " $MAINTAINER" 2.183 + fi 2.184 + 2.185 + # Publish and display pkg url's if no error 2.186 + if [ "$error" == "0" ]; then 2.187 + gettext "Moving package to mirror..." 2.188 + mv -f ${supfile} ${packages}; status 2.189 + gettext "Moving receip to public wok..." 2.190 + mkdir -p ${wok}/${PACKAGE} && mv -f receip ${wok}/${PACKAGE} 2.191 + status 2.192 + 2.193 + # Handle packages.md5 2.194 + 2.195 + 2.196 + # Log activity date|user|mail|pkg|version|short_desc 2.197 + cat >> ${suplog} << EOT 2.198 +$(date '+%Y-%m-%d %H:%M')|$user|$MAINTAINER|$PACKAGE|$VERSION|$SHORT_DESC 2.199 +EOT 2.200 + echo "</pre><p> 2.201 +Package page: <a href='${host}?sup=pkg&name=$PACKAGE'>$PACKAGE $VERSION</a>" 2.202 + else 2.203 + echo "</pre> 2.204 +<a href='${host}?sup=upload'>SUP Upload page</a>" 2.205 + # Show receip on error 2.206 + echo "<h2>receip</h2>" 2.207 + echo "<pre>" 2.208 + cat ${cache}/receip | receip_highlighter 2.209 + echo "</pre>" 2.210 + fi 2.211 + # HTML Footer 2.212 + echo "</p> 2.213 + </body> 2.214 +</html>" 2.215 + rm -rf ${cache} $(dirname $tmpfile) && exit 0 ;; 2.216 + 2.217 + *\ admin\ *) 2.218 + # Admin tools: gen packages.md5 for the mirror, clean any buggy 2.219 + # or corrupted packages in wok. 2.220 + d="SUP Hub admin" 2.221 + header 2.222 + html_header 2.223 + user_box 2.224 + if ! check_auth && admin_user; then 2.225 + echo "Only for admins" && html_footer && exit 0 2.226 + fi 2.227 cat << EOT 2.228 <h2>${d}</h2> 2.229 <div id="tools"> 2.230 - <a href='?sup'>Sup hub</a> 2.231 -EOT 2.232 - if check_auth; then 2.233 - cat << EOT 2.234 - <a href='?sup=debug'>Sup debug</a> 2.235 -EOT 2.236 - fi 2.237 - #. ${wok}/${pkg}/receip 2.238 - cat << EOT 2.239 -</div> 2.240 - 2.241 -<pre> 2.242 -$(cat ${wok}/${pkg}/receip ) 2.243 -</pre> 2.244 -EOT 2.245 - 2.246 - html_footer && exit 0 ;; 2.247 - 2.248 - *\ debug\ *) 2.249 - d="Sup server debug" 2.250 - header 2.251 - html_header 2.252 - user_box 2.253 - cat << EOT 2.254 -<h2>${d}</h2> 2.255 -<div id="tools"> 2.256 - <a href='?sup'>Sup hub</a> 2.257 + <a href="?sup=upload">Upload package</a> 2.258 </div> 2.259 EOT 2.260 - if ! check_auth; then 2.261 - echo "Only for logged users" && html_footer && exit 0 2.262 - fi 2.263 echo "<pre>" 2.264 echo "Checking: $content/sup/wok" 2.265 for pkg in $(ls $content/sup/wok); do 2.266 @@ -64,31 +236,71 @@ 2.267 html_footer && exit 0 ;; 2.268 2.269 *\ sup\ *) 2.270 - d="SliTaz User Packages" 2.271 - supdb="$content/sup" 2.272 - wok="$supdb/wok" 2.273 + d="SliTaz User Packages Hub" 2.274 header 2.275 html_header 2.276 user_box 2.277 + echo "<h2>${d}</h2>" 2.278 + # Tools for logged users and admins 2.279 + if check_auth; then 2.280 + if admin_user; then 2.281 + tools='<a href="?sup=admin">Admin tools</a>' 2.282 + fi 2.283 + cat << EOT 2.284 +<div id="tools"> 2.285 + <a href="?sup=upload">Upload package</a> 2.286 + $tools 2.287 +</div> 2.288 +EOT 2.289 + fi 2.290 cat << EOT 2.291 -<h2>${d}</h2> 2.292 <p> 2.293 - SliTaz User Packages server services. In developement :-) 2.294 + SliTaz User Packages services: Beta :-) 2.295 </p> 2.296 2.297 <pre> 2.298 Packages : $(ls $wok | wc -l) 2.299 -Mirror : <a href="$content/sup/packages/">Browse packages</a> 2.300 -Tools : <a href="?sup=debug">Debug page</a> 2.301 +Mirror : <a href="$packages/">Browse</a> 2.302 </pre> 2.303 +<h3>$(gettext "Latest uploads")</h3> 2.304 +<pre> 2.305 EOT 2.306 - # Packages list 2.307 - echo "<h3>Sup packages</h3>" 2.308 - echo "<pre>" 2.309 - for pkg in $(ls $content/sup/wok); do 2.310 - echo "<a href='?sup=pkg&name=$pkg'>$pkg</a>" 2.311 + IFS="|" 2.312 + tac ${suplog} | head -n 6 | while read date user mail pkg version short_desc 2.313 + do 2.314 + cat << EOT 2.315 +<a href="?user=$user">$(get_gravatar $mail 20)</a> \ 2.316 +<span class="date">$(echo $date | cut -d " " -f 1)</span> \ 2.317 +<a href="?sup=pkg&name=$pkg">$pkg $version</a> - \ 2.318 +$(echo ${short_desc} | cut -c 1-34)... 2.319 +EOT 2.320 done 2.321 + unset IFS 2.322 echo "</pre>" 2.323 + 2.324 + # Packages list: if one day, too much packages, then this should 2.325 + # move to ?sup=list 2.326 + cat << EOT 2.327 +<h3>$(gettext "SUP packages")</h3> 2.328 +<div id="plugins"> 2.329 +<table> 2.330 + <thead> 2.331 + <td>$(gettext "Package name")</td> 2.332 + <td>$(gettext "Version")</td> 2.333 + <td>$(gettext "Short description")</td> 2.334 + </thead> 2.335 +EOT 2.336 + for pkg in $(ls $wok); do 2.337 + . ${wok}/${pkg}/receip 2.338 + cat << EOT 2.339 + <tr> 2.340 + <td><a href='?sup=pkg&name=$pkg'>$pkg</a></td> 2.341 + <td>$VERSION</td> 2.342 + <td>$SHORT_DESC</td> 2.343 + </tr> 2.344 +EOT 2.345 + done 2.346 + echo "</table></div>" 2.347 html_footer && exit 0 ;; 2.348 2.349 esac
3.1 --- a/server/sup/sup.conf Sun Feb 26 22:38:12 2017 +0100 3.2 +++ b/server/sup/sup.conf Mon Feb 27 12:16:46 2017 +0100 3.3 @@ -5,9 +5,9 @@ 3.4 MAINTAINER="devel@slitaz.org" 3.5 3.6 # Authenticated users 3.7 -PLUGINS_TOOLS="${PLUGINS_TOOLS} <a href='?sup'>Sup hub</a>" 3.8 -DASHBOARD_TOOLS="${DASHBOARD_TOOLS} <a href='?sup'>Sup hub</a>" 3.9 -PROFILE_TOOLS="${PROFILE_TOOLS}" 3.10 +PLUGINS_TOOLS="${PLUGINS_TOOLS} <a href='?sup'>Sup Hub</a>" 3.11 +DASHBOARD_TOOLS="${DASHBOARD_TOOLS} <a href='?sup'>Sup Hub</a>" 3.12 +PROFILE_TOOLS="${PROFILE_TOOLS} <a href='?sup'>Sup Hub</a>" 3.13 3.14 # Admin only in Dashboard 3.15 ADMIN_TOOLS="${ADMIN_TOOLS}"
4.1 --- a/sup Sun Feb 26 22:38:12 2017 +0100 4.2 +++ b/sup Mon Feb 27 12:16:46 2017 +0100 4.3 @@ -152,7 +152,8 @@ 4.4 done 4.5 4.6 # Add $build_date 4.7 - echo "build_date=\"$(date "+%Y-%m-%d %H:%M")\"" >> ${receip} 4.8 + sed -i "/^build_date=/"d receip 4.9 + echo "build_date=\"$(date "+%Y-%m-%d %H:%M")\"" >> receip 4.10 4.11 gettext "Creating compressed archive..." 4.12 find files | cpio -o -H newc --quiet | lzma e files.lzma -si 4.13 @@ -162,7 +163,6 @@ 4.14 4.15 size="$(du -sh $cooked/$supfile | cut -d " " -f 1)" 4.16 echo "$(gettext 'Packages:') $(colorize 33 $supfile) ($size)" 4.17 - sed -i "/^build_date=/"d ${receip} 4.18 rm -rf ${cache} && newline ;; 4.19 4.20 -n|new)