some input sanitizing
[pb.git] / pb
1 #!/bin/sh
2
3 # pinosaur's blog script
4
5 blog_index_file="blogindex.html"
6 rolling_file="rolling.html"
7 template_file="template.html"
8 rss_file="rss.xml"
9 data_dir="blog"
10
11 [ ! -z "$EDITOR" ] && EDITOR="vim"
12
13
14 init() {
15     echo 1
16 }
17
18 refresh() {
19     echo 1
20     # add a confirmation of sorts here
21 }
22
23 new() {
24     [ -z "$1" ] && echo "please supply a name" && exit 1 
25
26     # sanitize input
27     sanitized=`echo -n "$1" | sed -e 's/[^A-Za-z0-9 _-]//g'| sed -e 's/ /-/g'`
28
29     # open in editor
30     $EDITOR "$data_dir/drafts/$sanitized"
31
32 }
33
34 publish() {
35     "Select which post to publish"
36     ls -1 "$data_dir/drafts" | nl 
37
38     read -p '> ' choice
39     to_publish=`ls -1 "$data_dir/drafts/" | sed -n "$choice p"`
40     [ -z "$to_publish" ] && echo "Invalid choice" && exit 1
41
42
43 }
44
45 delete() {
46     echo "Select which post to delete"
47     ls -1 "$data_dir/published" | nl 
48 }
49
50 # check to see if all required files are present
51 [ ! -f $blog_index_file ] && echo "missing $blog_index_file" && exit 1
52 [ ! -f $rolling_file ] && echo "missing $rolling_file" && exit 1
53 [ ! -f $template_file ] && echo "missing $template_file" && exit 1
54 [ ! -f $rss_file ] && echo "missing $rss_file" && exit 1
55
56 # possibly also check to see if index and rolling have the proper headers
57
58
59 # check if blog dir exists
60 [ ! -d $data_dir ] && echo "initing blog" &&\
61     mkdir -p "$data_dir/drafts" &&\
62     mkdir -p "$data_dir/published" &&\
63     touch "$data_dir/database" 
64
65 case $1 in
66     i|init) echo "init";;
67     n|new) new "$2";;
68     p|publish) publish;;
69     d|delete) echo "delete";;
70     r|refresh) echo "refresh";;
71     *) echo "helper" && exit 1;;
72 esac
73