]> pd.if.org Git - zpackage/blob - zpm-note
added program to output the elf type of a file
[zpackage] / zpm-note
1 #!/bin/sh
2
3 # Admin notes:
4
5 # Each note is just a file.  Stored under /var/spool/admin/notes/[open|ack]/<package>/<note>
6
7 # note: list notes
8 # note ack <note> - moves note to "acknowledged" spool
9 # note list [package] show notes for a given package, or all notes
10 # note delete <note> - delete a note from the system
11 # note edit <package> [file] - edit or create a note
12
13 SPOOL=/var/lib/admin/notes
14 OPEN=$SPOOL/open
15
16 set -e
17
18 umask 007
19
20 #cd $SPOOL || { echo "can't chdir to $SPOOL" ; exit 1; }
21
22 [ -z "$1" ] && set list
23
24 cmd=$1
25 shift
26
27 findnote() {
28         file=$(find $SPOOL -type f -name "$1")
29         if [ -z "$file" ] ; then
30                 printf "no such note $1\n"
31                 exit 1
32         fi
33         echo $file
34 }
35
36 findopen() {
37         file=$(find $SPOOL/open -type f -name "$1")
38         if [ -z "$file" ] ; then
39                 printf "no such open note $1\n"
40                 exit 1
41         fi
42         echo $file
43 }
44
45 case $cmd in
46         list)
47                 case $1 in
48                         -a) find $SPOOL/ack -type f -printf '%P\n' | sort -n
49                                 ;;
50                         *) find $SPOOL/open -type f -printf '%P\n' | sort -n
51                                 ;;
52                 esac
53                 ;;
54         detail)
55                 len=$(find $SPOOL/open -type f -printf "%P\n" | awk ' { if ( length > x ) { x = length } }END{ print x }')
56                 find $SPOOL/open -type f -printf "%P\n" | sort -n | while read note ; do
57                         subject=$(head -1 $SPOOL/open/$note)    
58                         date=$(stat -c '%y' $SPOOL/open/$note | cut -f1 -d' ')
59                         owner=$(stat -c '%U' $SPOOL/open/$note)
60                         printf '%*s %8s %s %s\n' $len $note $owner "$date" "$subject"
61                 done
62                 ;;
63         ack)
64                 file=$(findopen $1)
65                 subfile=$(echo $file | sed -e "s|$SPOOL/open/||")
66                 filedir=$(dirname $subfile)
67                 mkdir -p $SPOOL/ack/$filedir
68                 mv $file $SPOOL/ack/$filedir
69                 ;;
70         new)
71                 if [ $# -eq 1 ]; then set general $1; fi
72                 pkg=$1 ; shift
73                 mkdir -p $SPOOL/open/$pkg
74                 case $1 in
75                         '-')
76                                 tmp=$(mktemp -p $SPOOL/open)
77                                 cat - > $tmp
78                                 file=$(zpm sequence notes)
79                                 mv $tmp $SPOOL/open/$pkg/$file || { rm -f $tmp ; exit 1; }
80                                 echo created $file
81                                 ;;
82                         *)
83                                 tmp=$(mktemp -p $SPOOL/open)
84                                 cp $1 $tmp
85                                 #flock -n -E3 $tmp vim $tmp
86                                 #if [ $? -eq 3 ]; then echo already editing $1; exit 1; fi
87                                 file=$(zpm sequence notes)
88                                 mv $tmp $SPOOL/open/$pkg/$file || { rm -f $tmp; exit 1; }
89                                 echo created $file
90                                 ;;
91                 esac
92                 ;;
93         edit)
94                 file=$(findnote $1)
95                 flock -n -E3 $file vim $file
96                 if [ $? -eq 3 ]; then echo already editing $1; exit 1; fi
97                 ;;
98         remove)
99                 file=$(findnote $1)
100                 rm $file
101                 ;;
102         show)
103                 file=$(findnote $1)
104                 ${PAGER:-less} $file
105                 ;;
106         *)
107                 echo '$0: unknown command ' $cmd 1>&2
108                 exit 1
109 esac