seb rev 24
Add a CGI web frontend
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Sun Mar 12 04:47:04 2017 +0100 (2017-03-12) |
parents | 33509acd039d |
children | 0fd432698aaf |
files | libseb.sh seb tools/web/httpd.conf tools/web/seb.cgi |
line diff
1.1 --- a/libseb.sh Wed Mar 08 19:55:08 2017 +0000 1.2 +++ b/libseb.sh Sun Mar 12 04:47:04 2017 +0100 1.3 @@ -17,9 +17,20 @@ 1.4 1.5 # Exit if command returns 1 1.6 check() { 1.7 - case "$?" in 1.8 - 0) info 32 "Done" ;; 1.9 - 1) colorize 31 "--> Error" && exit 1 ;; 1.10 + local code="$?" 1.11 + case "$output" in 1.12 + html) 1.13 + case "$code" in 1.14 + 0) echo " <span style='color: green;'>Done</span>" ;; 1.15 + 1) 1.16 + echo " <span style='color: red;'>--> Error</span>" 1.17 + exit 1 ;; 1.18 + esac ;; 1.19 + *) 1.20 + case "$code" in 1.21 + 0) info 32 "Done" ;; 1.22 + 1) colorize 31 "--> Error" && exit 1 ;; 1.23 + esac ;; 1.24 esac 1.25 } 1.26 1.27 @@ -41,7 +52,10 @@ 1.28 indent() { 1.29 local in="$1" 1.30 shift 1.31 - echo -e "\033["${in}"G $@"; 1.32 + case "$output" in 1.33 + html) echo ": $@" ;; 1.34 + *) echo -e "\033["${in}"G $@" ;; 1.35 + esac 1.36 } 1.37 1.38 # Display a bold message 1.39 @@ -56,27 +70,43 @@ 1.40 colorize() { 1.41 : ${color=$1} 1.42 shift 1.43 - case "$color" in 1.44 - 0*) echo -e "\\033[${color:-38}m$@\\033[39m" ;; 1.45 - *) echo -e "\\033[1;${color:-38}m$@\\033[0;39m" ;; 1.46 + case "$output" in 1.47 + html|raw) echo "$@" ;; 1.48 + *) 1.49 + case "$color" in 1.50 + 0*) echo -e "\\033[${color:-38}m$@\\033[39m" ;; 1.51 + *) echo -e "\\033[1;${color:-38}m$@\\033[0;39m" ;; 1.52 + esac ;; 1.53 esac; unset color 1.54 } 1.55 1.56 # Last command status 1.57 status() { 1.58 local code="$?" 1.59 - case "$code" in 1.60 - 0) indent $(($(get_cols) - 11)) "[ $(colorize 32 'Done') ]" ;; 1.61 - 1) indent $(($(get_cols) - 11)) "[ $(colorize 31 'Fail') ]" ;; 1.62 + case "$output" in 1.63 + html) 1.64 + case "$code" in 1.65 + 0) echo " <span style='color: green;'>Done</span>" ;; 1.66 + 1) echo " <span style='color: red;'>Fail</span>" ;; 1.67 + esac ;; 1.68 + *) 1.69 + case "$code" in 1.70 + 0) info 32 "Done" ;; 1.71 + 1) info 31 "Fail" ;; 1.72 + esac ;; 1.73 esac 1.74 } 1.75 1.76 # Print info a la status way: info [color] [content] 1.77 info() { 1.78 local info="$2" 1.79 - local char="$(echo $info | wc -L)" 1.80 - local in=$((7 + ${char})) 1.81 - indent $(($(get_cols) - ${in})) "[ $(colorize $1 $info) ]" 1.82 + case "$output" in 1.83 + html) echo " <span class='info'>$info</span>" ;; 1.84 + *) 1.85 + local char="$(echo $info | wc -L)" 1.86 + local in=$((7 + ${char})) 1.87 + indent $(($(get_cols) - ${in})) "[ $(colorize $1 $info) ]" ;; 1.88 + esac 1.89 } 1.90 1.91 # Line separator
2.1 --- a/seb Wed Mar 08 19:55:08 2017 +0000 2.2 +++ b/seb Sun Mar 12 04:47:04 2017 +0100 2.3 @@ -15,6 +15,7 @@ 2.4 [ "$work" ] || work="$(pwd)" 2.5 [ "$iso" ] || iso="seb-os-$(date '+%Y%m%d').iso" 2.6 [ "$linux" ] || linux="/boot/vmlinuz-$(uname -r)" 2.7 +[ "$port" ] || port="8940" 2.8 2.9 rootfs="$work/rootfs" 2.10 rootiso="$work/rootiso" 2.11 @@ -67,12 +68,14 @@ 2.12 -l lsfs List all files in rootfs (-type f) 2.13 -v vdisk Create, mount or unmount a virtual disk 2.14 -e emu Emulate ISO image with Qemu 2.15 + -w web Start seb graphical web interface 2.16 env Print current seb environment 2.17 2.18 $(boldify "Options:") 2.19 --work= Path to build directory 2.20 --iso= Specify SliTaz Embedded ISO image name 2.21 --linux= Path to a custom Linux kernel 2.22 + --port= Httpd port for the web interface 2.23 --all Clean all files including sebfs 2.24 --emu Emulate ISO image after build 2.25 --check Check a virtual disk image 2.26 @@ -204,7 +207,7 @@ 2.27 "/lib/libresolv*" "/lib/libpthread*" "/lib/libdl*" 2.28 2.29 # Busybox applets 2.30 - action "Installing: busybox" 2.31 + echo -n "Installing: busybox" 2.32 cp -a /bin/busybox ${rootfs}/bin 2.33 chroot ${rootfs} /bin/busybox --install -s; check 2.34 2.35 @@ -221,7 +224,7 @@ 2.36 dumpkmap > ${rootfs}/usr/share/kmap/default; check 2.37 2.38 # Kilo editor (20K) with syntax highlight and search (Thanks Paul :-) 2.39 - action "Installing: kilo text editor" 2.40 + echo -n "$(colorize 034 'Installing: kilo text editor')" 2.41 cp -a ${tools}/kilo ${rootfs}/usr/bin; check 2.42 2.43 # Ncursesw && dialog for sebos and additional tools 2.44 @@ -233,7 +236,7 @@ 2.45 # /lib/libseb.sh & sebos config tool 2.46 echo -n "Installing: /lib/libseb.sh" 2.47 cp ${libseb} ${rootfs}/lib; check 2.48 - action "Installing: sebos config tool" 2.49 + echo -n "$(colorize 034 'Installing: sebos config tool')" 2.50 cp ${tools}/sebos ${rootfs}/usr/bin; check 2.51 2.52 # httphelper.sh for amazing CGI/Shell functions 2.53 @@ -286,7 +289,7 @@ 2.54 chmod 0600 ${rootfs}/etc/busybox.conf 2.55 2.56 # Rootfs archive: lzma e -si -so 2.57 - action "Creating the initramfs..." 2.58 + echo -n "$(colorize 034 'Creating the initramfs...')" 2.59 cd ${rootfs} 2.60 find . -print | cpio -o -H newc | xz -9 --format=lzma \ 2.61 > ${rootiso}/boot/rootfs.xz 2>/dev/null 2.62 @@ -381,7 +384,7 @@ 2.63 else 2.64 echo "Creating virtual disk image..." 2.65 dd if=/dev/zero of=${vdisk} bs=1M count=${vsize} 2.66 - action "Creating ext3 filesystem..."; echo 2.67 + colorize 034 "Creating ext3 filesystem..." 2.68 mkfs.ext3 -L "SebOShome" ${vdisk} 2.69 fi 2.70 2.71 @@ -445,6 +448,26 @@ 2.72 title "Emulating: $iso" 2.73 emulate ${work}/${iso} 2.74 footer ;; 2.75 + 2.76 + -w|web) 2.77 + pid=$(ps | grep 8940 | grep -v grep | awk '{print $1}') 2.78 + if [ "$stop" ] && [ "$pid" ]; then 2.79 + echo -n "Stopping Web interface... pid:" 2.80 + kill ${pid}; info 035 "$pid"; exit 0 2.81 + fi 2.82 + # Need the cgi script in server root 2.83 + if [ ! -f "$work/seb.cgi" ]; then 2.84 + cp ${tools}/web/seb.cgi . 2.85 + fi 2.86 + if [ "$pid" ]; then 2.87 + echo -n "Web interface is already running with pid:" 2.88 + info 035 "$pid" 2.89 + else 2.90 + echo -n "Starting web interface on port:"; info 035 "$port" 2.91 + httpd -p ${port} -u 0:0 -h ${work} \ 2.92 + -c ${tools}/web/httpd.conf 2.93 + fi 2.94 + tazweb --notoolbar http://localhost:${port}/ & ;; 2.95 2.96 env) 2.97 title "SEB environment" 2.98 @@ -465,8 +488,12 @@ 2.99 footer ;; 2.100 2.101 -t|testsuite) 2.102 - # Development purpose 2.103 - ${tools}/libseb.sh ;; 2.104 + # Development/debug purpose 2.105 + if [ -x "./libseb.sh" ]; then 2.106 + ./libseb.sh 2.107 + else 2.108 + /lib/libseb.sh 2.109 + fi ;; 2.110 2.111 *) help ;; 2.112
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/tools/web/httpd.conf Sun Mar 12 04:47:04 2017 +0100 3.3 @@ -0,0 +1,6 @@ 3.4 +# Allow address 3.5 +A:0.0.0.0/0 3.6 +# CGI interpreter path 3.7 +*.cgi:/bin/sh 3.8 +# File to open by default 3.9 +I:seb.cgi
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/tools/web/seb.cgi Sun Mar 12 04:47:04 2017 +0100 4.3 @@ -0,0 +1,65 @@ 4.4 +#!/bin/sh 4.5 +# 4.6 +# seb.cgi: SliTaz Embedded Builder CGI interface. Invoking seb to build 4.7 +# a custom OS in the current dir or the one set in work= config variable. 4.8 +# The webserver must be run by root, so we use Busyboy httpd to serv on 4.9 +# a custom port and for localhost only (see seb httpd.conf). 4.10 +# 4.11 +# Example: # cd path/to/os; seb -w 4.12 +# 4.13 +. /usr/lib/slitaz/httphelper.sh 4.14 +header 4.15 + 4.16 +work="$(pwd)" 4.17 +export output=html 4.18 +. /lib/libseb.sh 4.19 + 4.20 +# Everything preformated, for a cmdline style output 4.21 +cat << EOT 4.22 +<!DOCTYPE html> 4.23 +<html> 4.24 +<head> 4.25 + <meta charset="utf-8" /> 4.26 + <title>SliTaz Embedded Builder</title> 4.27 + <style type="text/css"> 4.28 + h1 { color: #aaa; font-size: 140%; } .info { color: #800057; } 4.29 + hr { border: 1px solid #ddd; } 4.30 + </style> 4.31 +</head> 4.32 +<h1>SliTaz Embedded Builder</h1> 4.33 +<pre> 4.34 +<a href="./seb.cgi">Summary</a> \ 4.35 +<a href="./seb.cgi?build">Build</a> \ 4.36 +<a href="./seb.cgi?packages">Packages</a> \ 4.37 +<a href="./seb.cgi?emulate">Emulate</a> \ 4.38 +<a href="./seb.cgi?debug">Debug</a> \ 4.39 +<a href="./seb.cgi?help">Help</a> 4.40 + 4.41 +EOT 4.42 + 4.43 +case " $(GET) " in 4.44 + 4.45 + *\ help\ *) seb | sed '1,2d' ;; 4.46 + *\ build\ *) seb -b ;; 4.47 + *\ packages\ *) seb -p ;; 4.48 + *\ emulate\ *) seb -e ;; 4.49 + *\ debug\ *) seb env; seb testsuite ;; 4.50 + 4.51 + *) 4.52 + echo "Work path : <span class='info'>$work</span>" 4.53 + if [ -d "$work/rootfs" ]; then 4.54 + cat << EOT 4.55 +Rootfs size : <span class='info'>$(du -sh $work/rootfs | awk '{print $1}')</span> 4.56 +Rootiso size : <span class='info'>$(du -sh $work/rootiso | awk '{print $1}')</span> 4.57 +EOT 4.58 + else 4.59 + echo "Seb OS : No build yet!" 4.60 + fi ;; 4.61 +esac 4.62 + 4.63 +cat << EOT 4.64 +</pre> 4.65 +</body> 4.66 +</html> 4.67 +EOT 4.68 +exit 0