OSDN Git Service

1.5.2-rc4
[pukiwiki/pukiwiki_devel.git] / tdiary-demogen.sh
1 #!/bin/sh
2 # $Id: tdiary-demogen.sh,v 1.7 2005/01/25 12:47:11 henoheno Exp $
3 #
4 # tDiary demonstration generator: generates many [theme].php
5 # License: GPL
6
7 warn(){ echo "$*" 1>&2; }
8 err(){ warn "$*"; exit 1; }
9
10 usage(){
11   base="`basename $0`";
12   warn "  $base [-d path/to/theme-directory] list"
13   warn "  $base [-d path/to/theme-directory] interwiki"
14   warn "  $base [-d path/to/theme-directory] touch"
15   warn "  $base [-d path/to/theme-directory] untouch"
16   warn "    Command:"
17   warn "      lis|list      - List themes"
18   warn "      int|interwiki - Publish interwiki definition and setting for each theme"
19   warn "      tou|touch     - Generate \$theme.php that includes index.php"
20   warn "      unt|untouch   - Remove \$theme.php(s) listed in theme directory"
21   exit 1
22 }
23
24 theme_list(){
25   cd "$dir" || err "Error: directory '$dir' not found"
26   ls -1 | while read theme; do
27     test -f "$theme/$theme.css" && echo "$theme"
28   done
29 }
30
31 # ---- Argument check ----
32 dir="skin/theme"
33 if [ "x-d" = "x$1" ] ; then
34   dir="$2"
35   shift 2
36 fi
37 cmd="$1"
38
39 # ----
40
41 case "$cmd" in
42 ''|-h|hel|help ) usage ;;
43 lis|list       ) theme_list ;;
44
45 int|inte|inter|interw|interwi|interwik|interwiki)
46   echo '--------'
47   echo '- [./$1.php theme] raw tDiary theme selector'
48   echo '--------'
49   echo '- (s) = sidebar CSS exists in this theme'
50   theme_list | while read theme; do
51     echo -n "+ [[theme:$theme]]"
52     grep -q div.sidebar "$dir/$theme/$theme.css" && echo -n " (s)"
53     echo
54   done
55   ;;
56
57 tou|touc|touch )
58   theme_list | while read theme; do
59     if [ -f "$theme.php" ]
60     then echo "Warning: '$theme.php' is already available. Ignoreing..."
61     else
62       cat <<EOF  > "$theme.php"
63 <?php
64         define('TDIARY_THEME', '$theme');
65         require('./index.php')
66 ?>
67 EOF
68     fi
69   done
70   ;;
71
72 unt|unto|untou|untouc|untouch )
73   echo -n "  Remove theme(s).php ? [y/N]: "
74   read answer
75   case "$answer" in
76   [yY] | [yY][eE][sS] )
77     theme_list | while read theme ; do
78       test -f "$theme.php" && grep -q "define('TDIARY_THEME', '$theme');" "$theme.php" && rm -f "$theme.php"
79     done
80     ;;
81   * )
82     echo "  Stopped."
83   esac
84   ;;
85 esac
86