# HG changeset patch # User Christophe Lincoln # Date 1489290424 -3600 # Node ID 33333de28e7383f0cefadd90450bae168aa27998 # Parent 33509acd039ded600f17e464ed35bade0d6f178f Add a CGI web frontend diff -r 33509acd039d -r 33333de28e73 libseb.sh --- a/libseb.sh Wed Mar 08 19:55:08 2017 +0000 +++ b/libseb.sh Sun Mar 12 04:47:04 2017 +0100 @@ -17,9 +17,20 @@ # Exit if command returns 1 check() { - case "$?" in - 0) info 32 "Done" ;; - 1) colorize 31 "--> Error" && exit 1 ;; + local code="$?" + case "$output" in + html) + case "$code" in + 0) echo " Done" ;; + 1) + echo " --> Error" + exit 1 ;; + esac ;; + *) + case "$code" in + 0) info 32 "Done" ;; + 1) colorize 31 "--> Error" && exit 1 ;; + esac ;; esac } @@ -41,7 +52,10 @@ indent() { local in="$1" shift - echo -e "\033["${in}"G $@"; + case "$output" in + html) echo ": $@" ;; + *) echo -e "\033["${in}"G $@" ;; + esac } # Display a bold message @@ -56,27 +70,43 @@ colorize() { : ${color=$1} shift - case "$color" in - 0*) echo -e "\\033[${color:-38}m$@\\033[39m" ;; - *) echo -e "\\033[1;${color:-38}m$@\\033[0;39m" ;; + case "$output" in + html|raw) echo "$@" ;; + *) + case "$color" in + 0*) echo -e "\\033[${color:-38}m$@\\033[39m" ;; + *) echo -e "\\033[1;${color:-38}m$@\\033[0;39m" ;; + esac ;; esac; unset color } # Last command status status() { local code="$?" - case "$code" in - 0) indent $(($(get_cols) - 11)) "[ $(colorize 32 'Done') ]" ;; - 1) indent $(($(get_cols) - 11)) "[ $(colorize 31 'Fail') ]" ;; + case "$output" in + html) + case "$code" in + 0) echo " Done" ;; + 1) echo " Fail" ;; + esac ;; + *) + case "$code" in + 0) info 32 "Done" ;; + 1) info 31 "Fail" ;; + esac ;; esac } # Print info a la status way: info [color] [content] info() { local info="$2" - local char="$(echo $info | wc -L)" - local in=$((7 + ${char})) - indent $(($(get_cols) - ${in})) "[ $(colorize $1 $info) ]" + case "$output" in + html) echo " $info" ;; + *) + local char="$(echo $info | wc -L)" + local in=$((7 + ${char})) + indent $(($(get_cols) - ${in})) "[ $(colorize $1 $info) ]" ;; + esac } # Line separator diff -r 33509acd039d -r 33333de28e73 seb --- a/seb Wed Mar 08 19:55:08 2017 +0000 +++ b/seb Sun Mar 12 04:47:04 2017 +0100 @@ -15,6 +15,7 @@ [ "$work" ] || work="$(pwd)" [ "$iso" ] || iso="seb-os-$(date '+%Y%m%d').iso" [ "$linux" ] || linux="/boot/vmlinuz-$(uname -r)" +[ "$port" ] || port="8940" rootfs="$work/rootfs" rootiso="$work/rootiso" @@ -67,12 +68,14 @@ -l lsfs List all files in rootfs (-type f) -v vdisk Create, mount or unmount a virtual disk -e emu Emulate ISO image with Qemu + -w web Start seb graphical web interface env Print current seb environment $(boldify "Options:") --work= Path to build directory --iso= Specify SliTaz Embedded ISO image name --linux= Path to a custom Linux kernel + --port= Httpd port for the web interface --all Clean all files including sebfs --emu Emulate ISO image after build --check Check a virtual disk image @@ -204,7 +207,7 @@ "/lib/libresolv*" "/lib/libpthread*" "/lib/libdl*" # Busybox applets - action "Installing: busybox" + echo -n "Installing: busybox" cp -a /bin/busybox ${rootfs}/bin chroot ${rootfs} /bin/busybox --install -s; check @@ -221,7 +224,7 @@ dumpkmap > ${rootfs}/usr/share/kmap/default; check # Kilo editor (20K) with syntax highlight and search (Thanks Paul :-) - action "Installing: kilo text editor" + echo -n "$(colorize 034 'Installing: kilo text editor')" cp -a ${tools}/kilo ${rootfs}/usr/bin; check # Ncursesw && dialog for sebos and additional tools @@ -233,7 +236,7 @@ # /lib/libseb.sh & sebos config tool echo -n "Installing: /lib/libseb.sh" cp ${libseb} ${rootfs}/lib; check - action "Installing: sebos config tool" + echo -n "$(colorize 034 'Installing: sebos config tool')" cp ${tools}/sebos ${rootfs}/usr/bin; check # httphelper.sh for amazing CGI/Shell functions @@ -286,7 +289,7 @@ chmod 0600 ${rootfs}/etc/busybox.conf # Rootfs archive: lzma e -si -so - action "Creating the initramfs..." + echo -n "$(colorize 034 'Creating the initramfs...')" cd ${rootfs} find . -print | cpio -o -H newc | xz -9 --format=lzma \ > ${rootiso}/boot/rootfs.xz 2>/dev/null @@ -381,7 +384,7 @@ else echo "Creating virtual disk image..." dd if=/dev/zero of=${vdisk} bs=1M count=${vsize} - action "Creating ext3 filesystem..."; echo + colorize 034 "Creating ext3 filesystem..." mkfs.ext3 -L "SebOShome" ${vdisk} fi @@ -445,6 +448,26 @@ title "Emulating: $iso" emulate ${work}/${iso} footer ;; + + -w|web) + pid=$(ps | grep 8940 | grep -v grep | awk '{print $1}') + if [ "$stop" ] && [ "$pid" ]; then + echo -n "Stopping Web interface... pid:" + kill ${pid}; info 035 "$pid"; exit 0 + fi + # Need the cgi script in server root + if [ ! -f "$work/seb.cgi" ]; then + cp ${tools}/web/seb.cgi . + fi + if [ "$pid" ]; then + echo -n "Web interface is already running with pid:" + info 035 "$pid" + else + echo -n "Starting web interface on port:"; info 035 "$port" + httpd -p ${port} -u 0:0 -h ${work} \ + -c ${tools}/web/httpd.conf + fi + tazweb --notoolbar http://localhost:${port}/ & ;; env) title "SEB environment" @@ -465,8 +488,12 @@ footer ;; -t|testsuite) - # Development purpose - ${tools}/libseb.sh ;; + # Development/debug purpose + if [ -x "./libseb.sh" ]; then + ./libseb.sh + else + /lib/libseb.sh + fi ;; *) help ;; diff -r 33509acd039d -r 33333de28e73 tools/web/httpd.conf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/web/httpd.conf Sun Mar 12 04:47:04 2017 +0100 @@ -0,0 +1,6 @@ +# Allow address +A:0.0.0.0/0 +# CGI interpreter path +*.cgi:/bin/sh +# File to open by default +I:seb.cgi diff -r 33509acd039d -r 33333de28e73 tools/web/seb.cgi --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/web/seb.cgi Sun Mar 12 04:47:04 2017 +0100 @@ -0,0 +1,65 @@ +#!/bin/sh +# +# seb.cgi: SliTaz Embedded Builder CGI interface. Invoking seb to build +# a custom OS in the current dir or the one set in work= config variable. +# The webserver must be run by root, so we use Busyboy httpd to serv on +# a custom port and for localhost only (see seb httpd.conf). +# +# Example: # cd path/to/os; seb -w +# +. /usr/lib/slitaz/httphelper.sh +header + +work="$(pwd)" +export output=html +. /lib/libseb.sh + +# Everything preformated, for a cmdline style output +cat << EOT + + + + + SliTaz Embedded Builder + + +

SliTaz Embedded Builder

+
+Summary \
+Build \
+Packages \
+Emulate \
+Debug \
+Help
+
+EOT
+
+case " $(GET) " in
+
+	*\ help\ *)      seb | sed '1,2d' ;;
+	*\ build\ *)     seb -b ;;
+	*\ packages\ *)  seb -p ;;
+	*\ emulate\ *)   seb -e ;;
+	*\ debug\ *)     seb env; seb testsuite ;;
+	
+	*)
+		echo "Work path   : $work"
+		if [ -d "$work/rootfs" ]; then
+			cat << EOT
+Rootfs size  : $(du -sh $work/rootfs | awk '{print $1}')
+Rootiso size : $(du -sh $work/rootiso | awk '{print $1}')
+EOT
+		else
+			echo "Seb OS      : No build yet!"
+		fi ;;
+esac
+
+cat << EOT
+
+ + +EOT +exit 0