#!/bin/sh # Copyright (C) 2008 Emmanuel Varoquaux # This file is part of XOS. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see . usage() { echo "Usage: $0 [OPTION]... setup|clean|publish|publish-html ..." echo echo "Mandatory arguments to long options are mandatory for short options too." echo " -h, --help display this help and exit" echo echo "Commands are:" echo " setup - create the website file tree structure and copy static files" echo " clean - remove the website file tree" echo " publish [files]... - upload the files to the ftp repository" echo " publish-html - like publish but upload only generated files" echo " validate-html page... - validate published html pages" echo " validate-css sheet... - validate published stylesheets" return 0 } attachnotice() { TMPFILE=`mktemp` trap "rm -f $TMPFILE" EXIT if [ "$3" ] && sed -n "1p" "$2" | grep "$3" >/dev/null; then sed -n "1p" "$2" >>$TMPFILE cat "$1" >>$TMPFILE sed -n "1!p" "$2" >>$TMPFILE else cat "$1" >>$TMPFILE if [ -s "$2" ]; then echo >>$TMPFILE cat "$2" >>$TMPFILE fi fi cp $TMPFILE "$2" rm $TMPFILE trap - EXIT return 0 } count() { find $@ -name "*\.[cSh]" -o -name "*.asm" | xargs wc -l | tail -n1 | sed "s/total//" | xargs echo return 0 } args=`getopt -o h -l help -n "$0" -- "$@"` status=$? if [ $status != 0 ]; then case $status in 1) echo "Try \`$0 --help' for more information." >/dev/stderr exit 1 ;; *) exit 1 esac fi eval set -- "$args" while true; do case "$1" in -h|--help) usage exit 0 ;; --) shift break ;; *) exit 1 esac done if [ -z "$1" ]; then usage >/dev/stderr exit 1 fi set -e . ./setenv case "$1" in setup) mkdir -p www echo "Installing PEAR..." tar xzf ext/PEAR-1.7.2.tgz -C www --strip 1 PEAR-1.7.2/PEAR.php mkdir -p www/Text tar xzf ext/Text_Highlighter-0.7.1.tgz -C www/Text --strip 1 rm -rf www/src mkdir www/src ( cd www/src echo "Exporting source code..." cvs -Q export -r LAST_RELEASE xos echo "Adding license notices..." cp ../../license/COPYING xos for file in `find xos -path "xos/website/license" -prune -o -type f -print`; do FILENAME=`basename $file` if echo $FILENAME | grep "\.[chS]$" >/dev/null; then attachnotice ../../license/notice.c $file "^[[:blank:]]*/\*[^*]*\*\([^/][^*]*\*\)*/[[:blank:]]*$" elif echo $FILENAME | grep "\.asm$" >/dev/null; then attachnotice ../../license/notice.asm $file elif echo $FILENAME | grep "\.xml$" >/dev/null; then attachnotice ../../license/notice.xml $file "^[[:blank:]]*/dev/null; then attachnotice ../../license/notice.xml $file "^[[:blank:]]*/dev/null; then attachnotice ../../license/notice.php $file elif echo $FILENAME | grep "\.css$" >/dev/null; then attachnotice ../../license/notice.css $file elif echo $FILENAME | grep "\.sh$" >/dev/null; then attachnotice ../../license/notice.sh $file "^#\!" elif echo $FILENAME | grep "^Makefile$" >/dev/null; then attachnotice ../../license/notice.mk $file fi done echo "Packaging source code..." tar czf xos.tar.gz xos echo "Computing statistics..." system_lines=`count xos/boot xos/common/include xos/drivers xos/fs xos/include xos/init xos/kernel xos/mm xos/startup` user_lines=`count xos/usr` tools_lines=`count xos/tools` total_lines=$(($system_lines+$user_lines+$tools_lines)) echo $system_lines $user_lines $tools_lines $total_lines >count.txt ) mkdir -p www/images mkdir -p www/css exit 0 ;; clean) rm -rf www exit 0 ;; publish) shift [ -z "$*" ] && set www ( cd www for file in "$@"; do local_file=`echo $file | sed -nr "s/^www(\/|$)/.\1/p"` [ "$local_file" ] && ncftpput -f ../login.cfg -R -m $REMOTE_DIR/`dirname $local_file` "$local_file" done ) exit 0 ;; publish-html) shift ( cd www local_files=`find -mindepth 1 -maxdepth 1 ! -path ./PEAR.php -a ! -path ./Text -a ! -path ./src` [ "$local_files" ] && ncftpput -f ../login.cfg -R -m $REMOTE_DIR $local_files ) exit 0 ;; validate-html) shift if [ -z "$*" ]; then usage >/dev/stderr exit 1 fi err=0 while [ "$1" ]; do status=`wget -q --save-headers -O - "http://validator.w3.org/check?uri=http://$HOST/$REMOTE_DIR/$1" | sed -n "s/^[[:blank:]]*X-W3C-Validator-Status:[[:blank:]]*\([[:alnum:]]*\)[[:space:]]*/\1/p"` echo "$1: $status" if [ "$status" = "Invalid" ]; then err=1 fi shift done [ $err -eq 0 ] exit ;; validate-css) shift if [ -z "$*" ]; then usage >/dev/stderr exit 1 fi err=0 while [ "$1" ]; do status=`wget -q --save-headers -O - "http://jigsaw.w3.org/css-validator/validator?uri=http://$HOST/$REMOTE_DIR/$1" | sed -n "s/^[[:blank:]]*X-W3C-Validator-Status:[[:blank:]]*\([[:alnum:]]*\)[[:space:]]*/\1/p"` if [ "$status" != "Valid" ]; then err=1 if [ -n $status ]; then status="?" fi fi echo "$1: $status" shift done [ $err -eq 0 ] exit ;; *) echo "$0: invalid command: $1" >/dev/stderr echo "Try \`$0 --help' for more information." >/dev/stderr exit 1 esac