history: fix ü and ö in samba-4.3.0.html
[metze/test/samba-web.git] / prepare_news.sh
1 #!/bin/sh
2 #
3
4 SAVE_LC_ALL="${LC_ALL}"
5 SAVE_LANG="${LANG}"
6 SAVE_LANGUAGE="${LANGUAGE}"
7
8 LC_ALL=C
9 export LC_ALL
10 LANG=C
11 export LANG
12 LANGUAGE=C
13 export LANGUAGE
14
15 set -u
16 set -e
17 umask 0022
18
19 test -d ".git" || {
20         echo "Run this script from the top-level directory in the"
21         echo "repository"
22         exit 1
23 }
24
25 usage() {
26         echo "usage: $0 <NAME> <HEADLINE>"
27         echo ""
28         echo "This will open \$EDITOR in order to fill in the body content"
29         echo ""
30 }
31
32 test -n "${EDITOR-}" || {
33         usage
34         exit 1
35 }
36
37 NAME=${1-}
38 test -n "${NAME}" || {
39         usage
40         exit 1
41 }
42 shift 1
43 HEADLINE=$(echo "$@" | xargs)
44 test -n "${HEADLINE}" || {
45         usage
46         exit 1
47 }
48
49 grep -q "<a name=\"${NAME}\"" posted_news/*.body.html && {
50         echo "NAME[${NAME}] is not unique, choose another name"
51         grep "<a name=\"${NAME}\"" posted_news/*.body.html
52         exit 1
53 }
54
55 nd=$(git diff -p --stat HEAD | wc -l)
56 test x"${nd}" = x"0" || {
57         echo "You have uncommited changes your working tree"
58         git status
59         exit 1
60 }
61
62 trap_handler() {
63         echo ""
64         echo "ERROR: cleaning up"
65         echo ""
66
67         for f in ${CLEANUP_FILES}; do
68                 echo "Removing file[${f}]"
69                 test -f "${f}" && {
70                         rm "${f}" || {
71                                 echo "failed to remove ${f}"
72                         }
73                 }
74         done
75
76         test -n "${CLEANUP_RESET_COMMIT}" && {
77                 echo "Reverting to commit[${CLEANUP_RESET_COMMIT}]"
78                 git reset "${CLEANUP_RESET_COMMIT}"
79         }
80 }
81
82 CLEANUP_FILES=""
83 trap trap_handler INT QUIT TERM EXIT
84
85 href="#${NAME}"
86 utcdate=$(date --utc +"%d %B %Y")
87 utctime=$(date --utc +"%Y%m%d-%H%M%S")
88
89 headlinefile="posted_news/${utctime}.${NAME}.headline.html"
90 bodyfile="posted_news/${utctime}.${NAME}.body.html"
91 echo "generating ${headlinefile}"
92 CLEANUP_FILES="${CLEANUP_FILES} ${headlinefile}"
93 {
94         echo "<!-- BEGIN: ${headlinefile} -->"
95         echo "<li> ${utcdate} <a href=\"${href}\">${HEADLINE}</a></li>"
96         echo "<!-- END: ${headlinefile} -->"
97 } > ${headlinefile}
98
99 echo "generating ${bodyfile}"
100 CLEANUP_FILES="${CLEANUP_FILES} ${bodyfile}"
101 {
102         echo "<!-- BEGIN: ${bodyfile} -->"
103         echo "<h5><a name=\"${NAME}\">${utcdate}</a></h5>"
104         echo "<p class=headline>${HEADLINE}</p>"
105         echo "<p>"
106         echo "<!-- TODO: add your context here -->"
107         echo "</p>"
108         echo "<p>"
109         echo "<!-- TODO: add more context here -->"
110         echo "</p>"
111         echo "<!-- END: ${bodyfile} -->"
112 } > ${bodyfile}
113
114 LC_ALL="${SAVE_LC_ALL}" \
115 LANG="${SAVE_LANG}" \
116 LANGUAGE="${SAVE_LANGUAGE}" \
117 ${EDITOR} ${bodyfile}
118
119 CLEANUP_FILES=""
120 CLEANUP_RESET_COMMIT="HEAD"
121 git add ${headlinefile} ${bodyfile}
122 git commit --signoff --message "NEWS[${NAME}]: ${HEADLINE}"
123 CLEANUP_RESET_COMMIT="HEAD^"
124
125 echo "Once you have pushed the commit a cronjob updates"
126 echo "the webserver content every 5 mins."
127 echo ""
128 echo "Please verify the commit carefully before pushing:"
129 echo ""
130 echo "  git show -p --stat HEAD"
131 echo "  git push ..."
132 echo ""
133
134 trap - INT QUIT TERM EXIT
135 exit 0