NEWS[4.18.0rc4]: Samba 4.18.0rc4 Available for Download
[samba-web.git] / import_oldnews.sh
1 #!/bin/sh
2 #
3
4 LC_ALL=C
5 export LC_ALL
6 LANG=C
7 export LANG
8 LANGUAGE=C
9 export LANGUAGE
10
11 set -u
12 set -e
13 umask 0022
14
15 HEADLINES=${1}
16 BODIES=${2}
17
18 LINES="$(cat ${HEADLINES} | grep '<li>')"
19 NLINES=$(echo "${LINES}" | wc -l)
20
21 BODYH5="$(grep --line-number '<h5>' ${BODIES})"
22
23 for i in $(seq 1 $NLINES); do
24         l=$(echo "${LINES}" | head -${i} | tail -1 | sed -e 's!^[\t ]*!!')
25         d=$(echo "${l}" | sed -e 's!^<li>\([^<]*\)<a href=.*!\1!')
26         n=$(echo "${l}" | sed -e 's!.*a href="#\([^"]*\)".*!\1!')
27         utctime=$(date --date="${d}" --utc +"%Y%m%d-%H%M%S")
28         headlinefile="posted_news/${utctime}.${n}.headline.html"
29         bodyfile="posted_news/${utctime}.${n}.body.html"
30         echo "${i}: ${headlinefile}"
31         {
32                 echo "<!-- BEGIN: ${headlinefile} -->"
33                 echo "${l}"
34                 echo "<!-- END: ${headlinefile} -->"
35         } > ${headlinefile}
36
37         boundary=$(echo "${BODYH5}" | grep -A1 "<h5><a name=\"${n}\">" | cut -d ':' -f1)
38         tmp=$(echo "${boundary}" | wc -l)
39         case "${tmp}" in
40         2)
41                 begin=$(echo "${boundary}" | head -1)
42                 next=$(echo "${boundary}" | tail -1)
43                 end=$(expr ${next} - 1)
44                 len=$(expr ${end} - ${begin})
45                 ;;
46         1)
47                 len="10000"
48                 ;;
49         *)
50                 echo "invalid boundary:"
51                 echo "${boundary}"
52                 exit 1
53                 ;;
54         esac
55         echo "${i}: ${bodyfile}"
56         {
57                 echo "<!-- BEGIN: ${bodyfile} -->"
58                 grep -A${len} "<h5><a name=\"${n}\">" ${BODIES}
59                 echo "<!-- END: ${bodyfile} -->"
60         } > ${bodyfile}
61 done