~ubuntu-motd-azure-devs/ubuntu-motd-azure/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/sh

set -e

dmotd="$1"

ret=0

if [ -z "$dmotd" ]; then
    echo "Usage:"
    echo " $0 <dynamic motd news file>"
    exit 1
fi

if [ ! -s "$dmotd" ]; then
    echo "WARNING: $dmotd is zero-sized and will be ignored."
    exit 0
fi

lines=$(wc -l < "$dmotd")
if [ "$lines" -gt 10 ]; then
    echo "ERROR: $dmotd contains more than 10 lines ($lines)"
    ret=1
fi

line_max_len=$(wc -L < "$dmotd")
if [ "$line_max_len" -gt 80 ]; then
    echo "ERROR: $dmotd contains longer than 80 character line ($line_max_len)"
    ret=1
fi

first_line="$(head -n 1 "$dmotd")"
if ! echo "$first_line" | grep -q '^ \* '; then
    echo "ERROR: $dmotd first line does does not match recommended format, but is:"
    echo "\"$first_line\""
    ret=1
fi

last_line="$(tail -n 1 "$dmotd")"
if ! echo "$last_line" | egrep -q '( https://| apt | snap )'; then
    echo "ERROR: $dmotd last line does does not match recommended format, but is:"
    echo "\"$last_line\""
    ret=1
fi

exit $ret